diff --git a/SabreTools.Library/Data/Enums.cs b/SabreTools.Library/Data/Enums.cs index 84af9b3a..4819c9ed 100644 --- a/SabreTools.Library/Data/Enums.cs +++ b/SabreTools.Library/Data/Enums.cs @@ -358,6 +358,8 @@ { Flag = 0, String, + Int32, + Int64, List, } diff --git a/SabreTools.Library/Help/Feature.cs b/SabreTools.Library/Help/Feature.cs index fe0ec748..1f8a2852 100644 --- a/SabreTools.Library/Help/Feature.cs +++ b/SabreTools.Library/Help/Feature.cs @@ -19,11 +19,26 @@ namespace SabreTools.Library.Help // Specific value types private bool _valueBool = false; + private int _valueInt32 = Int32.MinValue; + private long _valueInt64 = Int64.MinValue; private string _valueString = null; private List _valueList = null; #endregion + #region Publicly facing variables + + public string Description + { + get { return _description; } + } + public Dictionary Features + { + get { return _features; } + } + + #endregion + #region Constructors public Feature() @@ -336,8 +351,9 @@ namespace SabreTools.Library.Help /// /// Input to check against /// True if just this feature should be checked, false if all subfeatures are checked as well + /// True if the existing flag should be ignored, false otherwise /// True if the flag was valid, false otherwise - public bool ValidateInput(string input, bool exact = false) + public bool ValidateInput(string input, bool exact = false, bool ignore = false) { bool valid = false; @@ -350,10 +366,56 @@ namespace SabreTools.Library.Help if (valid) { _valueBool = true; + + // If we've already found this feature before + if (_foundOnce && !ignore) + { + valid = false; + } + _foundOnce = true; } break; + // If we have an Int32, try to parse it if at all possible + case FeatureType.Int32: + valid = input.Contains("=") && _flags.Contains(input.Split('=')[0]); + if (valid) + { + if (!Int32.TryParse(input.Split('=')[1], out int value)) + { + value = Int32.MinValue; + } + _valueInt32 = value; + // If we've already found this feature before + if (_foundOnce && !ignore) + { + valid = false; + } + + _foundOnce = true; + } + break; + // If we have an Int32, try to parse it if at all possible + case FeatureType.Int64: + valid = input.Contains("=") && _flags.Contains(input.Split('=')[0]); + if (valid) + { + if (!Int64.TryParse(input.Split('=')[1], out long value)) + { + value = Int64.MinValue; + } + _valueInt64 = value; + + // If we've already found this feature before + if (_foundOnce && !ignore) + { + valid = false; + } + + _foundOnce = true; + } + break; // If we have an input, make sure it has an equals sign in it case FeatureType.List: valid = input.Contains("=") && _flags.Contains(input.Split('=')[0]); @@ -372,6 +434,13 @@ namespace SabreTools.Library.Help if (valid) { _valueString = input.Split('=')[1]; + + // If we've already found this feature before + if (_foundOnce && !ignore) + { + valid = false; + } + _foundOnce = true; } break; @@ -392,12 +461,6 @@ namespace SabreTools.Library.Help } } - // If we've already found this flag before and we don't allow duplicates, set valid to false - if (valid && _foundOnce && _featureType != FeatureType.List) - { - valid = false; - } - // If we're not valid at this point, we want to check if this flag is a file or a folder if (!valid) { @@ -417,6 +480,10 @@ namespace SabreTools.Library.Help { case FeatureType.Flag: return _valueBool; + case FeatureType.Int32: + return _valueInt32; + case FeatureType.Int64: + return _valueInt64; case FeatureType.List: return _valueList; case FeatureType.String: @@ -438,6 +505,10 @@ namespace SabreTools.Library.Help { case FeatureType.Flag: return (bool)obj; + case FeatureType.Int32: + return (int)obj != Int32.MinValue; + case FeatureType.Int64: + return (long)obj != Int64.MinValue; case FeatureType.List: return obj != null; case FeatureType.String: diff --git a/SabreTools.Library/Help/Help.cs b/SabreTools.Library/Help/Help.cs index 8a87e8f1..af6b4807 100644 --- a/SabreTools.Library/Help/Help.cs +++ b/SabreTools.Library/Help/Help.cs @@ -102,7 +102,7 @@ namespace SabreTools.Library.Help // Loop through the features foreach (string featureName in _features.Keys) { - if (_features[featureName].ValidateInput(name, exact: true)) + if (_features[featureName].ValidateInput(name, exact: true, ignore: true)) { feature = featureName; break; @@ -259,14 +259,22 @@ namespace SabreTools.Library.Help /// Retrieve a list of enabled features /// /// List of Features representing what is enabled - public List GetEnabledFeatures() + public Dictionary GetEnabledFeatures() { - List enabled = new List(); + Dictionary enabled = new Dictionary(); // Loop through the features foreach(KeyValuePair feature in _features) { - enabled.AddRange(GetEnabledSubfeatures(feature.Value)); + Dictionary temp = GetEnabledSubfeatures(feature.Key, feature.Value); + foreach (KeyValuePair tempfeat in temp) + { + if (!enabled.ContainsKey(tempfeat.Key)) + { + enabled.Add(tempfeat.Key, null); + } + enabled[tempfeat.Key] = tempfeat.Value; + } } return enabled; @@ -275,22 +283,31 @@ namespace SabreTools.Library.Help /// /// Retrieve a nested list of subfeatures from the current feature /// + /// Name that should be assigned to the feature /// Feature with possible subfeatures to test /// List of Features representing what is enabled - private List GetEnabledSubfeatures(Feature feature) + private Dictionary GetEnabledSubfeatures(string key, Feature feature) { - List enabled = new List(); + Dictionary enabled = new Dictionary(); // First determine if the current feature is enabled if (feature.IsEnabled()) { - enabled.Add(feature); + enabled.Add(key, feature); } // Now loop through the subfeatures recursively - foreach (KeyValuePair sub in _features) + foreach (KeyValuePair sub in feature.Features) { - enabled.AddRange(GetEnabledSubfeatures(sub.Value)); + Dictionary temp = GetEnabledSubfeatures(sub.Key, sub.Value); + foreach (KeyValuePair tempfeat in temp) + { + if (!enabled.ContainsKey(tempfeat.Key)) + { + enabled.Add(tempfeat.Key, null); + } + enabled[tempfeat.Key] = tempfeat.Value; + } } return enabled; diff --git a/SabreTools/SabreTools.Help.cs b/SabreTools/SabreTools.Help.cs index 5f844386..d0d10e63 100644 --- a/SabreTools/SabreTools.Help.cs +++ b/SabreTools/SabreTools.Help.cs @@ -304,7 +304,7 @@ namespace SabreTools datFromDir.AddFeature("mt", new Feature( new List() { "-mt", "--mt" }, "Amount of threads to use (default 4, -1 unlimted)", - FeatureType.String, + FeatureType.Int32, null)); #endregion @@ -473,22 +473,22 @@ namespace SabreTools sort.AddFeature("7z", new Feature( new List() { "-7z", "--7z" }, "Set scanning level for 7z archives (default 1)", - FeatureType.String, + FeatureType.Int32, null)); sort.AddFeature("gz", new Feature( new List() { "-gz", "--gz" }, "Set scanning level for GZip archives (default 1)", - FeatureType.String, + FeatureType.Int32, null)); sort.AddFeature("rar", new Feature( new List() { "-rar", "--rar" }, "Set scanning level for RAR archives (default 1)", - FeatureType.String, + FeatureType.Int32, null)); sort.AddFeature("zip", new Feature( new List() { "-zip", "--zip" }, "Set scanning level for ZIP archives (default 1)", - FeatureType.String, + FeatureType.Int32, null)); sort.AddFeature("scan-all", new Feature( new List() { "-sa", "--scan-all" }, @@ -523,7 +523,7 @@ namespace SabreTools sort.AddFeature("mt", new Feature( new List() { "-mt", "--mt" }, "Amount of threads to use (default 4, -1 unlimted)", - FeatureType.String, + FeatureType.Int32, null)); #endregion @@ -1318,17 +1318,17 @@ namespace SabreTools update.AddFeature("greater", new Feature( new List() { "-sgt", "--greater" }, "Filter by size >=", - FeatureType.String, + FeatureType.Int32, null)); update.AddFeature("less", new Feature( new List() { "-slt", "--less" }, "Filter by size =<", - FeatureType.String, + FeatureType.Int32, null)); update.AddFeature("equal", new Feature( new List() { "-seq", "--equal" }, "Filter by size ==", - FeatureType.String, + FeatureType.Int32, null)); update.AddFeature("crc", new Feature( new List() { "-crc", "--crc" }, @@ -1449,7 +1449,7 @@ namespace SabreTools update.AddFeature("mt", new Feature( new List() { "-mt", "--mt" }, "Amount of threads to use (default 4, -1 unlimited)", - FeatureType.String, + FeatureType.Int32, null)); #endregion diff --git a/SabreTools/SabreTools.cs b/SabreTools/SabreTools.cs index b44794ed..faf832b0 100644 --- a/SabreTools/SabreTools.cs +++ b/SabreTools/SabreTools.cs @@ -36,7 +36,7 @@ namespace SabreTools Globals.Logger = new Logger(true, "sabretools.log"); // Create a new Help object for this program - _help = RetrieveHelp(); + _help = SabreTools.RetrieveHelp(); // Get the location of the script tag, if it exists int scriptLocation = (new List(args)).IndexOf("--script"); @@ -170,70 +170,29 @@ namespace SabreTools return; } - // Check the first argument for being a feature flag - switch (feature) - { - case "-?": - case "-h": - case "--help": - if (1 < args.Length) - { - _help.OutputIndividualFeature(args[1]); - } - else - { - _help.OutputGenericHelp(); - } - Globals.Logger.Close(); - return; - case "-d": - case "--d2d": - case "--dfd": - datFromDir = true; - break; - case "-ex": - case "--extract": - extract = true; - break; - case "-re": - case "--restore": - restore = true; - break; - case "--script": - // No-op for script mode, allowing for retaining the screen - break; - case "-sp": - case "--split": - split = true; - break; - case "-ss": - case "--sort": - sort = true; - break; - case "-st": - case "--stats": - stats = true; - break; - case "-ud": - case "--update": - update = true; - break; - case "-ve": - case "--verify": - verify = true; - break; - - // If we don't have a valid flag, feed it through the help system - default: - _help.OutputIndividualFeature(feature); - Globals.Logger.Close(); - return; - } - // Now get the proper name for the feature feature = _help.GetFeatureName(feature); - // Determine which switches are enabled (with values if necessary) + // If we had the help feature first + if (feature == "Help") + { + // If we had something else after help + if (args.Length > 1) + { + _help.OutputIndividualFeature(args[1]); + Globals.Logger.Close(); + return; + } + // Otherwise, show generic help + else + { + _help.OutputGenericHelp(); + Globals.Logger.Close(); + return; + } + } + + // Now verify that all other flags are valid for (int i = 1; i < args.Length; i++) { // Verify that the current flag is proper for the feature @@ -245,743 +204,547 @@ namespace SabreTools return; } - switch (args[i]) + // Special precautions for files and directories + if (File.Exists(args[i]) || Directory.Exists(args[i])) { + inputs.Add(args[i]); + } + } + + // Now loop through all inputs + Dictionary features = _help.GetEnabledFeatures(); + foreach (KeyValuePair feat in features) + { + // Check all of the flag names and translate to arguments + switch (feat.Key) + { + // Top-level features + case "Help": + // No-op as this should be caught + break; + case "DATFromDir": + datFromDir = true; + break; + case "Extract": + extract = true; + break; + case "Restore": + restore = true; + break; + case "Script": + // No-op as this should be caught + break; + case "Split": + split = true; + break; + case "Sort": + sort = true; + break; + case "Stats": + stats = true; + break; + case "Update": + update = true; + break; + case "Verify": + verify = true; + break; + // User flags - case "-ab": - case "--add-blank": + case "add-blank": addBlankFilesForEmptyFolder = true; break; - case "-ad": - case "--add-date": + case "add-date": addFileDates = true; break; - case "-ag": - case "--against": + case "against": updateMode |= UpdateMode.DiffAgainst; break; - case "-as": - case "--all-stats": + case "all-stats": statDatFormat = StatReportFormat.All; break; - case "-b": - case "--bare": + case "bare": removeDateFromAutomaticName = true; break; - case "-ba": - case "--base": + case "base": basedat = true; break; - case "-bc": - case "--baddump-col": + case "baddump-col": showBaddumpColumn = true; break; - case "-bn": - case "--base-name": + case "base-name": updateMode |= UpdateMode.BaseReplace; break; - case "-c": - case "--cascade": + case "cascade": updateMode |= UpdateMode.DiffCascade; break; - case "-cf": - case "--copy-files": + case "copy-files": copyFiles = true; break; - case "-clean": - case "--clean": + case "clean": cleanGameNames = true; break; - case "-csv": - case "--csv": + case "csv": statDatFormat |= StatReportFormat.CSV; break; - case "-dan": - case "--desc-name": + case "desc-name": descAsName = true; break; - case "-dd": - case "--dedup": + case "dedup": dedup = DedupeType.Full; break; - case "-del": - case "--delete": + case "delete": delete = true; break; - case "-dep": - case "--depot": + case "depot": depot = true; break; - case "-df": - case "--dat-fullnonmerged": + case "dat-fullnonmerged": splitType = SplitType.FullNonMerged; break; - case "-di": - case "--diff": + case "diff": updateMode |= UpdateMode.AllDiffs; break; - case "-did": - case "--diff-du": + case "diff-du": updateMode |= UpdateMode.DiffDupesOnly; break; - case "-dii": - case "--diff-in": + case "diff-in": updateMode |= UpdateMode.DiffIndividualsOnly; break; - case "-din": - case "--diff-nd": + case "diff-nd": updateMode |= UpdateMode.DiffNoDupesOnly; break; - case "-dm": - case "--dat-merged": + case "-dat-merged": splitType = SplitType.Merged; break; - case "-dnd": - case "--dat-devnonmerged": + case "dat-devnonmerged": splitType = SplitType.DeviceNonMerged; break; - case "-dnm": - case "--dat-nonmerged": + case "dat-nonmerged": splitType = SplitType.NonMerged; break; - case "-ds": - case "--dat-split": + case "dat-split": splitType = SplitType.Split; break; - case "-es": - case "--ext": + case "ext": splittingMode |= SplittingMode.Extension; break; - case "-f": - case "--files": + case "files": archivesAsFiles = true; break; - case "-gdd": - case "--game-dedup": + case "game-dedup": dedup = DedupeType.Game; break; - case "-gp": - case "--game-prefix": + case "game-prefix": datPrefix = true; break; - case "-ho": - case "--hash-only": + case "hash-only": hashOnly = true; break; - case "-html": - case "--html": + case "html": statDatFormat |= StatReportFormat.HTML; break; - case "-hs": - case "--hash": + case "hash": splittingMode |= SplittingMode.Hash; break; - case "-ic": - case "--ignore-chd": + case "ignore-chd": chdsAsFiles = true; break; - case "-in": - case "--inverse": + case "inverse": inverse = true; break; - case "-ip": - case "--inplace": + case "inplace": inplace = true; break; - case "-ls": - case "--level": + case "level": splittingMode |= SplittingMode.Level; break; - case "-m": - case "--merge": + case "merge": updateMode |= UpdateMode.Merge; break; - case "-nc": - case "--nodump-col": + case "nodump-col": showNodumpColumn = true; break; - case "-nm": - case "--noMD5": + case "noMD5": omitFromScan |= Hash.MD5; break; - case "-nrun": - case "--not-run": + case "not-run": filter.Runnable = false; break; - case "-ns": - case "--noSHA1": + case "noSHA1": omitFromScan |= Hash.SHA1; break; - case "-ns256": - case "--noSHA256": + case "noSHA256": omitFromScan &= ~Hash.SHA256; // This needs to be inverted later break; - case "-ns384": - case "--noSHA384": + case "noSHA384": omitFromScan &= ~Hash.SHA384; // This needs to be inverted later break; - case "-ns512": - case "--noSHA512": + case "noSHA512": omitFromScan &= ~Hash.SHA512; // This needs to be inverted later break; - case "-nsh": - case "--no-store-header": + case "-no-store-header": nostore = true; break; - case "-oa": - case "--output-all": + case "output-all": datFormat |= DatFormat.ALL; break; - case "-oam": - case "--output-am": + case "output-am": datFormat |= DatFormat.AttractMode; break; - case "-oc": - case "--output-cmp": + case "output-cmp": datFormat |= DatFormat.ClrMamePro; break; - case "-ocsv": - case "--output-csv": + case "output-csv": datFormat |= DatFormat.CSV; break; - case "-od": - case "--output-dc": + case "output-dc": datFormat |= DatFormat.DOSCenter; break; - case "-ofg": - case "--of-as-game": + case "of-as-game": filter.IncludeOfInGame = true; break; - case "-olr": - case "--output-lr": + case "output-lr": datFormat |= DatFormat.Listroms; break; - case "-om": - case "--output-miss": + case "output-miss": datFormat |= DatFormat.MissFile; break; - case "-omd5": - case "--output-md5": + case "output-md5": datFormat |= DatFormat.RedumpMD5; break; - case "-ool": - case "--output-ol": + case "output-ol": datFormat |= DatFormat.OfflineList; break; - case "-or": - case "--output-rc": + case "output-rc": datFormat |= DatFormat.RomCenter; break; - case "-os": - case "--output-sd": + case "output-sd": datFormat |= DatFormat.SabreDat; break; - case "-osfv": - case "--output-sfv": + case "output-sfv": datFormat |= DatFormat.RedumpSFV; break; - case "-osha1": - case "--output-sha1": + case "output-sha1": datFormat |= DatFormat.RedumpSHA1; break; - case "-osha256": - case "--output-sha256": + case "output-sha256": datFormat |= DatFormat.RedumpSHA256; break; - case "-osha384": - case "--output-sha384": + case "output-sha384": datFormat |= DatFormat.RedumpSHA384; break; - case "-osha512": - case "--output-sha512": + case "output-sha512": datFormat |= DatFormat.RedumpSHA512; break; - case "-osl": - case "--output-sl": + case "output-sl": datFormat |= DatFormat.SoftwareList; break; - case "-otsv": - case "--output-tsv": + case "output-tsv": datFormat |= DatFormat.TSV; break; - case "-ox": - case "--output-xml": + case "output-xml": datFormat |= DatFormat.Logiqx; break; - case "-q": - case "--quotes": + case "quotes": quotes = true; break; - case "-qs": - case "--quick": + case "quick": quickScan = true; break; - case "-r": - case "--roms": + case "roms": usegame = false; break; - case "-rbn": - case "--reverse-base-name": + case "reverse-base-name": updateMode |= UpdateMode.ReverseBaseReplace; break; - case "-rc": - case "--rev-cascade": + case "rev-cascade": updateMode |= UpdateMode.DiffReverseCascade; break; - case "-rmd5": - case "--rem-md5": + case "rem-md5": stripHash |= Hash.MD5; break; - case "-rme": - case "--rem-ext": + case "rem-ext": remext = true; break; - case "-ro": - case "--romba": + case "romba": romba = true; break; - case "-rsha1": - case "--rem-sha1": + case "rem-sha1": stripHash |= Hash.SHA1; break; - case "-rsha256": - case "--rem-sha256": + case "rem-sha256": stripHash |= Hash.SHA256; break; - case "-rsha384": - case "--rem-sha384": + case "rem-sha384": stripHash |= Hash.SHA384; break; - case "-rsha512": - case "--rem-sha512": + case "rem-sha512": stripHash |= Hash.SHA512; break; - case "-ru": - case "--rem-uni": + case "rem-uni": removeUnicode = true; break; - case "-run": - case "--runnable": + case "runnable": filter.Runnable = true; break; - case "-s": - case "--short": + case "short": shortname = true; break; - case "-sa": - case "--scan-all": + case "scan-all": sevenzip = 0; gz = 0; rar = 0; zip = 0; break; - case "-sd": - case "--superdat": + case "superdat": superdat = true; break; - case "-sds": - case "--scene-date-strip": + case "scene-date-strip": sceneDateStrip = true; break; - case "-sf": - case "--skip": + case "skip": skip = true; break; - case "-si": - case "--single": + case "single": filter.Single = true; break; - case "-ska": - case "--skiparc": + case "skiparc": skipFileType = SkipFileType.Archive; break; - case "-skf": - case "--skipfile": + case "skipfile": skipFileType = SkipFileType.File; break; - case "-t7z": - case "--t7z": + case "t7z": outputFormat = OutputFormat.Torrent7Zip; break; - case "-tar": - case "--tar": + case "tar": outputFormat = OutputFormat.TapeArchive; break; - case "-tgz": - case "--tgz": + case "tgz": outputFormat = OutputFormat.TorrentGzip; break; - case "-tlrz": - case "--tlrz": + case "tlrz": outputFormat = OutputFormat.TorrentLRZip; break; - case "-lz4": - case "--tlz4": + case "tlz4": outputFormat = OutputFormat.TorrentLZ4; break; - case "-trar": - case "--trar": + case "trar": outputFormat = OutputFormat.TorrentRar; break; - case "-trim": - case "--trim": + case "trim": filter.Trim = true; break; - case "-ts": - case "--type": + case "type": splittingMode |= SplittingMode.Type; break; - case "-tsv": - case "--tsv": + case "tsv": statDatFormat |= StatReportFormat.TSV; break; - case "-txz": - case "--txz": + case "txz": outputFormat = OutputFormat.TorrentXZ; break; - case "-txt": - case "--text": + case "text": statDatFormat |= StatReportFormat.Textfile; break; - case "-tzip": - case "--tzip": + case "tzip": outputFormat = OutputFormat.TorrentZip; break; - case "-tzpaq": - case "--tzpaq": + case "tzpaq": outputFormat = OutputFormat.TorrentZPAQ; break; - case "-tzstd": - case "--tzstd": + case "tzstd": outputFormat = OutputFormat.TorrentZstd; break; - case "-upd": - case "--update-dat": + case "update-dat": updateDat = true; break; - case "-xof": - case "--exclude-of": + case "exclude-of": excludeOf = true; break; // User inputs - default: - string temparg = args[i].Replace("\"", "").Replace("file://", ""); - - if (temparg.StartsWith("-") && temparg.Contains("=")) + case "7z": + sevenzip = (int)feat.Value.GetValue() == Int32.MinValue ? (int)feat.Value.GetValue() : 1; + break; + case "-add-ext": + addext = (string)feat.Value.GetValue(); + break; + case "author": + author = (string)feat.Value.GetValue(); + break; + case "base-dat": + basePaths.AddRange((List)feat.Value.GetValue()); + break; + case "category": + category = (string)feat.Value.GetValue(); + break; + case "comment": + comment = (string)feat.Value.GetValue(); + break; + case "crc": + filter.CRCs.AddRange((List)feat.Value.GetValue()); + break; + case "date": + date = (string)feat.Value.GetValue(); + break; + case "dat": + if (!File.Exists((string)feat.Value.GetValue()) && !Directory.Exists((string)feat.Value.GetValue())) { - // Split the argument - string[] argsplit = temparg.Split('='); - - // If we have a null second argument, we set it to be a blank - if (argsplit[1] == null) - { - argsplit[1] = ""; - } - // If we have more than 2 items in the split, we want to combine the other parts again - else if (argsplit.Length > 2) - { - argsplit[1] = string.Join("=", argsplit.Skip(1)); - } - - switch (argsplit[0]) - { - case "-7z": - case "--7z": - if (!Int32.TryParse(argsplit[1], out sevenzip)) - { - sevenzip = 1; - } - break; - case "-ae": - case "--add-ext": - addext = argsplit[1]; - break; - case "-au": - case "--author": - author = argsplit[1]; - break; - case "-bd": - case "--base-dat": - basePaths.Add(argsplit[1]); - break; - case "-ca": - case "--category=": - category = argsplit[1]; - break; - case "-co": - case "--comment": - comment = argsplit[1]; - break; - case "-crc": - case "--crc": - filter.CRCs.Add(argsplit[1]); - break; - case "-da": - case "--date": - date = argsplit[1]; - break; - case "-dat": - case "--dat": - if (!File.Exists(argsplit[1]) && !Directory.Exists(argsplit[1])) - { - Globals.Logger.Error("Must be a valid file or folder of DATs: {0}", argsplit[1]); - Globals.Logger.Close(); - return; - } - datfiles.Add(argsplit[1]); - break; - case "-de": - case "--desc": - description = argsplit[1]; - break; - case "-em": - case "--email": - email = argsplit[1]; - break; - case "-exta": - case "--exta": - exta.Add(argsplit[1]); - break; - case "-extb": - case "--extb": - extb.Add(argsplit[1]); - break; - case "-f": - case "--filename": - filename = argsplit[1]; - break; - case "-fm": - case "--forcemerge": - forcemerge = argsplit[1]; - break; - case "-fn": - case "--forcend": - forcend = argsplit[1]; - break; - case "-fp": - case "--forcepack": - forcepack = argsplit[1]; - break; - case "-gn": - case "--game-name": - filter.GameNames.Add(argsplit[1]); - break; - case "-gt": - case "--game-type": - filter.MachineTypes |= Utilities.GetMachineType(argsplit[1]); - break; - case "-gz": - case "--gz": - if (!Int32.TryParse(argsplit[1], out gz)) - { - gz = 2; - } - break; - case "-h": - case "--header": - header = argsplit[1]; - break; - case "-hp": - case "--homepage": - homepage = argsplit[1]; - break; - case "-is": - case "--status": - filter.ItemStatuses |= Utilities.GetItemStatus(argsplit[1]); - break; - case "-md5": - case "--md5": - filter.MD5s.Add(argsplit[1]); - break; - case "-mt": - case "--mt": - if (Int32.TryParse(argsplit[1], out int mdop)) - { - Globals.MaxThreads = mdop; - } - break; - case "-n": - case "--name": - name = argsplit[1]; - break; - case "-ncrc": - case "--not-crc": - filter.NotCRCs.Add(argsplit[i]); - break; - case "-ngn": - case "--not-game": - filter.NotGameNames.Add(argsplit[1]); - break; - case "-ngt": - case "--not-gtype": - filter.NotMachineTypes |= Utilities.GetMachineType(argsplit[1]); - break; - case "-nis": - case "--not-status": - filter.NotItemStatuses |= Utilities.GetItemStatus(argsplit[1]); - break; - case "-nmd5": - case "--not-md5": - filter.NotMD5s.Add(argsplit[1]); - break; - case "-nrn": - case "--not-rom": - filter.NotRomNames.Add(argsplit[1]); - break; - case "-nrt": - case "--not-type": - filter.NotRomTypes.Add(argsplit[1]); - break; - case "-nsha1": - case "--not-sha1": - filter.NotSHA1s.Add(argsplit[1]); - break; - case "-nsha256": - case "--not-sha256": - filter.NotSHA256s.Add(argsplit[1]); - break; - case "-nsha384": - case "--not-sha384": - filter.NotSHA384s.Add(argsplit[1]); - break; - case "-nsha512": - case "--not-sha512": - filter.NotSHA512s.Add(argsplit[1]); - break; - case "-out": - case "--out": - outDir = argsplit[1]; - break; - case "-post": - case "--postfix": - postfix = argsplit[1]; - break; - case "-pre": - case "--prefix": - prefix = argsplit[1]; - break; - case "-r": - case "--root": - rootdir = argsplit[1]; - break; - case "-rar": - case "--rar": - if (!Int32.TryParse(argsplit[1], out rar)) - { - rar = 2; - } - break; - case "-rd": - case "--root-dir": - filter.Root = argsplit[1]; - break; - case "-rep": - case "--rep-ext": - repext = argsplit[1]; - break; - case "-rn": - case "--rom-name": - filter.RomNames.Add(argsplit[1]); - break; - case "-rt": - case "--rom-type": - filter.RomTypes.Add(argsplit[1]); - break; - case "-seq": - case "--equal": - filter.SizeEqualTo = Utilities.GetSizeFromString(argsplit[1]); - break; - case "-sgt": - case "--greater": - filter.SizeGreaterThanOrEqual = Utilities.GetSizeFromString(argsplit[1]); - break; - case "-sha1": - case "--sha1": - filter.SHA1s.Add(argsplit[1]); - break; - case "-sha256": - case "--sha256": - filter.SHA256s.Add(argsplit[1]); - break; - case "-sha384": - case "--sha384": - filter.SHA384s.Add(argsplit[1]); - break; - case "-sha512": - case "--sha512": - filter.SHA512s.Add(argsplit[1]); - break; - case "-slt": - case "--less": - filter.SizeLessThanOrEqual = Utilities.GetSizeFromString(argsplit[1]); - break; - case "-t": - case "--temp": - tempDir = argsplit[1]; - break; - case "-u": - case "-url": - case "--url": - url = argsplit[1]; - break; - case "-v": - case "--version": - version = argsplit[1]; - break; - case "-zip": - case "--zip": - if (!Int32.TryParse(argsplit[1], out zip)) - { - zip = 1; - } - break; - default: - if (File.Exists(temparg) || Directory.Exists(temparg)) - { - inputs.Add(temparg); - } - else - { - Globals.Logger.Error("Invalid input detected: {0}", args[i]); - Globals.Logger.Close(); - return; - } - break; - } - } - else if (File.Exists(temparg) || Directory.Exists(temparg)) - { - inputs.Add(temparg); - } - else - { - Globals.Logger.Error("Invalid input detected: {0}", args[i]); + Globals.Logger.Error("Must be a valid file or folder of DATs: {0}", (string)feat.Value.GetValue()); Globals.Logger.Close(); return; } + datfiles.AddRange((List)feat.Value.GetValue()); + break; + case "desc": + description = (string)feat.Value.GetValue(); + break; + case "email": + email = (string)feat.Value.GetValue(); + break; + case "exta": + exta.AddRange((List)feat.Value.GetValue()); + break; + case "extb": + extb.AddRange((List)feat.Value.GetValue()); + break; + case "filename": + filename = (string)feat.Value.GetValue(); + break; + case "forcemerge": + forcemerge = (string)feat.Value.GetValue(); + break; + case "forcend": + forcend = (string)feat.Value.GetValue(); + break; + case "forcepack": + forcepack = (string)feat.Value.GetValue(); + break; + case "game-name": + filter.GameNames.AddRange((List)feat.Value.GetValue()); + break; + case "game-type": + filter.MachineTypes |= Utilities.GetMachineType((string)feat.Value.GetValue()); + break; + case "gz": + gz = (int)feat.Value.GetValue() == Int32.MinValue ? (int)feat.Value.GetValue() : 1; + break; + case "header": + header = (string)feat.Value.GetValue(); + break; + case "homepage": + homepage = (string)feat.Value.GetValue(); + break; + case "status": + filter.ItemStatuses |= Utilities.GetItemStatus((string)feat.Value.GetValue()); + break; + case "md5": + filter.MD5s.AddRange((List)feat.Value.GetValue()); + break; + case "mt": + Globals.MaxThreads = (int)feat.Value.GetValue() == Int32.MinValue ? (int)feat.Value.GetValue() : Globals.MaxThreads; + break; + case "name": + name = (string)feat.Value.GetValue(); + break; + case "not-crc": + filter.NotCRCs.AddRange((List)feat.Value.GetValue()); + break; + case "not-game": + filter.NotGameNames.AddRange((List)feat.Value.GetValue()); + break; + case "not-gtype": + filter.NotMachineTypes |= Utilities.GetMachineType((string)feat.Value.GetValue()); + break; + case "not-status": + filter.NotItemStatuses |= Utilities.GetItemStatus((string)feat.Value.GetValue()); + break; + case "not-md5": + filter.NotMD5s.AddRange((List)feat.Value.GetValue()); + break; + case "not-rom": + filter.NotRomNames.AddRange((List)feat.Value.GetValue()); + break; + case "not-type": + filter.NotRomTypes.AddRange((List)feat.Value.GetValue()); + break; + case "not-sha1": + filter.NotSHA1s.AddRange((List)feat.Value.GetValue()); + break; + case "not-sha256": + filter.NotSHA256s.AddRange((List)feat.Value.GetValue()); + break; + case "not-sha384": + filter.NotSHA384s.AddRange((List)feat.Value.GetValue()); + break; + case "not-sha512": + filter.NotSHA512s.AddRange((List)feat.Value.GetValue()); + break; + case "out": + outDir = (string)feat.Value.GetValue(); + break; + case "postfix": + postfix = (string)feat.Value.GetValue(); + break; + case "prefix": + prefix = (string)feat.Value.GetValue(); + break; + case "root": + rootdir = (string)feat.Value.GetValue(); + break; + case "rar": + rar = (int)feat.Value.GetValue() == Int32.MinValue ? (int)feat.Value.GetValue() : 1; + break; + case "root-dir": + filter.Root = (string)feat.Value.GetValue(); + break; + case "rep-ext": + repext = (string)feat.Value.GetValue(); + break; + case "rom-name": + filter.RomNames.AddRange((List)feat.Value.GetValue()); + break; + case "rom-type": + filter.RomTypes.AddRange((List)feat.Value.GetValue()); + break; + case "equal": + filter.SizeEqualTo = Utilities.GetSizeFromString((string)feat.Value.GetValue()); + break; + case "greater": + filter.SizeGreaterThanOrEqual = Utilities.GetSizeFromString((string)feat.Value.GetValue()); + break; + case "sha1": + filter.SHA1s.AddRange((List)feat.Value.GetValue()); + break; + case "sha256": + filter.SHA256s.AddRange((List)feat.Value.GetValue()); + break; + case "sha384": + filter.SHA384s.AddRange((List)feat.Value.GetValue()); + break; + case "sha512": + filter.SHA512s.AddRange((List)feat.Value.GetValue()); + break; + case "less": + filter.SizeLessThanOrEqual = Utilities.GetSizeFromString((string)feat.Value.GetValue()); + break; + case "temp": + tempDir = (string)feat.Value.GetValue(); + break; + case "url": + url = (string)feat.Value.GetValue(); + break; + case "version": + version = (string)feat.Value.GetValue(); + break; + case "zip": + zip = (int)feat.Value.GetValue() == Int32.MinValue ? (int)feat.Value.GetValue() : 1; break; } } - // If none of the feature flags is enabled, show the help screen - if (!(datFromDir | extract | restore | sort | split | stats | update | verify)) - { - Globals.Logger.Error("At least one feature switch must be enabled"); - _help.OutputGenericHelp(); - Globals.Logger.Close(); - return; - } - - // If more than one switch is enabled, show the help screen - if (!(datFromDir ^ extract ^ restore ^ sort ^ split ^ stats ^ update ^ verify)) - { - Globals.Logger.Error("Only one feature switch is allowed at a time"); - _help.OutputGenericHelp(); - Globals.Logger.Close(); - return; - } - // If a switch that requires a filename is set and no file is, show the help screen if (inputs.Count == 0 && (datFromDir || extract || restore || split || stats || update || verify)) @@ -997,7 +760,7 @@ namespace SabreTools // Create a DAT from a directory or set of directories if (datFromDir) { - InitDatFromDir(inputs, filename, name, description, category, version, author, email, homepage, url, comment, + InitDatFromDir(inputs, filename, name, description, category, version, author, email, homepage, url, comment, forcepack, excludeOf, sceneDateStrip, datFormat, romba, superdat, omitFromScan, removeDateFromAutomaticName, archivesAsFiles, skipFileType, addBlankFilesForEmptyFolder, addFileDates, tempDir, outDir, copyFiles, header, chdsAsFiles); }