mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[ALL] Convert "noHASH" flags to using Hash type
This commit is contained in:
@@ -26,9 +26,7 @@ namespace SabreTools.Helper.Dats
|
||||
/// Create a new Dat from a directory
|
||||
/// </summary>
|
||||
/// <param name="basePath">Base folder to be used in creating the DAT</param>
|
||||
/// <param name="noMD5">True if MD5 hashes should be skipped over, false otherwise</param>
|
||||
/// <param name="noSHA1">True if SHA-1 hashes should be skipped over, false otherwise</param>
|
||||
/// <param name="noSHA256">True if SHA-256 hashes should be skipped over, false otherwise</param>
|
||||
/// <param name="omitFromScan">Hash flag saying what hashes should not be calculated</param>
|
||||
/// <param name="bare">True if the date should be omitted from the DAT, false otherwise</param>
|
||||
/// <param name="archivesAsFiles">True if archives should be treated as files, false otherwise</param>
|
||||
/// <param name="enableGzip">True if GZIP archives should be treated as files, false otherwise</param>
|
||||
@@ -40,7 +38,7 @@ namespace SabreTools.Helper.Dats
|
||||
/// <param name="headerToCheckAgainst">Populated string representing the name of the skipper to use, a blank string to use the first available checker, null otherwise</param>
|
||||
/// <param name="maxDegreeOfParallelism">Integer representing the maximum amount of parallelization to be used</param>
|
||||
/// <param name="logger">Logger object for console and file output</param>
|
||||
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
|
||||
/// </summary>
|
||||
/// <param name="item">Filename of the item to be checked</param>
|
||||
/// <param name="basePath">Base folder to be used in creating the DAT</param>
|
||||
/// <param name="noMD5">True if MD5 hashes should be skipped over, false otherwise</param>
|
||||
/// <param name="noSHA1">True if SHA-1 hashes should be skipped over, false otherwise</param>
|
||||
/// <param name="noSHA256">True if SHA-256 hashes should be skipped over, false otherwise</param>
|
||||
/// <param name="omitFromScan">Hash flag saying what hashes should not be calculated</param>
|
||||
/// <param name="bare">True if the date should be omitted from the DAT, false otherwise</param>
|
||||
/// <param name="archivesAsFiles">True if archives should be treated as files, false otherwise</param>
|
||||
/// <param name="enableGzip">True if GZIP archives should be treated as files, false otherwise</param>
|
||||
@@ -190,7 +186,7 @@ namespace SabreTools.Helper.Dats
|
||||
/// <param name="headerToCheckAgainst">Populated string representing the name of the skipper to use, a blank string to use the first available checker, null otherwise</param>
|
||||
/// <param name="maxDegreeOfParallelism">Integer representing the maximum amount of parallelization to be used</param>
|
||||
/// <param name="logger">Logger object for console and file output</param>
|
||||
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
|
||||
/// <param name="item">File to be added</param>
|
||||
/// <param name="parent">Parent game to be used</param>
|
||||
/// <param name="basePath">Path the represents the parent directory</param>
|
||||
/// <param name="noMD5">True if MD5 hashes should be skipped over, false otherwise</param>
|
||||
/// <param name="noSHA1">True if SHA-1 hashes should be skipped over, false otherwise</param>
|
||||
/// <param name="noSHA256">True if SHA-256 hashes should be skipped over, false otherwise</param>
|
||||
/// <param name="omitFromScan">Hash flag saying what hashes should not be calculated</param>
|
||||
/// <param name="addDate">True if dates should be archived for all files, false otherwise</param>
|
||||
/// <param name="headerToCheckAgainst">Populated string representing the name of the skipper to use, a blank string to use the first available checker, null otherwise</param>
|
||||
/// <param name="logger">Logger object for console and file output</param>
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -188,15 +188,13 @@ namespace SabreTools.Helper.Tools
|
||||
/// </summary>
|
||||
/// <param name="input">Filename to get information from</param>
|
||||
/// <param name="logger">Logger object for console and file output</param>
|
||||
/// <param name="noMD5">True if MD5 hashes should not be calculated, false otherwise (default)</param>
|
||||
/// <param name="noSHA1">True if SHA-1 hashes should not be calcluated, false otherwise (default)</param>
|
||||
/// <param name="noSHA256">True if SHA-256 hashes should not be calcluated, false otherwise (default)</param>
|
||||
/// <param name="omitFromScan">Hash flag saying what hashes should not be calculated (defaults to none)</param>
|
||||
/// <param name="offset">Set a >0 number for getting hash for part of the file, 0 otherwise (default)</param>
|
||||
/// <param name="date">True if the file Date should be included, false otherwise (default)</param>
|
||||
/// <param name="header">Populated string representing the name of the skipper to use, a blank string to use the first available checker, null otherwise</param>
|
||||
/// <returns>Populated RomData object if success, empty one on error</returns>
|
||||
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
|
||||
/// </summary>
|
||||
/// <param name="input">Filename to get information from</param>
|
||||
/// <param name="size">Size of the input stream</param>
|
||||
/// <param name="noMD5">True if MD5 hashes should not be calculated, false otherwise (default)</param>
|
||||
/// <param name="noSHA1">True if SHA-1 hashes should not be calcluated, false otherwise (default)</param>
|
||||
/// <param name="noSHA256">True if SHA-256 hashes should not be calcluated, false otherwise (default)</param>
|
||||
/// <param name="omitFromScan">Hash flag saying what hashes should not be calculated (defaults to none)</param>
|
||||
/// <param name="offset">Set a >0 number for getting hash for part of the file, 0 otherwise (default)</param>
|
||||
/// <param name="keepReadOpen">True if the underlying read stream should be kept open, false otherwise</param>
|
||||
/// <returns>Populated RomData object if success, empty one on error</returns>
|
||||
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();
|
||||
|
||||
@@ -35,9 +35,7 @@ namespace SabreTools
|
||||
/// <param name="datFormat">DatFormat to be used for outputting the DAT</param>
|
||||
/// <param name="romba">True to enable reading a directory like a Romba depot, false otherwise</param>
|
||||
/// <param name="superdat">True to enable SuperDAT-style reading, false otherwise</param>
|
||||
/// <param name="noMD5">True to disable getting MD5 hash, false otherwise</param>
|
||||
/// <param name="noSHA1">True to disable getting SHA-1 hash, false otherwise</param>
|
||||
/// <param name="noSHA256">True to disable getting SHA-256 hash, false otherwise</param>
|
||||
/// <param name="omitFromScan">Hash flag saying what hashes should not be calculated</param>
|
||||
/// <param name="removeDateFromAutomaticName">True if the date should be omitted from the DAT, false otherwise</param>
|
||||
/// <param name="parseArchivesAsFiles">True if archives should be treated as files, false otherwise</param>
|
||||
/// <param name="enableGzip">True if GZIP archives should be treated as files, false otherwise</param>
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user