static string GetRadsPath(LaunchArguments arguments) { if (arguments.ContainsKey("radsPath")) { return(arguments["radsPath"]); } if (File.Exists("rads-path.txt")) { return(File.ReadAllText("rads-path.txt")); } throw new Exception("No RADS path defined"); }
static void Main(string[] args) { new ProgramInterfaceCLI().ConsoleInterface(); return; var timer = new Stopwatch(); timer.Start(); var arguments = LaunchArguments.Parse(args); var radsPath = GetRadsPath(arguments); var manager = new ArchiveFileManager(radsPath); timer.Stop(); Console.WriteLine("Elapsed time: {0} ms", timer.ElapsedMilliseconds); Console.ReadKey(); }
/// <summary> /// Parses launch arguments into a key/value mapping /// </summary> /// <param name="arguments">Launch arguments</param> /// <returns>LaunchArguments object</returns> public static LaunchArguments Parse(string[] arguments) { var result = new LaunchArguments(); //Make sure we have a proper amount of arguments, since the format is --<key> <value> if (arguments.Length % 2 != 0) { throw new Exception("Invalid launch argument count"); } //Form key value pairs for (var i = 0; i < arguments.Length;) { var key = arguments[i++]; var value = arguments[i++]; //Make sure proper format is employed if (!key.StartsWith("--") || key.Contains(' ')) { throw new Exception("Invalid argument format"); } if (key.Length < 3) { throw new Exception("Invalid argument key length"); } if (key[2] == '-') { throw new Exception("Invalid argument key"); } //Trim leading dashes key = key.TrimStart('-'); result._arguments.Add(key, value); } return(result); }