internal static bool ShouldRecord(string path) { if (AllowPath.AnyX()) { if (path.NullOrEmpty()) { return(false); } foreach (var item in AllowPath) { bool r = Regex.IsMatch(path, item); if (r) { return(true); } } return(false); } else if (ForbbidenPath.AnyX()) { if (path.NullOrEmpty()) { return(true); } foreach (var item in ForbbidenPath) { bool r = Regex.IsMatch(path, item); if (r) { return(false); } } return(true); } else { return(true); } }
public CDEArgs() { // Every Option except "<>" needs to set _currentlist to its own list, or null. // This improves the handling of non matching parameters. _os = new OptionSet { //{ // "config=", "Load parameters from {File}(s)", o => { // // import the config file. // // # start of line is comment ignore. // // new lines are considered same as white space for parameter identification. // // extra white space is ignored at start or end of lines. // } //}, // Modes below here in this section { "scan=", "Mode: scans one or more {Path}(s) creating catalogs", o => { Mode = Modes.Scan; _currentList = _scanParameters; _scanParameters.Add(o); } }, { "find=", "Mode: find entries matching {String}(s)", o => { Mode = Modes.Find; _currentList = _findParameters; _findParameters.Add(o); } }, { "hash", "Mode: collect minimal set of hashes for dupes", o => { Mode = Modes.Hash; _currentList = null; } }, { "dupes", "Mode: find duplicate files, depends on hashes", o => { Mode = Modes.Dupes; _currentList = null; } }, { "dump", "Mode: output to console catalog entries", o => { Mode = Modes.Dump; _currentList = null; } }, { "loadWait", "Mode: load catalogs and wait till enter pressed", o => { Mode = Modes.LoadWait; _currentList = null; } }, { "h|help", "Mode: show this message and exit", o => { Mode = Modes.Help; _currentList = null; } }, { "v|version", "Mode: show version", o => { Mode = Modes.Version; _currentList = null; } }, // Options below here in this section { "bp|basePath=", "Set one or more base {Path}(s)", o => { if (!AllowStartPath.Contains(_mode)) { throw new OptionException("The -basePath option is not supported in mode '-" + _mode.ToString().ToLower() + "'.", o); } _currentList = _basePaths; _currentList.Add(o); } }, { "grep", "Enable regular expressions for String find.", o => { if (!AllowGrep.Contains(_mode)) { throw new OptionException("The -grep option is not supported in mode '-" + _mode.ToString().ToLower() + "'.", o); } _grepEnabled = o != null; _currentList = null; } }, { "repl", "Enable prompting for more find searches.", o => { if (!AllowRepl.Contains(_mode)) { throw new OptionException("The -repl option is not supported in mode '-" + _mode.ToString().ToLower() + "'.", o); } _replEnabled = o != null; _currentList = null; } }, { "path", "Include paths when searching in find.", o => { if (!AllowPath.Contains(_mode)) { throw new OptionException("The -path option is not supported in mode '-" + _mode.ToString().ToLower() + "'.", o); } _pathEnabled = o != null; _currentList = null; } }, { "hashAll", "In hash mode hash all files", o => { if (!AllowHashAll.Contains(_mode)) { throw new OptionException("The -hashAll option is not supported in mode '-" + _mode.ToString().ToLower() + "'.", o); } _hashAllEnabled = o != null; _currentList = null; } }, { "e|exclude=", "regex {String}(s) to exclude from processing", o => { if (!AllowExclude.Contains(_mode)) { throw new OptionException("The -exclude option is not supported in mode '-" + _mode.ToString().ToLower() + "'.", o); } _currentList = _exclude; _currentList.Add(o); } }, { "i|include=", "regex {String}(s) to include it in processing", o => { if (!AllowInclude.Contains(_mode)) { throw new OptionException("The -include option is not supported in mode '-" + _mode.ToString().ToLower() + "'.", o); } _currentList = _include; _currentList.Add(o); } }, { "minSize=", "Minimum file size to include it in processing", o => { if (!AllowMinSize.Contains(_mode)) { throw new OptionException("The -minSize option is not supported in mode '-" + _mode.ToString().ToLower() + "'.", o); } _minSize = SizeOption(o); _currentList = null; } }, { "maxSize=", "Maximum file size to include it in processing", o => { if (!AllowMaxSize.Contains(_mode)) { throw new OptionException("The -maxSize option is not supported in mode '-" + _mode.ToString().ToLower() + "'.", o); } _maxSize = SizeOption(o); _currentList = null; } }, { "minDate=", "Minimum DateTime on entry to include it in processing", o => { if (!AllowMinDate.Contains(_mode)) { throw new OptionException("The -minDate option is not supported in mode '-" + _mode.ToString().ToLower() + "'.", o); } try { var d = new DateTimePartialParameter(o); _minDate = d.GetDate(); } catch (ArgumentException ae) { throw new OptionException(ae.Message, _mode.ToString()); } _currentList = null; } }, { "maxDate=", "Maximum DateTime on entry to include it in processing", o => { if (!AllowMaxDate.Contains(_mode)) { throw new OptionException("The -maxDate option is not supported in mode '-" + _mode.ToString().ToLower() + "'.", o); } try { var d = new DateTimePartialParameter(o); _maxDate = d.GetDate(); } catch (ArgumentException ae) { throw new OptionException(ae.Message, _mode.ToString()); } _currentList = null; } }, { "minTime=", "Minimum Time on entry ignore Date to include it in processing", o => { if (!AllowMinTime.Contains(_mode)) { throw new OptionException("The -minTime option is not supported in mode '-" + _mode.ToString().ToLower() + "'.", o); } try { var d = new TimePartialParameter(o); _minTime = new DateTime(1, 1, 1, d.Hour, d.Minute, d.Second); } catch (ArgumentException ae) { throw new OptionException(ae.Message, _mode.ToString()); } _currentList = null; } }, { // unsure if leaving this here for releases "alternate", "an alternate data model (testing)", o => { if (!AllowAlternate.Contains(_mode)) { throw new OptionException("The -alt option is not supported in mode '-" + _mode.ToString().ToLower() + "'.", o); } _alternate = o != null; _currentList = null; } }, // to collection multi value parameter values. { "<>", "", o => { if (_currentList == null) { throw new OptionException("Error unmatched parameter: '" + o + "'", o); } _currentList.Add(o); } }, }; }