/// <summary> /// Convert a string operator to a FilterType.ValueOptions enum. /// </summary> /// <param name="op">string value of operator (supports =,!=,<,>,<=,>=)</param> /// <returns>FilterType.ValueOptions enum value</returns> private static libAstroGrep.FilterType.ValueOptions GetValueOptionFromOperator(string op) { libAstroGrep.FilterType.ValueOptions valueOption = libAstroGrep.FilterType.ValueOptions.None; switch (op) { case "=": valueOption = libAstroGrep.FilterType.ValueOptions.Equals; break; case "!=": valueOption = libAstroGrep.FilterType.ValueOptions.NotEquals; break; case ">": valueOption = libAstroGrep.FilterType.ValueOptions.GreaterThan; break; case ">=": valueOption = libAstroGrep.FilterType.ValueOptions.GreaterThanEquals; break; case "<": valueOption = libAstroGrep.FilterType.ValueOptions.LessThan; break; case "<=": valueOption = libAstroGrep.FilterType.ValueOptions.LessThanEquals; break; } return(valueOption); }
/// <summary> /// Parse the given string for valid command line option flags. /// </summary> /// <param name="myArgs">String containing potential options.</param> /// <param name="args">CommandLineArguments structure to hold found options.</param> /// <history> /// [Curtis_Beard] 07/26/2006 Created /// [Curtis_Beard] 05/18/2007 CHG: use new command line arguments /// [Curtis_Beard] 09/26/2012 ADD: display help option /// [Curtis_Beard] 04/08/2014 CHG: 74, add missing search options, exit, save /// [Curtis_Beard] 06/02/2015 CHG: 97, remove /local since portable version created /// [Curtis_Beard] 01/08/2019 FIX: 104, allow any path to be passed to UI and UI will validate /// </history> private static void ProcessFlags(Arguments myArgs, ref CommandLineArguments args) { if (myArgs["s"] != null) { args.StartSearch = true; } if (myArgs["e"] != null) { args.UseRegularExpressions = true; } if (myArgs["c"] != null) { args.IsCaseSensitive = true; } if (myArgs["w"] != null) { args.IsWholeWord = true; } if (myArgs["r"] != null) { args.UseRecursion = true; } if (myArgs["n"] != null) { args.IsNegation = true; } if (myArgs["l"] != null) { args.UseLineNumbers = true; } if (myArgs["f"] != null) { args.IsFileNamesOnly = true; } if (myArgs["cl"] != null) { try { int num = int.Parse(myArgs["cl"]); if (num >= 0 && num <= Constants.MAX_CONTEXT_LINES) { args.ContextLines = num; } } catch {} } if (myArgs["sh"] != null) { args.SkipHiddenFile = true; args.SkipHiddenDirectory = true; } if (myArgs["ss"] != null) { args.SkipSystemFile = true; args.SkipSystemDirectory = true; } if (myArgs["shf"] != null) { args.SkipHiddenFile = true; } if (myArgs["shd"] != null) { args.SkipHiddenDirectory = true; } if (myArgs["ssf"] != null) { args.SkipSystemFile = true; } if (myArgs["ssd"] != null) { args.SkipSystemDirectory = true; } if (myArgs["spath"] != null) { args.IsValidStartPath = true; args.StartPath = myArgs["spath"]; } if (myArgs["stypes"] != null) { args.IsValidFileTypes = true; args.FileTypes = myArgs["stypes"]; } if (myArgs["stext"] != null) { args.IsValidSearchText = true; args.SearchText = myArgs["stext"]; } if (myArgs["h"] != null || myArgs["?"] != null || myArgs["help"] != null) { args.DisplayHelp = true; } if (myArgs["opath"] != null) { args.OutputPath = myArgs["opath"]; // default to txt (override by supplying outputtype) args.OutputType = "txt"; // since they want to save results, then we have to start search args.StartSearch = true; } if (myArgs["otype"] != null) { args.OutputType = myArgs["otype"].ToLower(); // set default path if not defined if (string.IsNullOrEmpty(args.OutputPath)) { args.OutputPath = System.IO.Path.Combine(Environment.CurrentDirectory, string.Format("results.{0}", args.OutputType)); } // since they want to save results, then we have to start search args.StartSearch = true; } if (myArgs["exit"] != null) { args.ExitAfterSearch = true; } if (myArgs["dmf"] != null) { string[] values = myArgs["dmf"].Split('|'); if (values.Length == 2) { libAstroGrep.FilterType.ValueOptions valueOption = GetValueOptionFromOperator(values[0]); DateTime value = DateTime.MinValue; if (DateTime.TryParse(values[1], out value) && valueOption != libAstroGrep.FilterType.ValueOptions.None) { args.DateModifiedFile = new ValueOptionPair() { Value = value, ValueOption = valueOption }; } } } if (myArgs["dmd"] != null) { string[] values = myArgs["dmd"].Split('|'); if (values.Length == 2) { libAstroGrep.FilterType.ValueOptions valueOption = GetValueOptionFromOperator(values[0]); DateTime value = DateTime.MinValue; if (DateTime.TryParse(values[1], out value) && valueOption != libAstroGrep.FilterType.ValueOptions.None) { args.DateModifiedDirectory = new ValueOptionPair() { Value = value, ValueOption = valueOption }; } } } if (myArgs["dcf"] != null) { string[] values = myArgs["dcf"].Split('|'); if (values.Length == 2) { libAstroGrep.FilterType.ValueOptions valueOption = GetValueOptionFromOperator(values[0]); DateTime value = DateTime.MinValue; if (DateTime.TryParse(values[1], out value) && valueOption != libAstroGrep.FilterType.ValueOptions.None) { args.DateCreatedFile = new ValueOptionPair() { Value = value, ValueOption = valueOption }; } } } if (myArgs["dcd"] != null) { string[] values = myArgs["dcd"].Split('|'); if (values.Length == 2) { libAstroGrep.FilterType.ValueOptions valueOption = GetValueOptionFromOperator(values[0]); DateTime value = DateTime.MinValue; if (DateTime.TryParse(values[1], out value) && valueOption != libAstroGrep.FilterType.ValueOptions.None) { args.DateCreatedDirectory = new ValueOptionPair() { Value = value, ValueOption = valueOption }; } } } if (myArgs["minfsize"] != null) { string[] values = myArgs["minfsize"].Split('|'); if (values.Length == 2) { libAstroGrep.FilterType.ValueOptions valueOption = GetValueOptionFromOperator(values[0]); long value = 0; if (Int64.TryParse(values[1], out value) && valueOption != libAstroGrep.FilterType.ValueOptions.None) { args.MinFileSize = new ValueOptionPair() { Value = value, ValueOption = valueOption }; } } } if (myArgs["maxfsize"] != null) { string[] values = myArgs["maxfsize"].Split('|'); if (values.Length == 2) { libAstroGrep.FilterType.ValueOptions valueOption = GetValueOptionFromOperator(values[0]); long value = 0; if (Int64.TryParse(values[1], out value) && valueOption != libAstroGrep.FilterType.ValueOptions.None) { args.MaxFileSize = new ValueOptionPair() { Value = value, ValueOption = valueOption }; } } } if (myArgs["minfc"] != null) { int value = 0; if (Int32.TryParse(myArgs["minfc"], out value)) { args.MinFileCount = value; } } if (myArgs["srf"] != null) { args.ReadOnlyFile = true; } }