/// <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 libbSearch.FilterType.ValueOptions GetValueOptionFromOperator(string op) { libbSearch.FilterType.ValueOptions valueOption = libbSearch.FilterType.ValueOptions.None; switch (op) { case "=": valueOption = libbSearch.FilterType.ValueOptions.Equals; break; case "!=": valueOption = libbSearch.FilterType.ValueOptions.NotEquals; break; case ">": valueOption = libbSearch.FilterType.ValueOptions.GreaterThan; break; case ">=": valueOption = libbSearch.FilterType.ValueOptions.GreaterThanEquals; break; case "<": valueOption = libbSearch.FilterType.ValueOptions.LessThan; break; case "<=": valueOption = libbSearch.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> 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) { if (System.IO.Directory.Exists(myArgs["spath"])) { 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) { libbSearch.FilterType.ValueOptions valueOption = GetValueOptionFromOperator(values[0]); DateTime value = DateTime.MinValue; if (DateTime.TryParse(values[1], out value) && valueOption != libbSearch.FilterType.ValueOptions.None) { args.DateModifiedFile = new ValueOptionPair() { Value = value, ValueOption = valueOption }; } } } if (myArgs["dmd"] != null) { string[] values = myArgs["dmd"].Split('|'); if (values.Length == 2) { libbSearch.FilterType.ValueOptions valueOption = GetValueOptionFromOperator(values[0]); DateTime value = DateTime.MinValue; if (DateTime.TryParse(values[1], out value) && valueOption != libbSearch.FilterType.ValueOptions.None) { args.DateModifiedDirectory = new ValueOptionPair() { Value = value, ValueOption = valueOption }; } } } if (myArgs["dcf"] != null) { string[] values = myArgs["dcf"].Split('|'); if (values.Length == 2) { libbSearch.FilterType.ValueOptions valueOption = GetValueOptionFromOperator(values[0]); DateTime value = DateTime.MinValue; if (DateTime.TryParse(values[1], out value) && valueOption != libbSearch.FilterType.ValueOptions.None) { args.DateCreatedFile = new ValueOptionPair() { Value = value, ValueOption = valueOption }; } } } if (myArgs["dcd"] != null) { string[] values = myArgs["dcd"].Split('|'); if (values.Length == 2) { libbSearch.FilterType.ValueOptions valueOption = GetValueOptionFromOperator(values[0]); DateTime value = DateTime.MinValue; if (DateTime.TryParse(values[1], out value) && valueOption != libbSearch.FilterType.ValueOptions.None) { args.DateCreatedDirectory = new ValueOptionPair() { Value = value, ValueOption = valueOption }; } } } if (myArgs["minfsize"] != null) { string[] values = myArgs["minfsize"].Split('|'); if (values.Length == 2) { libbSearch.FilterType.ValueOptions valueOption = GetValueOptionFromOperator(values[0]); long value = 0; if (Int64.TryParse(values[1], out value) && valueOption != libbSearch.FilterType.ValueOptions.None) { args.MinFileSize = new ValueOptionPair() { Value = value, ValueOption = valueOption }; } } } if (myArgs["maxfsize"] != null) { string[] values = myArgs["maxfsize"].Split('|'); if (values.Length == 2) { libbSearch.FilterType.ValueOptions valueOption = GetValueOptionFromOperator(values[0]); long value = 0; if (Int64.TryParse(values[1], out value) && valueOption != libbSearch.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; } }