1 using System.Text;
2 using OpenBveApi;
3 using OpenBveApi.Math;
4 
5 namespace OpenBve
6 {
7 	/// <summary>Contains methods used to parse command-line arguments</summary>
8 	class CommandLine
9 	{
10 		/// <summary>Parses any command-line arguments passed to the main program</summary>
11 		/// <param name="Arguments">A string array of arguments</param>
12 		/// <param name="Result">The main dialog result (Used to launch)</param>
ParseArguments(string[] Arguments, ref formMain.MainDialogResult Result)13 		internal static void ParseArguments(string[] Arguments, ref formMain.MainDialogResult Result)
14 		{
15 			if (Arguments.Length == 0)
16 			{
17 				return;
18 			}
19 			for (int i = 0; i < Arguments.Length; i++)
20 			{
21 				int equals = Arguments[i].IndexOf('=');
22 				if (equals >= 0)
23 				{
24 					string key = Arguments[i].Substring(0, equals).Trim(new char[] { }).ToLowerInvariant();
25 					string value = Arguments[i].Substring(equals + 1).Trim(new char[] { });
26 					switch (key)
27 					{
28 						case "/route":
29 							Result.RouteFile = value;
30 							Result.RouteEncoding = TextEncoding.GetSystemEncodingFromFile(Result.RouteFile);
31 							break;
32 						case "/train":
33 							Result.TrainFolder = value;
34 							Result.TrainEncoding = TextEncoding.GetSystemEncodingFromFile(Result.TrainFolder, "train.txt");
35 							break;
36 						case "/station":
37 							Result.InitialStation = value;
38 							break;
39 						case "/time":
40 							Interface.TryParseTime(value, out Result.StartTime);
41 							break;
42 						case "/ai":
43 							if (value.ToLowerInvariant() == "true" || value.ToLowerInvariant() == "1")
44 							{
45 								Result.AIDriver = true;
46 							}
47 							break;
48 						case "/fullscreen":
49 							if (value.ToLowerInvariant() == "true" || value.ToLowerInvariant() == "1")
50 							{
51 								Result.FullScreen = true;
52 							}
53 							break;
54 						case "/width":
55 							NumberFormats.TryParseIntVb6(value, out Result.Width);
56 							break;
57 						case "/height":
58 							NumberFormats.TryParseIntVb6(value, out Result.Height);
59 							break;
60 						case "/glmenu":
61 							if (value.ToLowerInvariant() == "true" || value.ToLowerInvariant() == "1")
62 							{
63 								Result.ExperimentalGLMenu = true;
64 							}
65 							break;
66 					}
67 				}
68 			}
69 		}
70 	}
71 }
72