static void Main(string[] args) { Dictionary <string, string> arguments = ArgParser.Parse(args); string filePath = null; int size = 0; //parsing cmdline args foreach (KeyValuePair <string, string> kp in arguments) { //Console.WriteLine("Key = {0} , Value = {1}", kp.Key, kp.Value); if (kp.Key == "f") { filePath = kp.Value; } if (kp.Key == "s") { size = Convert.ToInt32(kp.Value); } } //making sure the file extension is OK string e = Path.GetExtension(filePath); if (e != ".rar") { filePath = Path.ChangeExtension(filePath, ".rar"); } //Doing the real work CreateByteFile(size, filePath); ChangeBytesToRAR(filePath); }
public static Dictionary <string, string> Parse(string[] args) { Dictionary <string, string> returnVal = new Dictionary <string, string>(); // set defaults returnVal["f"] = null; returnVal["s"] = null; returnVal["h"] = null; string currentKey = ""; foreach (string str in args) { if (str.Substring(0, 1) == "-") { currentKey = str.Substring(1); bool expectedKey = false; foreach (string exp in returnVal.Keys) { if (string.Equals(currentKey, exp, StringComparison.OrdinalIgnoreCase)) { expectedKey = true; break; } } if (!expectedKey) { ArgParser.Usage(); } else { returnVal[currentKey] = ""; } } else { returnVal[currentKey] = str; } } if (returnVal["h"] != null) { ArgParser.Usage(); } return(returnVal); }