diff --git a/SabreTools.Helper/Dats/Partials/DatFile.DFD.cs b/SabreTools.Helper/Dats/Partials/DatFile.DFD.cs index 3c7f65d5..0c89ddcb 100644 --- a/SabreTools.Helper/Dats/Partials/DatFile.DFD.cs +++ b/SabreTools.Helper/Dats/Partials/DatFile.DFD.cs @@ -26,9 +26,7 @@ namespace SabreTools.Helper.Dats /// Create a new Dat from a directory /// /// Base folder to be used in creating the DAT - /// True if MD5 hashes should be skipped over, false otherwise - /// True if SHA-1 hashes should be skipped over, false otherwise - /// True if SHA-256 hashes should be skipped over, false otherwise + /// Hash flag saying what hashes should not be calculated /// True if the date should be omitted from the DAT, false otherwise /// True if archives should be treated as files, false otherwise /// True if GZIP archives should be treated as files, false otherwise @@ -40,7 +38,7 @@ namespace SabreTools.Helper.Dats /// Populated string representing the name of the skipper to use, a blank string to use the first available checker, null otherwise /// Integer representing the maximum amount of parallelization to be used /// Logger object for console and file output - public bool PopulateFromDir(string basePath, bool noMD5, bool noSHA1, bool noSHA256, bool bare, bool archivesAsFiles, + public bool PopulateFromDir(string basePath, Hash omitFromScan, bool bare, bool archivesAsFiles, bool enableGzip, bool addBlanks, bool addDate, string tempDir, bool copyFiles, string headerToCheckAgainst, int maxDegreeOfParallelism, Logger logger) { @@ -74,7 +72,7 @@ namespace SabreTools.Helper.Dats new ParallelOptions { MaxDegreeOfParallelism = maxDegreeOfParallelism }, item => { - PopulateFromDirCheckFile(item, basePath, noMD5, noSHA1, noSHA256, bare, archivesAsFiles, enableGzip, addBlanks, addDate, + PopulateFromDirCheckFile(item, basePath, omitFromScan, bare, archivesAsFiles, enableGzip, addBlanks, addDate, tempDir, copyFiles, headerToCheckAgainst, maxDegreeOfParallelism, logger); }); @@ -89,7 +87,7 @@ namespace SabreTools.Helper.Dats new ParallelOptions { MaxDegreeOfParallelism = maxDegreeOfParallelism }, subitem => { - PopulateFromDirCheckFile(subitem, basePath, noMD5, noSHA1, noSHA256, bare, archivesAsFiles, enableGzip, addBlanks, addDate, + PopulateFromDirCheckFile(subitem, basePath, omitFromScan, bare, archivesAsFiles, enableGzip, addBlanks, addDate, tempDir, copyFiles, headerToCheckAgainst, maxDegreeOfParallelism, logger); }); }); @@ -151,7 +149,7 @@ namespace SabreTools.Helper.Dats } else if (File.Exists(basePath)) { - PopulateFromDirCheckFile(basePath, Path.GetDirectoryName(Path.GetDirectoryName(basePath)), noMD5, noSHA1, noSHA256, bare, archivesAsFiles, enableGzip, addBlanks, addDate, + PopulateFromDirCheckFile(basePath, Path.GetDirectoryName(Path.GetDirectoryName(basePath)), omitFromScan, bare, archivesAsFiles, enableGzip, addBlanks, addDate, tempDir, copyFiles, headerToCheckAgainst, maxDegreeOfParallelism, logger); } @@ -177,9 +175,7 @@ namespace SabreTools.Helper.Dats /// /// Filename of the item to be checked /// Base folder to be used in creating the DAT - /// True if MD5 hashes should be skipped over, false otherwise - /// True if SHA-1 hashes should be skipped over, false otherwise - /// True if SHA-256 hashes should be skipped over, false otherwise + /// Hash flag saying what hashes should not be calculated /// True if the date should be omitted from the DAT, false otherwise /// True if archives should be treated as files, false otherwise /// True if GZIP archives should be treated as files, false otherwise @@ -190,7 +186,7 @@ namespace SabreTools.Helper.Dats /// Populated string representing the name of the skipper to use, a blank string to use the first available checker, null otherwise /// Integer representing the maximum amount of parallelization to be used /// Logger object for console and file output - private void PopulateFromDirCheckFile(string item, string basePath, bool noMD5, bool noSHA1, bool noSHA256, bool bare, bool archivesAsFiles, + private void PopulateFromDirCheckFile(string item, string basePath, Hash omitFromScan, bool bare, bool archivesAsFiles, bool enableGzip, bool addBlanks, bool addDate, string tempDir, bool copyFiles, string headerToCheckAgainst, int maxDegreeOfParallelism, Logger logger) { @@ -230,7 +226,7 @@ namespace SabreTools.Helper.Dats } // If all deep hash skip flags are set, do a quickscan - if (noMD5 && noSHA1 && noSHA256) + if (omitFromScan == (Hash.MD5 & Hash.SHA1 & Hash.SHA256 & Hash.SHA384 & Hash.SHA512)) { ArchiveType? type = ArchiveTools.GetCurrentArchiveType(newItem, logger); @@ -251,7 +247,7 @@ namespace SabreTools.Helper.Dats // Otherwise, just get the info on the file itself else if (File.Exists(newItem)) { - PopulateFromDirProcessFile(newItem, "", newBasePath, noMD5, noSHA1, noSHA256, addDate, headerToCheckAgainst, logger); + PopulateFromDirProcessFile(newItem, "", newBasePath, omitFromScan, addDate, headerToCheckAgainst, logger); } } // Otherwise, attempt to extract the files to the temporary directory @@ -279,9 +275,7 @@ namespace SabreTools.Helper.Dats : ""), Path.GetFileNameWithoutExtension(item)), tempSubDir, - noMD5, - noSHA1, - noSHA256, + omitFromScan, addDate, headerToCheckAgainst, logger); @@ -290,7 +284,7 @@ namespace SabreTools.Helper.Dats // Otherwise, just get the info on the file itself else if (File.Exists(newItem)) { - PopulateFromDirProcessFile(newItem, "", newBasePath, noMD5, noSHA1, noSHA256, addDate, headerToCheckAgainst, logger); + PopulateFromDirProcessFile(newItem, "", newBasePath, omitFromScan, addDate, headerToCheckAgainst, logger); } } @@ -317,17 +311,15 @@ namespace SabreTools.Helper.Dats /// File to be added /// Parent game to be used /// Path the represents the parent directory - /// True if MD5 hashes should be skipped over, false otherwise - /// True if SHA-1 hashes should be skipped over, false otherwise - /// True if SHA-256 hashes should be skipped over, false otherwise + /// 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 /// Logger object for console and file output - private void PopulateFromDirProcessFile(string item, string parent, string basePath, bool noMD5, bool noSHA1, - bool noSHA256, bool addDate, string headerToCheckAgainst, Logger logger) + private void PopulateFromDirProcessFile(string item, string parent, string basePath, Hash omitFromScan, + bool addDate, string headerToCheckAgainst, Logger logger) { logger.Verbose(Path.GetFileName(item) + " treated like a file"); - Rom rom = FileTools.GetFileInfo(item, logger, noMD5: noMD5, noSHA1: noSHA1, noSHA256: noSHA256, date: addDate, header: headerToCheckAgainst); + Rom rom = FileTools.GetFileInfo(item, logger, omitFromScan: omitFromScan, date: addDate, header: headerToCheckAgainst); PopulateFromDirProcessFileHelper(item, rom, basePath, parent, logger); } diff --git a/SabreTools.Helper/Tools/FileTools.cs b/SabreTools.Helper/Tools/FileTools.cs index c4ac454a..9cc71a7b 100644 --- a/SabreTools.Helper/Tools/FileTools.cs +++ b/SabreTools.Helper/Tools/FileTools.cs @@ -188,15 +188,13 @@ namespace SabreTools.Helper.Tools /// /// Filename to get information from /// Logger object for console and file output - /// True if MD5 hashes should not be calculated, false otherwise (default) - /// True if SHA-1 hashes should not be calcluated, false otherwise (default) - /// True if SHA-256 hashes should not be calcluated, false otherwise (default) + /// Hash flag saying what hashes should not be calculated (defaults to none) /// Set a >0 number for getting hash for part of the file, 0 otherwise (default) /// True if the file Date should be included, false otherwise (default) /// Populated string representing the name of the skipper to use, a blank string to use the first available checker, null otherwise /// Populated RomData object if success, empty one on error - public static Rom GetFileInfo(string input, Logger logger, bool noMD5 = false, bool noSHA1 = false, - bool noSHA256 = false, long offset = 0, bool date = false, string header = null) + public static Rom GetFileInfo(string input, Logger logger, Hash omitFromScan = 0x0, + long offset = 0, bool date = false, string header = null) { // Add safeguard if file doesn't exist if (!File.Exists(input)) @@ -228,12 +226,12 @@ namespace SabreTools.Helper.Tools // Otherwise, just get the info else { - rom = GetStreamInfo(File.OpenRead(input), new FileInfo(input).Length, noMD5, noSHA1, noSHA256, offset, false); + rom = GetStreamInfo(File.OpenRead(input), new FileInfo(input).Length, omitFromScan, offset, false); } } else { - rom = GetStreamInfo(File.OpenRead(input), new FileInfo(input).Length, noMD5, noSHA1, noSHA256, offset, false); + rom = GetStreamInfo(File.OpenRead(input), new FileInfo(input).Length, omitFromScan, offset, false); } // Add unique data from the file @@ -509,14 +507,12 @@ namespace SabreTools.Helper.Tools /// /// Filename to get information from /// Size of the input stream - /// True if MD5 hashes should not be calculated, false otherwise (default) - /// True if SHA-1 hashes should not be calcluated, false otherwise (default) - /// True if SHA-256 hashes should not be calcluated, false otherwise (default) + /// Hash flag saying what hashes should not be calculated (defaults to none) /// Set a >0 number for getting hash for part of the file, 0 otherwise (default) /// True if the underlying read stream should be kept open, false otherwise /// Populated RomData object if success, empty one on error - public static Rom GetStreamInfo(Stream input, long size, bool noMD5 = false, bool noSHA1 = false, - bool noSHA256 = false, long offset = 0, bool keepReadOpen = false) + public static Rom GetStreamInfo(Stream input, long size, Hash omitFromScan = 0x0, + long offset = 0, bool keepReadOpen = false) { Rom rom = new Rom { @@ -551,15 +547,15 @@ namespace SabreTools.Helper.Tools while ((read = input.Read(buffer, 0, buffer.Length)) > 0) { crc.Update(buffer, 0, read); - if (!noMD5) + if ((omitFromScan & Hash.MD5) == 0) { md5.TransformBlock(buffer, 0, read, buffer, 0); } - if (!noSHA1) + if ((omitFromScan & Hash.SHA1) == 0) { sha1.TransformBlock(buffer, 0, read, buffer, 0); } - if (!noSHA256) + if ((omitFromScan & Hash.SHA256) == 0) { sha256.TransformBlock(buffer, 0, read, buffer, 0); } @@ -568,17 +564,17 @@ namespace SabreTools.Helper.Tools crc.Update(buffer, 0, 0); rom.CRC = crc.Value.ToString("X8").ToLowerInvariant(); - if (!noMD5) + if ((omitFromScan & Hash.MD5) == 0) { md5.TransformFinalBlock(buffer, 0, 0); rom.MD5 = BitConverter.ToString(md5.Hash).Replace("-", "").ToLowerInvariant(); } - if (!noSHA1) + if ((omitFromScan & Hash.SHA1) == 0) { sha1.TransformFinalBlock(buffer, 0, 0); rom.SHA1 = BitConverter.ToString(sha1.Hash).Replace("-", "").ToLowerInvariant(); } - if (!noSHA256) + if ((omitFromScan & Hash.SHA256) == 0) { sha256.TransformFinalBlock(buffer, 0, 0); rom.SHA256 = BitConverter.ToString(sha256.Hash).Replace("-", "").ToLowerInvariant(); diff --git a/SabreTools/Partials/SabreTools.Inits.cs b/SabreTools/Partials/SabreTools.Inits.cs index 7bc54d18..d6fc5e9a 100644 --- a/SabreTools/Partials/SabreTools.Inits.cs +++ b/SabreTools/Partials/SabreTools.Inits.cs @@ -35,9 +35,7 @@ namespace SabreTools /// DatFormat to be used for outputting the DAT /// True to enable reading a directory like a Romba depot, false otherwise /// True to enable SuperDAT-style reading, false otherwise - /// True to disable getting MD5 hash, false otherwise - /// True to disable getting SHA-1 hash, false otherwise - /// True to disable getting SHA-256 hash, false otherwise + /// Hash flag saying what hashes should not be calculated /// True if the date should be omitted from the DAT, false otherwise /// True if archives should be treated as files, false otherwise /// True if GZIP archives should be treated as files, false otherwise @@ -60,9 +58,7 @@ namespace SabreTools DatFormat datFormat, bool romba, bool superdat, - bool noMD5, - bool noSHA1, - bool noSHA256, + Hash omitFromScan, bool removeDateFromAutomaticName, bool parseArchivesAsFiles, bool enableGzip, @@ -118,7 +114,7 @@ namespace SabreTools DatFile datdata = new DatFile(basedat); string basePath = Path.GetFullPath(path); - bool success = datdata.PopulateFromDir(basePath, noMD5, noSHA1, noSHA256, removeDateFromAutomaticName, parseArchivesAsFiles, enableGzip, + bool success = datdata.PopulateFromDir(basePath, omitFromScan, removeDateFromAutomaticName, parseArchivesAsFiles, enableGzip, addBlankFilesForEmptyFolder, addFileDates, tempDir, copyFiles, headerToCheckAgainst, maxDegreeOfParallelism, _logger); // If it was a success, write the DAT out diff --git a/SabreTools/SabreTools.cs b/SabreTools/SabreTools.cs index 19e6c093..847785a5 100644 --- a/SabreTools/SabreTools.cs +++ b/SabreTools/SabreTools.cs @@ -102,9 +102,6 @@ namespace SabreTools inplace = false, inverse = false, merge = false, - noMD5 = false, - noSHA1 = false, - noSHA256 = true, // TODO: This will eventually need to be inversed parseArchivesAsFiles = false, quickScan = false, quotes = false, @@ -122,10 +119,11 @@ namespace SabreTools usegame = true; DatFormat datFormat = 0x0; DiffMode diffMode = 0x0; + Hash omitFromScan = Hash.SHA256 & Hash.SHA384 & Hash.SHA512; // Should be set to 0x0 later + Hash stripHash = 0x0; OutputFormat outputFormat = OutputFormat.Folder; SplitType splitType = SplitType.None; StatDatFormat statDatFormat = 0x0; - Hash stripHash = 0x0; // User inputs int gz = 2, @@ -390,7 +388,7 @@ namespace SabreTools break; case "-nm": case "--noMD5": - noMD5 = true; + omitFromScan |= Hash.MD5; break; case "-nrun": case "--not-run": @@ -398,11 +396,19 @@ namespace SabreTools break; case "-ns": case "--noSHA1": - noSHA1 = true; + omitFromScan |= Hash.SHA1; break; case "-ns256": case "--noSHA256": - noSHA256 = false; + omitFromScan &= ~Hash.SHA256; // This needs to be inverted later + break; + case "-ns384": + case "--noSHA384": + omitFromScan &= ~Hash.SHA384; // This needs to be inverted later + break; + case "-ns512": + case "--noSHA512": + omitFromScan &= ~Hash.SHA512; // This needs to be inverted later break; case "-oa": case "--output-all": @@ -1123,9 +1129,7 @@ namespace SabreTools datFormat, romba, superdat, - noMD5, - noSHA1, - noSHA256, + omitFromScan, removeDateFromAutomaticName, parseArchivesAsFiles, enableGzip,