static int Main(string[] args) { SimpleCommandLineParser parser = new SimpleCommandLineParser(args); parser.addOption("v", ARGUMENT_TYPE.MUST, "verb"); parser.addOption("a", ARGUMENT_TYPE.MUST, "arguments"); parser.addOption("type", ARGUMENT_TYPE.MUST, "type"); parser.addOption("name", ARGUMENT_TYPE.MUST, "name"); parser.Parse(); string verb = parser["v"].ToString(); // getString("v"); string arguments = parser["a"].ToString(); //.getString("a"); string folder = parser.getMainargs(0); if (string.IsNullOrEmpty(verb)) { MessageBox.Show("No Verb", Application.ProductName); return(-1); } if (string.IsNullOrEmpty(arguments)) { MessageBox.Show("No Arguments", Application.ProductName); return(-1); } if (string.IsNullOrEmpty(folder)) { MessageBox.Show("No Folder", Application.ProductName); return(-1); } if (!Directory.Exists(folder)) { MessageBox.Show(folder + " does not exist.", Application.ProductName); return(-1); } string type = parser["type"].ToString(); if (type != null) { if (type != "f" || type != "d") { MessageBox.Show("wrong type", Application.ProductName); return(-1); } } string name = parser["name"].ToString(); return(0); }
static int Main(string[] args) { SimpleCommandLineParser parser = new SimpleCommandLineParser(args); parser.addOption("rf", ARGUMENT_TYPE.MUST); parser.addOption("rt", ARGUMENT_TYPE.MUST); parser.addOption("ie", ARGUMENT_TYPE.MUSTNOT); parser.addOption("ic", ARGUMENT_TYPE.MUSTNOT); parser.addOption("cf", ARGUMENT_TYPE.MUSTNOT); parser.addOption("ca", ARGUMENT_TYPE.MUSTNOT); parser.addOption("blob", ARGUMENT_TYPE.MUSTNOT); parser.addOption("h", ARGUMENT_TYPE.MUSTNOT); parser.addOption("?", ARGUMENT_TYPE.MUSTNOT); parser.Parse(); if (parser["h"] != null || parser["?"] != null) { return(0); } if (parser["ca"] != null) { // check argument StringBuilder sb = new StringBuilder(); if (parser["rf"] != null) { sb.Append("rf:"); sb.AppendLine(parser["rf"].ToString()); } if (parser["rt"] != null) { sb.Append("rt:"); sb.AppendLine(parser["rt"].ToString()); } if (parser["ie"] != null) { sb.AppendLine("ie"); } if (parser["ic"] != null) { sb.AppendLine("ic"); } if (parser["ca"] != null) { sb.AppendLine("ca"); } if (parser["cf"] != null) { sb.AppendLine("cf"); } if (parser["blob"] != null) { sb.AppendLine("blob"); } if (parser["h"] != null) { sb.AppendLine("h"); } if (parser["?"] != null) { sb.AppendLine("?"); } sb.AppendLine("--------------"); for (int i = 0; i < parser.MainargLength; ++i) { sb.AppendLine(parser.getMainargs(i)); } CppUtils.CenteredMessageBox(sb.ToString()); } return(0); }
static int Main(string[] args) { SimpleCommandLineParser parser = new SimpleCommandLineParser(args); parser.addOption("rf", ARGUMENT_TYPE.MUST); parser.addOption("rt", ARGUMENT_TYPE.MUST); parser.addOption("ie", ARGUMENT_TYPE.MUSTNOT); parser.addOption("ic", ARGUMENT_TYPE.MUSTNOT); parser.addOption("cf", ARGUMENT_TYPE.MUSTNOT); parser.addOption("ca", ARGUMENT_TYPE.MUSTNOT); parser.addOption("blob", ARGUMENT_TYPE.MUSTNOT); parser.addOption("h", ARGUMENT_TYPE.MUSTNOT); parser.addOption("?", ARGUMENT_TYPE.MUSTNOT); parser.Parse(); if (parser["h"] != null || parser["?"] != null) { ShowHelp(); return(0); } if (parser["ca"] != null) { // check argument StringBuilder sb = new StringBuilder(); if (parser["rf"] != null) { sb.Append("rf:"); sb.AppendLine(parser["rf"].ToString()); } if (parser["rt"] != null) { sb.Append("rt:"); sb.AppendLine(parser["rt"].ToString()); } if (parser["ie"] != null) { sb.AppendLine("ie"); } if (parser["ic"] != null) { sb.AppendLine("ic"); } if (parser["ca"] != null) { sb.AppendLine("ca"); } if (parser["cf"] != null) { sb.AppendLine("cf"); } if (parser["blob"] != null) { sb.AppendLine("blob"); } if (parser["h"] != null) { sb.AppendLine("h"); } if (parser["?"] != null) { sb.AppendLine("?"); } MessageBox.Show(sb.ToString(), Application.ProductName + " " + "check arg", MessageBoxButtons.OK, MessageBoxIcon.Information); return(0); } if (parser["rf"] == null || parser["rt"] == null) { ShowAlert(Properties.Resources.MUST_SPECIFY_RF_RT); return(1); } string f = parser["rf"].ToString(); string t = parser["rt"].ToString(); if (parser.MainargLength == 0) { ShowAlert(Properties.Resources.NO_FILE); return(1); } Regex regf = null; try { if (parser["ic"] != null) { regf = new Regex(f, RegexOptions.IgnoreCase); } else { regf = new Regex(f); } } catch (Exception ex) { CppUtils.CenteredMessageBox(ex.Message); return(1); } bool isAlsoExt = null != parser["ie"]; bool dryrun = parser["cf"] != null; Dictionary <string, string> targets = new Dictionary <string, string>(); string[] mainArgs = ConstructMainArgs(parser); try { foreach (string orgFullorRelativeFileName in mainArgs)// (int i = 0; i < parser.MainargLength; ++i) { FileInfo fiorig = new FileInfo(orgFullorRelativeFileName); string orgFileName = getProperName(fiorig, isAlsoExt); string orgFolder = fiorig.DirectoryName; string newFileName = regf.Replace(orgFileName, t); if (!isAlsoExt) { newFileName += fiorig.Extension; } //if (dryrun) //{ // sbDry.AppendLine(string.Format("\"{0}\" -> \"{1}\"", // fiorig.FullName, orgFolder + @"\" + newFileName)); //} //else //{ // fiorig.MoveTo(orgFolder + @"\" + newFileName); //} targets.Add(fiorig.FullName, orgFolder + @"\" + newFileName); } if (dryrun) { StringBuilder sbDry = new StringBuilder(); foreach (string org in targets.Keys) { sbDry.AppendFormat("\"{0}\" -> \"{1}\"", org, targets[org]); sbDry.AppendLine(); sbDry.AppendLine(); } sbDry.AppendLine(); sbDry.AppendLine(Properties.Resources.DO_YOU_WANT_TO_PERFORM); if (DialogResult.Yes != MessageBox.Show( sbDry.ToString(), Application.ProductName + " " + Properties.Resources.CONFIRM, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)) { return(0); } } foreach (string org in targets.Keys) { if (Directory.Exists(org)) { Directory.Move(org, targets[org]); } else { File.Move(org, targets[org]); } } return(0); } catch (Exception e) { MessageBox.Show( e.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); return(-1); } }