[DatFile] Add hashOnly check for verify

This commit is contained in:
Matt Nadareski
2017-01-26 18:03:07 -08:00
parent 5314ff39b5
commit 1def9c0226
5 changed files with 48 additions and 15 deletions

View File

@@ -379,6 +379,7 @@ namespace SabreTools.Helper.Data
helptext.Add(" -ve, --verify Verify a folder against DATs");
helptext.Add(" -dat= Input DAT to verify against");
helptext.Add(" -t=, --temp= Set the temporary directory to use");
helptext.Add(" -ho, --hash-only Check files by hash only");
helptext.Add(" -h=, --header= Set a header skipper to use, blank means all");
// Additional Notes

View File

@@ -1,12 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using SabreTools.Helper.Data;
using SabreTools.Helper.Skippers;
using SabreTools.Helper.Tools;
using SharpCompress.Common;
#if MONO
using System.IO;
@@ -468,13 +466,13 @@ namespace SabreTools.Helper.Dats
/// <summary>
/// Process the DAT and verify the output directory
/// </summary>
/// <param name="datFile">DAT to use to verify the directory</param>
/// <param name="inputs">List of input directories to compare against</param>
/// <param name="tempDir">Temporary directory for archive extraction</param>
/// <param name="hashOnly">True if only hashes should be checked, false for full file information</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 file and console output</param>
/// <returns>True if verification was a success, false otherwise</returns>
public bool VerifyDirectory(List<string> inputs, string tempDir, string headerToCheckAgainst, Logger logger)
public bool VerifyDirectory(List<string> inputs, string tempDir, bool hashOnly, string headerToCheckAgainst, Logger logger)
{
// First create or clean the temp directory
if (!Directory.Exists(tempDir))
@@ -509,8 +507,30 @@ namespace SabreTools.Helper.Dats
matched.Description = "fixDat_" + matched.Description;
matched.DatFormat = DatFormat.Logiqx;
// Now that all files are parsed, get only files found in directory
// If we are checking hashes only, essentially diff the inputs
bool found = false;
if (hashOnly)
{
// First we need to sort by hash to get duplicates
BucketBySHA1(true, logger, output: false);
// Then follow the same tactics as before
foreach (string key in Keys)
{
List<DatItem> roms = this[key];
foreach (Rom rom in roms)
{
if (rom.SourceID == 99)
{
found = true;
matched.Add(rom.Size + "-" + rom.CRC, rom);
}
}
}
}
// If we are checking full names, get only files found in directory
else
{
foreach (string key in Keys)
{
List<DatItem> roms = this[key];
@@ -524,6 +544,7 @@ namespace SabreTools.Helper.Dats
}
}
}
}
// Now output the fixdat to the main folder
if (found)

View File

@@ -901,6 +901,11 @@ Options:
(inside the running folder) is not preferred. This is used for any operations that
require an archive to be extracted.
-ho, --hash-only Check files by hash only
This sets a mode where files are not checked based on name but rather hash alone.
This allows verification of (possibly) incorrectly named folders and sets to be
verified without worrying about the proper set structure to be there.
-h=, --header= Remove headers from hash calculations
If this is set, then all files that have copier headers that are detected will
have them removed from the hash calculation. This will allow for a headered collection

View File

@@ -789,8 +789,9 @@ namespace SabreTools
/// <param name="datfiles">Names of the DATs to compare against</param>
/// <param name="inputs">Input directories to compare against</param>
/// <param name="tempDir">Temporary directory for archive extraction</param>
/// <param name="hashOnly">True if only hashes should be checked, false for full file information</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>
private static void InitVerify(List<string> datfiles, List<string> inputs, string tempDir, string headerToCheckAgainst)
private static void InitVerify(List<string> datfiles, List<string> inputs, string tempDir, bool hashOnly, string headerToCheckAgainst)
{
// Get the archive scanning level
ArchiveScanLevel asl = ArchiveTools.GetArchiveScanLevelFromNumbers(1, 1, 1, 1);
@@ -806,7 +807,7 @@ namespace SabreTools
}
_logger.User("Populating complete in " + DateTime.Now.Subtract(start).ToString(@"hh\:mm\:ss\.fffff"));
datdata.VerifyDirectory(inputs, tempDir, headerToCheckAgainst, _logger);
datdata.VerifyDirectory(inputs, tempDir, hashOnly, headerToCheckAgainst, _logger);
}
#endregion

View File

@@ -78,6 +78,7 @@ namespace SabreTools
delete = false, // SimpleSort
enableGzip = false,
excludeOf = false,
hashOnly = false,
inplace = false,
inverse = false, // SimpleSort
merge = false,
@@ -306,6 +307,10 @@ namespace SabreTools
case "--gz-files":
enableGzip = true;
break;
case "-ho":
case "--hash-only":
hashOnly = true;
break;
case "-html":
case "--html":
statDatFormat |= StatDatFormat.HTML;
@@ -1104,7 +1109,7 @@ namespace SabreTools
// If we're using the verifier
else if (verify)
{
InitVerify(datfiles, inputs, tempDir, header);
InitVerify(datfiles, inputs, tempDir, hashOnly, header);
}
// If nothing is set, show the help