mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[DatFile] Add hashOnly check for verify
This commit is contained in:
@@ -379,6 +379,7 @@ namespace SabreTools.Helper.Data
|
|||||||
helptext.Add(" -ve, --verify Verify a folder against DATs");
|
helptext.Add(" -ve, --verify Verify a folder against DATs");
|
||||||
helptext.Add(" -dat= Input DAT to verify against");
|
helptext.Add(" -dat= Input DAT to verify against");
|
||||||
helptext.Add(" -t=, --temp= Set the temporary directory to use");
|
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");
|
helptext.Add(" -h=, --header= Set a header skipper to use, blank means all");
|
||||||
|
|
||||||
// Additional Notes
|
// Additional Notes
|
||||||
|
|||||||
@@ -1,12 +1,10 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
using SabreTools.Helper.Data;
|
using SabreTools.Helper.Data;
|
||||||
using SabreTools.Helper.Skippers;
|
using SabreTools.Helper.Skippers;
|
||||||
using SabreTools.Helper.Tools;
|
using SabreTools.Helper.Tools;
|
||||||
using SharpCompress.Common;
|
|
||||||
|
|
||||||
#if MONO
|
#if MONO
|
||||||
using System.IO;
|
using System.IO;
|
||||||
@@ -468,13 +466,13 @@ namespace SabreTools.Helper.Dats
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Process the DAT and verify the output directory
|
/// Process the DAT and verify the output directory
|
||||||
/// </summary>
|
/// </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="inputs">List of input directories to compare against</param>
|
||||||
/// <param name="tempDir">Temporary directory for archive extraction</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="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>
|
/// <param name="logger">Logger object for file and console output</param>
|
||||||
/// <returns>True if verification was a success, false otherwise</returns>
|
/// <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
|
// First create or clean the temp directory
|
||||||
if (!Directory.Exists(tempDir))
|
if (!Directory.Exists(tempDir))
|
||||||
@@ -509,18 +507,41 @@ namespace SabreTools.Helper.Dats
|
|||||||
matched.Description = "fixDat_" + matched.Description;
|
matched.Description = "fixDat_" + matched.Description;
|
||||||
matched.DatFormat = DatFormat.Logiqx;
|
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;
|
bool found = false;
|
||||||
foreach (string key in Keys)
|
if (hashOnly)
|
||||||
{
|
{
|
||||||
List<DatItem> roms = this[key];
|
// First we need to sort by hash to get duplicates
|
||||||
List<DatItem> newroms = DatItem.Merge(roms, logger);
|
BucketBySHA1(true, logger, output: false);
|
||||||
foreach (Rom rom in newroms)
|
|
||||||
|
// Then follow the same tactics as before
|
||||||
|
foreach (string key in Keys)
|
||||||
{
|
{
|
||||||
if (rom.SourceID == 99)
|
List<DatItem> roms = this[key];
|
||||||
|
foreach (Rom rom in roms)
|
||||||
{
|
{
|
||||||
found = true;
|
if (rom.SourceID == 99)
|
||||||
matched.Add(rom.Size + "-" + rom.CRC, rom);
|
{
|
||||||
|
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];
|
||||||
|
List<DatItem> newroms = DatItem.Merge(roms, logger);
|
||||||
|
foreach (Rom rom in newroms)
|
||||||
|
{
|
||||||
|
if (rom.SourceID == 99)
|
||||||
|
{
|
||||||
|
found = true;
|
||||||
|
matched.Add(rom.Size + "-" + rom.CRC, rom);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -901,6 +901,11 @@ Options:
|
|||||||
(inside the running folder) is not preferred. This is used for any operations that
|
(inside the running folder) is not preferred. This is used for any operations that
|
||||||
require an archive to be extracted.
|
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
|
-h=, --header= Remove headers from hash calculations
|
||||||
If this is set, then all files that have copier headers that are detected will
|
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
|
have them removed from the hash calculation. This will allow for a headered collection
|
||||||
|
|||||||
@@ -789,8 +789,9 @@ namespace SabreTools
|
|||||||
/// <param name="datfiles">Names of the DATs to compare against</param>
|
/// <param name="datfiles">Names of the DATs to compare against</param>
|
||||||
/// <param name="inputs">Input directories to compare against</param>
|
/// <param name="inputs">Input directories to compare against</param>
|
||||||
/// <param name="tempDir">Temporary directory for archive extraction</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="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
|
// Get the archive scanning level
|
||||||
ArchiveScanLevel asl = ArchiveTools.GetArchiveScanLevelFromNumbers(1, 1, 1, 1);
|
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"));
|
_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
|
#endregion
|
||||||
|
|||||||
@@ -78,6 +78,7 @@ namespace SabreTools
|
|||||||
delete = false, // SimpleSort
|
delete = false, // SimpleSort
|
||||||
enableGzip = false,
|
enableGzip = false,
|
||||||
excludeOf = false,
|
excludeOf = false,
|
||||||
|
hashOnly = false,
|
||||||
inplace = false,
|
inplace = false,
|
||||||
inverse = false, // SimpleSort
|
inverse = false, // SimpleSort
|
||||||
merge = false,
|
merge = false,
|
||||||
@@ -306,6 +307,10 @@ namespace SabreTools
|
|||||||
case "--gz-files":
|
case "--gz-files":
|
||||||
enableGzip = true;
|
enableGzip = true;
|
||||||
break;
|
break;
|
||||||
|
case "-ho":
|
||||||
|
case "--hash-only":
|
||||||
|
hashOnly = true;
|
||||||
|
break;
|
||||||
case "-html":
|
case "-html":
|
||||||
case "--html":
|
case "--html":
|
||||||
statDatFormat |= StatDatFormat.HTML;
|
statDatFormat |= StatDatFormat.HTML;
|
||||||
@@ -1104,7 +1109,7 @@ namespace SabreTools
|
|||||||
// If we're using the verifier
|
// If we're using the verifier
|
||||||
else if (verify)
|
else if (verify)
|
||||||
{
|
{
|
||||||
InitVerify(datfiles, inputs, tempDir, header);
|
InitVerify(datfiles, inputs, tempDir, hashOnly, header);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If nothing is set, show the help
|
// If nothing is set, show the help
|
||||||
|
|||||||
Reference in New Issue
Block a user