[SabreTools, DatFile, README.1ST] bool ignorechd

This commit is contained in:
Matt Nadareski
2017-10-31 03:04:54 -07:00
parent b1bc6eb062
commit b200f148b8
5 changed files with 67 additions and 22 deletions

View File

@@ -3453,8 +3453,10 @@ namespace SabreTools.Library.DatFiles
/// <param name="outDir">Output directory to </param>
/// <param name="copyFiles">True if files should be copied to the temp directory before hashing, 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="ignorechd">True if CHDs should be treated like regular files, false otherwise</param>
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
/// <param name="tempDir">Name of the directory to create a temp folder in (blank is current directory)</param>
/// <param name="copyFiles">True if files should be copied to the temp directory before hashing, 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="ignorechd">True if CHDs should be treated like regular files, false otherwise</param>
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
/// <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="ignorechd">True if CHDs should be treated like regular files, false otherwise</param>
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
/// <param name="hashOnly">True if only hashes should be checked, false for full file information</param>
/// <param name="quickScan">True to enable external scanning of archives, 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="ignorechd">True if CHDs should be treated like regular files, false otherwise</param>
/// <returns>True if verification was a success, false otherwise</returns>
public bool VerifyGeneric(List<string> inputs, string tempDir, bool hashOnly, bool quickScan, string headerToCheckAgainst)
public bool VerifyGeneric(List<string> 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

View File

@@ -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

View File

@@ -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<string>() { "-ic", "--ignore-chd" },
"Treat CHDs as regular files",
FeatureType.Flag,
null));
datFromDir.AddFeature("temp", new Feature(
new List<string>() { "-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<string>() { "-ic", "--ignore-chd" },
"Treat CHDs as regular files",
FeatureType.Flag,
null));
sort.AddFeature("add-date", new Feature(
new List<string>() { "-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<string>() { "-ic", "--ignore-chd" },
"Treat CHDs as regular files",
FeatureType.Flag,
null));
verify.AddFeature("dat-merged", new Feature(
new List<string>() { "-dm", "--dat-merged" },
"Force checking merged sets",

View File

@@ -53,6 +53,7 @@ namespace SabreTools
/// <param name="outDir">Name of the directory to output the DAT to (blank is the current directory)</param>
/// <param name="copyFiles">True if files should be copied to the temp directory before hashing, 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="ignorechd">True if CHDs should be treated like regular files, false otherwise</param>
private static void InitDatFromDir(List<string> 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
/// <param name="updateDat">True if the updated DAT should be output, 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="splitType">Type of the split that should be performed (split, merged, fully merged)</param>
/// <param name="ignorechd">True if CHDs should be treated like regular files, false otherwise</param>
private static void InitSort(List<string> datfiles, List<string> 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);
}
/// <summary>
@@ -745,8 +748,9 @@ namespace SabreTools
/// <param name="quickScan">True to enable external scanning of archives, 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="splitType">Type of the split that should be performed (split, merged, fully merged)</param>
/// <param name="ignorechd">True if CHDs should be treated like regular files, false otherwise</param>
private static void InitVerify(List<string> datfiles, List<string> 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);
}
/// <summary>

View File

@@ -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