diff --git a/SabreTools.Library/DatFiles/DatFile.cs b/SabreTools.Library/DatFiles/DatFile.cs index 3c5aef7e..99876055 100644 --- a/SabreTools.Library/DatFiles/DatFile.cs +++ b/SabreTools.Library/DatFiles/DatFile.cs @@ -3453,8 +3453,10 @@ namespace SabreTools.Library.DatFiles /// Output directory to /// True if files should be copied to the temp directory before hashing, false otherwise /// Populated string representing the name of the skipper to use, a blank string to use the first available checker, null otherwise + /// True if CHDs should be treated like regular files, false otherwise public bool PopulateFromDir(string basePath, Hash omitFromScan, bool bare, bool archivesAsFiles, bool enableGzip, - SkipFileType skipFileType, bool addBlanks, bool addDate, string tempDir, bool copyFiles, string headerToCheckAgainst) + SkipFileType skipFileType, bool addBlanks, bool addDate, string tempDir, bool copyFiles, string headerToCheckAgainst, + bool ignorechd) { // If the description is defined but not the name, set the name from the description if (String.IsNullOrEmpty(Name) && !String.IsNullOrEmpty(Description)) @@ -3485,7 +3487,7 @@ namespace SabreTools.Library.DatFiles Parallel.ForEach(files, Globals.ParallelOptions, item => { CheckFileForHashes(item, basePath, omitFromScan, bare, archivesAsFiles, enableGzip, skipFileType, - addBlanks, addDate, tempDir, copyFiles, headerToCheckAgainst); + addBlanks, addDate, tempDir, copyFiles, headerToCheckAgainst, ignorechd); }); // Find all top-level subfolders @@ -3496,7 +3498,7 @@ namespace SabreTools.Library.DatFiles Parallel.ForEach(subfiles, Globals.ParallelOptions, subitem => { CheckFileForHashes(subitem, basePath, omitFromScan, bare, archivesAsFiles, enableGzip, skipFileType, - addBlanks, addDate, tempDir, copyFiles, headerToCheckAgainst); + addBlanks, addDate, tempDir, copyFiles, headerToCheckAgainst, ignorechd); }); } @@ -3553,7 +3555,7 @@ namespace SabreTools.Library.DatFiles else if (File.Exists(basePath)) { CheckFileForHashes(basePath, Path.GetDirectoryName(Path.GetDirectoryName(basePath)), omitFromScan, bare, archivesAsFiles, enableGzip, - skipFileType, addBlanks, addDate, tempDir, copyFiles, headerToCheckAgainst); + skipFileType, addBlanks, addDate, tempDir, copyFiles, headerToCheckAgainst, ignorechd); } // Now that we're done, delete the temp folder (if it's not the default) @@ -3581,8 +3583,10 @@ namespace SabreTools.Library.DatFiles /// Name of the directory to create a temp folder in (blank is current directory) /// True if files should be copied to the temp directory before hashing, false otherwise /// Populated string representing the name of the skipper to use, a blank string to use the first available checker, null otherwise + /// True if CHDs should be treated like regular files, false otherwise private void CheckFileForHashes(string item, string basePath, Hash omitFromScan, bool bare, bool archivesAsFiles, - bool enableGzip, SkipFileType skipFileType, bool addBlanks, bool addDate, string tempDir, bool copyFiles, string headerToCheckAgainst) + bool enableGzip, SkipFileType skipFileType, bool addBlanks, bool addDate, string tempDir, bool copyFiles, + string headerToCheckAgainst, bool ignorechd) { // Define the temporary directory string tempSubDir = Path.GetFullPath(Path.Combine(tempDir, Path.GetRandomFileName())) + Path.DirectorySeparatorChar; @@ -3653,7 +3657,7 @@ namespace SabreTools.Library.DatFiles // If the extracted list is null, just scan the item itself if (extracted == null || archivesAsFiles) { - ProcessFile(newItem, "", newBasePath, omitFromScan, addDate, headerToCheckAgainst); + ProcessFile(newItem, "", newBasePath, omitFromScan, addDate, headerToCheckAgainst, ignorechd); } // Otherwise, add all of the found items else @@ -3701,11 +3705,12 @@ namespace SabreTools.Library.DatFiles /// Hash flag saying what hashes should not be calculated /// True if dates should be archived for all files, false otherwise /// Populated string representing the name of the skipper to use, a blank string to use the first available checker, null otherwise + /// True if CHDs should be treated like regular files, false otherwise private void ProcessFile(string item, string parent, string basePath, Hash omitFromScan, - bool addDate, string headerToCheckAgainst) + bool addDate, string headerToCheckAgainst, bool ignorechd) { Globals.Logger.Verbose("'{0}' treated like a file", Path.GetFileName(item)); - DatItem rom = FileTools.GetFileInfo(item, omitFromScan: omitFromScan, date: addDate, header: headerToCheckAgainst); + DatItem rom = FileTools.GetFileInfo(item, omitFromScan: omitFromScan, date: addDate, header: headerToCheckAgainst, ignorechd: ignorechd); ProcessFileHelper(item, rom, basePath, parent); } @@ -3730,9 +3735,9 @@ namespace SabreTools.Library.DatFiles { key = ((Rom)datItem).Size + "-" + ((Rom)datItem).CRC; } - else + else if (datItem.Type == ItemType.Disk) { - key = ((Disk)datItem).MD5; + key = ((Disk)datItem).SHA1; } // Add the list if it doesn't exist already @@ -4785,8 +4790,9 @@ namespace SabreTools.Library.DatFiles /// True if only hashes should be checked, false for full file information /// True to enable external scanning of archives, false otherwise /// Populated string representing the name of the skipper to use, a blank string to use the first available checker, null otherwise + /// True if CHDs should be treated like regular files, false otherwise /// True if verification was a success, false otherwise - public bool VerifyGeneric(List inputs, string tempDir, bool hashOnly, bool quickScan, string headerToCheckAgainst) + public bool VerifyGeneric(List inputs, string tempDir, bool hashOnly, bool quickScan, string headerToCheckAgainst, bool ignorechd) { // Check the temp directory exists if (String.IsNullOrEmpty(tempDir)) @@ -4814,7 +4820,7 @@ namespace SabreTools.Library.DatFiles // TODO: All instances of Hash.DeepHashes should be made into 0x0 eventually PopulateFromDir(input, (quickScan ? Hash.SecureHashes : Hash.DeepHashes) /* omitFromScan */, true /* bare */, false /* archivesAsFiles */, true /* enableGzip */, SkipFileType.None, false /* addBlanks */, false /* addDate */, tempDir /* tempDir */, false /* copyFiles */, - headerToCheckAgainst); + headerToCheckAgainst, ignorechd); } // Setup the fixdat diff --git a/SabreTools.Library/README.1ST b/SabreTools.Library/README.1ST index 3fca33d7..a4a6b635 100644 --- a/SabreTools.Library/README.1ST +++ b/SabreTools.Library/README.1ST @@ -349,6 +349,11 @@ Options: that skipper exists, then it will be used instead of trying to find one that matches. + -ic, --ignore-chd Treat CHDs as regular files + Normally, CHDs would be processed using their internal hash to + compare against the input DATs. This flag forces all CHDs to + be treated like regular files. + -t=, --temp= Set the name of the temporary directory Optionally, a temp folder can be supplied in the case the default temp directory (inside the running folder) is not preferred. This is @@ -500,6 +505,11 @@ Options: to the temp folder. On the downside, it can only get the CRC and size from most archive formats, leading to possible issues. + -ic, --ignore-chd Treat CHDs as regular files + Normally, CHDs would be processed using their internal hash to + compare against the input DATs. This flag forces all CHDs to + be treated like regular files. + -ad, --add-date Write dates for each file parsed, if available If this flag is set, the the date in the DAT will be used for the output file instead of the standard date and time for TorrentZip. @@ -1311,6 +1321,11 @@ Options: that skipper exists, then it will be used instead of trying to find one that matches. + -ic, --ignore-chd Treat CHDs as regular files + Normally, CHDs would be processed using their internal hash to + compare against the input DATs. This flag forces all CHDs to + be treated like regular files. + -dm, --dat-merged Force checking merged sets Preprocess the DAT to have parent sets contain all items from the children based on the cloneof tag. This is incompatible with the diff --git a/SabreTools/SabreTools.Help.cs b/SabreTools/SabreTools.Help.cs index 2155f8da..a04f2640 100644 --- a/SabreTools/SabreTools.Help.cs +++ b/SabreTools/SabreTools.Help.cs @@ -285,6 +285,11 @@ namespace SabreTools "Set a header skipper to use, blank means all", FeatureType.Flag, null)); + datFromDir.AddFeature("ignore-chd", new Feature( + new List() { "-ic", "--ignore-chd" }, + "Treat CHDs as regular files", + FeatureType.Flag, + null)); datFromDir.AddFeature("temp", new Feature( new List() { "-t", "--temp" }, "Set the temporary directory to use", @@ -424,6 +429,11 @@ namespace SabreTools "Enable quick scanning of archives", FeatureType.Flag, null)); + sort.AddFeature("ignore-chd", new Feature( + new List() { "-ic", "--ignore-chd" }, + "Treat CHDs as regular files", + FeatureType.Flag, + null)); sort.AddFeature("add-date", new Feature( new List() { "-ad", "--add-date" }, "Add original dates from DAT, if possible", @@ -1448,6 +1458,11 @@ namespace SabreTools "Set a header skipper to use, blank means all", FeatureType.String, null)); + verify.AddFeature("ignore-chd", new Feature( + new List() { "-ic", "--ignore-chd" }, + "Treat CHDs as regular files", + FeatureType.Flag, + null)); verify.AddFeature("dat-merged", new Feature( new List() { "-dm", "--dat-merged" }, "Force checking merged sets", diff --git a/SabreTools/SabreTools.Inits.cs b/SabreTools/SabreTools.Inits.cs index 03af2757..8f7996c0 100644 --- a/SabreTools/SabreTools.Inits.cs +++ b/SabreTools/SabreTools.Inits.cs @@ -53,6 +53,7 @@ namespace SabreTools /// Name of the directory to output the DAT to (blank is the current directory) /// True if files should be copied to the temp directory before hashing, false otherwise /// Populated string representing the name of the skipper to use, a blank string to use the first available checker, null otherwise + /// True if CHDs should be treated like regular files, false otherwise private static void InitDatFromDir(List inputs, /* Normal DAT header info */ string filename, @@ -85,7 +86,8 @@ namespace SabreTools string tempDir, string outDir, bool copyFiles, - string headerToCheckAgainst) + string headerToCheckAgainst, + bool ignorechd) { ForcePacking fp = ForcePacking.None; switch (forcepack?.ToLowerInvariant()) @@ -137,7 +139,7 @@ namespace SabreTools string basePath = Path.GetFullPath(path); bool success = datdata.PopulateFromDir(basePath, omitFromScan, removeDateFromAutomaticName, parseArchivesAsFiles, enableGzip, - skipFileType, addBlankFilesForEmptyFolder, addFileDates, tempDir, copyFiles, headerToCheckAgainst); + skipFileType, addBlankFilesForEmptyFolder, addFileDates, tempDir, copyFiles, headerToCheckAgainst, ignorechd); // If it was a success, write the DAT out if (success) @@ -332,9 +334,10 @@ namespace SabreTools /// True if the updated DAT should be output, false otherwise /// Populated string representing the name of the skipper to use, a blank string to use the first available checker, null otherwise /// Type of the split that should be performed (split, merged, fully merged) + /// True if CHDs should be treated like regular files, false otherwise private static void InitSort(List datfiles, List inputs, string outDir, string tempDir, bool quickScan, bool date, bool delete, bool inverse, OutputFormat outputFormat, bool romba, int sevenzip, int gz, int rar, int zip, bool updateDat, string headerToCheckAgainst, - SplitType splitType) + SplitType splitType, bool ignorechd) { // Get the archive scanning level ArchiveScanLevel asl = ArchiveTools.GetArchiveScanLevelFromNumbers(sevenzip, gz, rar, zip); @@ -354,7 +357,7 @@ namespace SabreTools watch.Stop(); datdata.RebuildGeneric(inputs, outDir, tempDir, quickScan, date, delete, inverse, outputFormat, romba, asl, - updateDat, headerToCheckAgainst, true /* ignorechd */); + updateDat, headerToCheckAgainst, ignorechd); } /// @@ -745,8 +748,9 @@ namespace SabreTools /// True to enable external scanning of archives, false otherwise /// Populated string representing the name of the skipper to use, a blank string to use the first available checker, null otherwise /// Type of the split that should be performed (split, merged, fully merged) + /// True if CHDs should be treated like regular files, false otherwise private static void InitVerify(List datfiles, List inputs, string tempDir, - bool hashOnly, bool quickScan, string headerToCheckAgainst, SplitType splitType) + bool hashOnly, bool quickScan, string headerToCheckAgainst, SplitType splitType, bool ignorechd) { // Get the archive scanning level ArchiveScanLevel asl = ArchiveTools.GetArchiveScanLevelFromNumbers(1, 1, 1, 1); @@ -765,7 +769,7 @@ namespace SabreTools watch.Stop(); - datdata.VerifyGeneric(inputs, tempDir, hashOnly, quickScan, headerToCheckAgainst); + datdata.VerifyGeneric(inputs, tempDir, hashOnly, quickScan, headerToCheckAgainst, ignorechd); } /// diff --git a/SabreTools/SabreTools.cs b/SabreTools/SabreTools.cs index 5b0ce0d3..9c2c59cb 100644 --- a/SabreTools/SabreTools.cs +++ b/SabreTools/SabreTools.cs @@ -99,7 +99,8 @@ namespace SabreTools enableGzip = false, excludeOf = false, hashOnly = false, - inplace = false, + ignorechd = false, + inplace = true, inverse = false, merge = false, oneGameOneRegion = false, @@ -396,6 +397,10 @@ namespace SabreTools case "--html": statDatFormat |= StatDatFormat.HTML; break; + case "-ic": + case "--ignore-chd": + ignorechd = true; + break; case "-in": case "--inverse": inverse = true; @@ -1255,7 +1260,7 @@ namespace SabreTools { InitDatFromDir(inputs, filename, name, description, category, version, author, email, homepage, url, comment, forcepack, excludeOf, sceneDateStrip, datFormat, romba, superdat, omitFromScan, removeDateFromAutomaticName, parseArchivesAsFiles, - enableGzip, skipFileType, addBlankFilesForEmptyFolder, addFileDates, tempDir, outDir, copyFiles, header); + enableGzip, skipFileType, addBlankFilesForEmptyFolder, addFileDates, tempDir, outDir, copyFiles, header, ignorechd); } // If we're in header extract and remove mode @@ -1274,7 +1279,7 @@ namespace SabreTools else if (sort) { InitSort(datfiles, inputs, outDir, tempDir, quickScan, addFileDates, delete, inverse, - outputFormat, romba, sevenzip, gz, rar, zip, updateDat, header, splitType); + outputFormat, romba, sevenzip, gz, rar, zip, updateDat, header, splitType, ignorechd); } // If we're using the sorter from depot @@ -1326,7 +1331,7 @@ namespace SabreTools // If we're using the verifier else if (verify) { - InitVerify(datfiles, inputs, tempDir, hashOnly, quickScan, header, splitType); + InitVerify(datfiles, inputs, tempDir, hashOnly, quickScan, header, splitType, ignorechd); } // If we're using the depot verifier