diff --git a/SabreTools.Helper/Data/Flags.cs b/SabreTools.Helper/Data/Flags.cs index 0a803e33..ae75ad43 100644 --- a/SabreTools.Helper/Data/Flags.cs +++ b/SabreTools.Helper/Data/Flags.cs @@ -182,14 +182,39 @@ namespace SabreTools.Helper.Data ExtraData = 0x2 } - #endregion + #endregion - #region DatFile related + #region DatFile related - /// - /// Determines which diffs should be created - /// - [Flags] + /// + /// Determines the DAT output format + /// + [Flags] + public enum DatFormat + { + Logiqx = 0x0001, + ClrMamePro = 0x0002, + RomCenter = 0x0004, + DOSCenter = 0x0008, + MissFile = 0x0010, + SabreDat = 0x0020, + RedumpMD5 = 0x0040, + RedumpSHA1 = 0x0080, + RedumpSFV = 0x0100, + SoftwareList = 0x0200, + OfflineList = 0x0400, + TSV = 0x0800, + CSV = 0x1000, + AttractMode = 0x2000, + RedumpSHA256 = 0x4000, + + ALL = 0xFFFF, + } + + /// + /// Determines which diffs should be created + /// + [Flags] public enum DiffMode { // Standard diffs @@ -203,31 +228,6 @@ namespace SabreTools.Helper.Data ReverseCascade = 0x10, } - /// - /// Determines the DAT output format - /// - [Flags] - public enum DatFormat - { - Logiqx = 0x0001, - ClrMamePro = 0x0002, - RomCenter = 0x0004, - DOSCenter = 0x0008, - MissFile = 0x0010, - SabreDat = 0x0020, - RedumpMD5 = 0x0040, - RedumpSHA1 = 0x0080, - RedumpSFV = 0x0100, - SoftwareList = 0x0200, - OfflineList = 0x0400, - TSV = 0x0800, - CSV = 0x1000, - AttractMode = 0x2000, - RedumpSHA256 = 0x4000, - - ALL = 0xFFFF, - } - /// /// Determine which format to output Stats to /// @@ -240,14 +240,25 @@ namespace SabreTools.Helper.Data TSV = 0x08, } - #endregion + /// + /// Determine what hashes to strip from the DAT + /// + [Flags] + public enum StripHash + { + MD5 = 0x01, + SHA1 = 0x02, + SHA256 = 0x04, + } - #region DatItem related + #endregion - /// - /// Determines which type of duplicate a file is - /// - [Flags] + #region DatItem related + + /// + /// Determines which type of duplicate a file is + /// + [Flags] public enum DupeType { // Type of match diff --git a/SabreTools.Helper/Dats/DatFile.cs b/SabreTools.Helper/Dats/DatFile.cs index 4a970cca..144e78b3 100644 --- a/SabreTools.Helper/Dats/DatFile.cs +++ b/SabreTools.Helper/Dats/DatFile.cs @@ -30,6 +30,7 @@ namespace SabreTools.Helper.Dats private DatFormat _datFormat; private bool _excludeOf; private bool _mergeRoms; + private StripHash _stripHash; private SortedDictionary> _files = new SortedDictionary>(); private SortedBy _sortedBy; @@ -160,6 +161,11 @@ namespace SabreTools.Helper.Dats get { return _mergeRoms; } set { _mergeRoms = value; } } + public StripHash StripHash + { + get { return _stripHash; } + set { _stripHash = value; } + } public SortedBy SortedBy { get { return _sortedBy; } @@ -540,6 +546,7 @@ namespace SabreTools.Helper.Dats _excludeOf = datFile.ExcludeOf; _datFormat = datFile.DatFormat; _mergeRoms = datFile.MergeRoms; + _stripHash = datFile.StripHash; _sortedBy = SortedBy.Default; _useGame = datFile.UseGame; _prefix = datFile.Prefix; diff --git a/SabreTools.Helper/Dats/Partials/DatFile.ConvertUpdate.cs b/SabreTools.Helper/Dats/Partials/DatFile.ConvertUpdate.cs index 7abe3718..f6831a8e 100644 --- a/SabreTools.Helper/Dats/Partials/DatFile.ConvertUpdate.cs +++ b/SabreTools.Helper/Dats/Partials/DatFile.ConvertUpdate.cs @@ -434,6 +434,88 @@ namespace SabreTools.Helper.Dats WriteToFile(outDir, logger); } + /// + /// Strip the given hash types from the DAT + /// + /// Logging object for console and file output + private void StripHashesFromItems(Logger logger) + { + // Output the logging statement + string set = ""; + switch ((int)StripHash) + { + case 0x01: + set = "MD5"; + break; + case 0x02: + set = "SHA-1"; + break; + case 0x03: + set = "MD5 and SHA-1"; + break; + case 0x04: + set = "SHA-256"; + break; + case 0x05: + set = "MD5 and SHA-256"; + break; + case 0x06: + set = "SHA-1 and SHA-256"; + break; + case 0x07: + set = "MD5, SHA-1, and SHA-256"; + break; + } + logger.User("Stripping " + set + " hashes"); + + // Now process all of the roms + List keys = Keys.ToList(); + for (int i = 0; i < keys.Count; i++) + { + List items = this[keys[i]]; + for (int j = 0; j < items.Count; j++) + { + DatItem item = items[j]; + if (item.Type == ItemType.Rom) + { + Rom rom = (Rom)item; + if ((StripHash & StripHash.MD5) != 0) + { + rom.MD5 = null; + } + if ((StripHash & StripHash.SHA1) != 0) + { + rom.SHA1 = null; + } + if ((StripHash & StripHash.SHA256) != 0) + { + rom.SHA256 = null; + } + items[j] = rom; + } + else if (item.Type == ItemType.Disk) + { + Disk disk = (Disk)item; + if ((StripHash & StripHash.MD5) != 0) + { + disk.MD5 = null; + } + if ((StripHash & StripHash.SHA1) != 0) + { + disk.SHA1 = null; + } + if ((StripHash & StripHash.SHA256) != 0) + { + disk.SHA256 = null; + } + items[j] = disk; + } + } + + this[keys[i]] = items; + } + } + /// /// Convert, update, and filter a DAT file or set of files using a base /// diff --git a/SabreTools.Helper/Dats/Partials/DatFile.Writers.cs b/SabreTools.Helper/Dats/Partials/DatFile.Writers.cs index 687662be..64d6b90e 100644 --- a/SabreTools.Helper/Dats/Partials/DatFile.Writers.cs +++ b/SabreTools.Helper/Dats/Partials/DatFile.Writers.cs @@ -111,6 +111,12 @@ namespace SabreTools.Helper.Dats // Bucket roms by game name and optionally dedupe BucketByGame(MergeRoms, norename, logger); + // If we are removing hashes, do that now + if (_stripHash != 0x0) + { + StripHashesFromItems(logger); + } + // Get the outfile names Dictionary outfiles = Style.CreateOutfileNames(outDir, this, overwrite); diff --git a/SabreTools.Helper/README.1ST b/SabreTools.Helper/README.1ST index a86d9ff8..56c0950e 100644 --- a/SabreTools.Helper/README.1ST +++ b/SabreTools.Helper/README.1ST @@ -878,6 +878,18 @@ Options: Game names will be santitized to remove what the original WoD standards deemed as unneeded information, such as parenthized or bracketed strings + -rmd5, --rem-md5 Remove MD5 hashes from the output + By default, all available hashes will be written out to the DAT. This will + remove all MD5 hashes from the output file(s). + + -rsha1, --rem-sha1 Remove SHA-1 hashes from the output + By default, all available hashes will be written out to the DAT. This will + remove all SHA-1 hashes from the output file(s). + + -rsha256, --rem-sha256 Remove SHA-256 hashes from the output + By default, all available hashes will be written out to the DAT. This will + remove all SHA-256 hashes from the output file(s). + -dan, --desc-name Use Software List name instead of description By default, all DATs are converted exactly as they are input. Enabling this flag allows for the machine names in the DAT to be replaced by the machine description diff --git a/SabreTools/Partials/SabreTools.Help.cs b/SabreTools/Partials/SabreTools.Help.cs index 5c31c38b..8d9571f6 100644 --- a/SabreTools/Partials/SabreTools.Help.cs +++ b/SabreTools/Partials/SabreTools.Help.cs @@ -966,6 +966,21 @@ namespace SabreTools "Clean game names according to WoD standards", FeatureType.Flag, null)); + update.AddFeature("rem-md5", new Feature( + new List() { "-rmd5", "--rem-md5" }, + "Remove MD5 hashes from the output", + FeatureType.Flag, + null)); + update.AddFeature("rem-sha1", new Feature( + new List() { "-rsha1", "--rem-sha1" }, + "Remove SHA-1 hashes from the output", + FeatureType.Flag, + null)); + update.AddFeature("rem-sha256", new Feature( + new List() { "-rsha256", "--rem-sha256" }, + "Remove SHA-256 hashes from the output", + FeatureType.Flag, + null)); update.AddFeature("desc-name", new Feature( new List() { "-dan", "--desc-name" }, "Use description instead of machine name", diff --git a/SabreTools/Partials/SabreTools.Inits.cs b/SabreTools/Partials/SabreTools.Inits.cs index fb827446..488326ad 100644 --- a/SabreTools/Partials/SabreTools.Inits.cs +++ b/SabreTools/Partials/SabreTools.Inits.cs @@ -473,6 +473,7 @@ namespace SabreTools /// True to clean the game names to WoD standard, false otherwise (default) /// True if descriptions should be used as names, false otherwise (default) /// True to dedupe the roms in the DAT, false otherwise (default) + /// StripHash that represents the hash(es) that you want to remove from the output /// /* Multithreading info */ /// Integer representing the maximum amount of parallelization to be used private static void InitUpdate(List inputs, @@ -529,6 +530,7 @@ namespace SabreTools bool clean, bool descAsName, bool dedup, + StripHash stripHash, /* Multithreading info */ int maxDegreeOfParallelism) @@ -654,6 +656,7 @@ namespace SabreTools MergeRoms = dedup, ExcludeOf = excludeOf, DatFormat = datFormat, + StripHash = stripHash, UseGame = usegame, Prefix = prefix, diff --git a/SabreTools/SabreTools.cs b/SabreTools/SabreTools.cs index 51c9be1e..54550a8f 100644 --- a/SabreTools/SabreTools.cs +++ b/SabreTools/SabreTools.cs @@ -125,6 +125,7 @@ namespace SabreTools OutputFormat outputFormat = OutputFormat.Folder; SplitType splitType = SplitType.None; StatDatFormat statDatFormat = 0x0; + StripHash stripHash = 0x0; // User inputs int gz = 2, @@ -487,6 +488,10 @@ namespace SabreTools case "--rev-cascade": diffMode |= DiffMode.ReverseCascade; break; + case "-rmd5": + case "--rem-md5": + stripHash |= StripHash.MD5; + break; case "-rme": case "--rem-ext": remext = true; @@ -495,6 +500,14 @@ namespace SabreTools case "--romba": romba = true; break; + case "-rsha1": + case "--rem-sha1": + stripHash |= StripHash.SHA1; + break; + case "-rsha256": + case "--rem-sha256": + stripHash |= StripHash.SHA256; + break; case "-run": case "--runnable": filter.Runnable = true; @@ -1187,7 +1200,7 @@ namespace SabreTools InitUpdate(inputs, filename, name, description, rootdir, category, version, date, author, email, homepage, url, comment, header, superdat, forcemerge, forcend, forcepack, excludeOf, datFormat, usegame, prefix, postfix, quotes, repext, addext, remext, datPrefix, romba, merge, diffMode, inplace, skip, removeDateFromAutomaticName, - filter, splitType, trim, single, root, outDir, cleanGameNames, descAsName, dedup, maxParallelism); + filter, splitType, trim, single, root, outDir, cleanGameNames, descAsName, dedup, stripHash, maxParallelism); } // If we're using the verifier