mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[ALL] Add remove hash flags and implement
This commit is contained in:
@@ -186,23 +186,6 @@ namespace SabreTools.Helper.Data
|
||||
|
||||
#region DatFile related
|
||||
|
||||
/// <summary>
|
||||
/// Determines which diffs should be created
|
||||
/// </summary>
|
||||
[Flags]
|
||||
public enum DiffMode
|
||||
{
|
||||
// Standard diffs
|
||||
Dupes = 0x01,
|
||||
NoDupes = 0x02,
|
||||
Individuals = 0x04,
|
||||
All = Dupes | NoDupes | Individuals,
|
||||
|
||||
// Cascaded diffs
|
||||
Cascade = 0x08,
|
||||
ReverseCascade = 0x10,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines the DAT output format
|
||||
/// </summary>
|
||||
@@ -228,6 +211,23 @@ namespace SabreTools.Helper.Data
|
||||
ALL = 0xFFFF,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines which diffs should be created
|
||||
/// </summary>
|
||||
[Flags]
|
||||
public enum DiffMode
|
||||
{
|
||||
// Standard diffs
|
||||
Dupes = 0x01,
|
||||
NoDupes = 0x02,
|
||||
Individuals = 0x04,
|
||||
All = Dupes | NoDupes | Individuals,
|
||||
|
||||
// Cascaded diffs
|
||||
Cascade = 0x08,
|
||||
ReverseCascade = 0x10,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determine which format to output Stats to
|
||||
/// </summary>
|
||||
@@ -240,6 +240,17 @@ namespace SabreTools.Helper.Data
|
||||
TSV = 0x08,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determine what hashes to strip from the DAT
|
||||
/// </summary>
|
||||
[Flags]
|
||||
public enum StripHash
|
||||
{
|
||||
MD5 = 0x01,
|
||||
SHA1 = 0x02,
|
||||
SHA256 = 0x04,
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region DatItem related
|
||||
|
||||
@@ -30,6 +30,7 @@ namespace SabreTools.Helper.Dats
|
||||
private DatFormat _datFormat;
|
||||
private bool _excludeOf;
|
||||
private bool _mergeRoms;
|
||||
private StripHash _stripHash;
|
||||
private SortedDictionary<string, List<DatItem>> _files = new SortedDictionary<string, List<DatItem>>();
|
||||
private SortedBy _sortedBy;
|
||||
|
||||
@@ -160,6 +161,11 @@ namespace SabreTools.Helper.Dats
|
||||
get { return _mergeRoms; }
|
||||
set { _mergeRoms = value; }
|
||||
}
|
||||
public StripHash StripHash
|
||||
{
|
||||
get { return _stripHash; }
|
||||
set { _stripHash = value; }
|
||||
}
|
||||
public SortedBy SortedBy
|
||||
{
|
||||
get { return _sortedBy; }
|
||||
@@ -540,6 +546,7 @@ namespace SabreTools.Helper.Dats
|
||||
_excludeOf = datFile.ExcludeOf;
|
||||
_datFormat = datFile.DatFormat;
|
||||
_mergeRoms = datFile.MergeRoms;
|
||||
_stripHash = datFile.StripHash;
|
||||
_sortedBy = SortedBy.Default;
|
||||
_useGame = datFile.UseGame;
|
||||
_prefix = datFile.Prefix;
|
||||
|
||||
@@ -434,6 +434,88 @@ namespace SabreTools.Helper.Dats
|
||||
WriteToFile(outDir, logger);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Strip the given hash types from the DAT
|
||||
/// </summary>
|
||||
/// <param name="logger">Logging object for console and file output</param>
|
||||
private void StripHashesFromItems(Logger logger)
|
||||
{
|
||||
// Output the logging statement
|
||||
string set = "";
|
||||
switch ((int)StripHash)
|
||||
{
|
||||
case 0x01:
|
||||
set = "MD5";
|
||||
break;
|
||||
case 0x02:
|
||||
set = "SHA-1";
|
||||
break;
|
||||
case 0x03:
|
||||
set = "MD5 and SHA-1";
|
||||
break;
|
||||
case 0x04:
|
||||
set = "SHA-256";
|
||||
break;
|
||||
case 0x05:
|
||||
set = "MD5 and SHA-256";
|
||||
break;
|
||||
case 0x06:
|
||||
set = "SHA-1 and SHA-256";
|
||||
break;
|
||||
case 0x07:
|
||||
set = "MD5, SHA-1, and SHA-256";
|
||||
break;
|
||||
}
|
||||
logger.User("Stripping " + set + " hashes");
|
||||
|
||||
// Now process all of the roms
|
||||
List<string> keys = Keys.ToList();
|
||||
for (int i = 0; i < keys.Count; i++)
|
||||
{
|
||||
List<DatItem> items = this[keys[i]];
|
||||
for (int j = 0; j < items.Count; j++)
|
||||
{
|
||||
DatItem item = items[j];
|
||||
if (item.Type == ItemType.Rom)
|
||||
{
|
||||
Rom rom = (Rom)item;
|
||||
if ((StripHash & StripHash.MD5) != 0)
|
||||
{
|
||||
rom.MD5 = null;
|
||||
}
|
||||
if ((StripHash & StripHash.SHA1) != 0)
|
||||
{
|
||||
rom.SHA1 = null;
|
||||
}
|
||||
if ((StripHash & StripHash.SHA256) != 0)
|
||||
{
|
||||
rom.SHA256 = null;
|
||||
}
|
||||
items[j] = rom;
|
||||
}
|
||||
else if (item.Type == ItemType.Disk)
|
||||
{
|
||||
Disk disk = (Disk)item;
|
||||
if ((StripHash & StripHash.MD5) != 0)
|
||||
{
|
||||
disk.MD5 = null;
|
||||
}
|
||||
if ((StripHash & StripHash.SHA1) != 0)
|
||||
{
|
||||
disk.SHA1 = null;
|
||||
}
|
||||
if ((StripHash & StripHash.SHA256) != 0)
|
||||
{
|
||||
disk.SHA256 = null;
|
||||
}
|
||||
items[j] = disk;
|
||||
}
|
||||
}
|
||||
|
||||
this[keys[i]] = items;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert, update, and filter a DAT file or set of files using a base
|
||||
/// </summary>
|
||||
|
||||
@@ -111,6 +111,12 @@ namespace SabreTools.Helper.Dats
|
||||
// Bucket roms by game name and optionally dedupe
|
||||
BucketByGame(MergeRoms, norename, logger);
|
||||
|
||||
// If we are removing hashes, do that now
|
||||
if (_stripHash != 0x0)
|
||||
{
|
||||
StripHashesFromItems(logger);
|
||||
}
|
||||
|
||||
// Get the outfile names
|
||||
Dictionary<DatFormat, string> outfiles = Style.CreateOutfileNames(outDir, this, overwrite);
|
||||
|
||||
|
||||
@@ -878,6 +878,18 @@ Options:
|
||||
Game names will be santitized to remove what the original WoD standards
|
||||
deemed as unneeded information, such as parenthized or bracketed strings
|
||||
|
||||
-rmd5, --rem-md5 Remove MD5 hashes from the output
|
||||
By default, all available hashes will be written out to the DAT. This will
|
||||
remove all MD5 hashes from the output file(s).
|
||||
|
||||
-rsha1, --rem-sha1 Remove SHA-1 hashes from the output
|
||||
By default, all available hashes will be written out to the DAT. This will
|
||||
remove all SHA-1 hashes from the output file(s).
|
||||
|
||||
-rsha256, --rem-sha256 Remove SHA-256 hashes from the output
|
||||
By default, all available hashes will be written out to the DAT. This will
|
||||
remove all SHA-256 hashes from the output file(s).
|
||||
|
||||
-dan, --desc-name Use Software List name instead of description
|
||||
By default, all DATs are converted exactly as they are input. Enabling this flag
|
||||
allows for the machine names in the DAT to be replaced by the machine description
|
||||
|
||||
@@ -966,6 +966,21 @@ namespace SabreTools
|
||||
"Clean game names according to WoD standards",
|
||||
FeatureType.Flag,
|
||||
null));
|
||||
update.AddFeature("rem-md5", new Feature(
|
||||
new List<string>() { "-rmd5", "--rem-md5" },
|
||||
"Remove MD5 hashes from the output",
|
||||
FeatureType.Flag,
|
||||
null));
|
||||
update.AddFeature("rem-sha1", new Feature(
|
||||
new List<string>() { "-rsha1", "--rem-sha1" },
|
||||
"Remove SHA-1 hashes from the output",
|
||||
FeatureType.Flag,
|
||||
null));
|
||||
update.AddFeature("rem-sha256", new Feature(
|
||||
new List<string>() { "-rsha256", "--rem-sha256" },
|
||||
"Remove SHA-256 hashes from the output",
|
||||
FeatureType.Flag,
|
||||
null));
|
||||
update.AddFeature("desc-name", new Feature(
|
||||
new List<string>() { "-dan", "--desc-name" },
|
||||
"Use description instead of machine name",
|
||||
|
||||
@@ -473,6 +473,7 @@ namespace SabreTools
|
||||
/// <param name="clean">True to clean the game names to WoD standard, false otherwise (default)</param>
|
||||
/// <param name="descAsName">True if descriptions should be used as names, false otherwise (default)</param>
|
||||
/// <param name="dedup">True to dedupe the roms in the DAT, false otherwise (default)</param>
|
||||
/// <param name="stripHash">StripHash that represents the hash(es) that you want to remove from the output</param>
|
||||
/// /* Multithreading info */
|
||||
/// <param name="maxDegreeOfParallelism">Integer representing the maximum amount of parallelization to be used</param>
|
||||
private static void InitUpdate(List<string> inputs,
|
||||
@@ -529,6 +530,7 @@ namespace SabreTools
|
||||
bool clean,
|
||||
bool descAsName,
|
||||
bool dedup,
|
||||
StripHash stripHash,
|
||||
|
||||
/* Multithreading info */
|
||||
int maxDegreeOfParallelism)
|
||||
@@ -654,6 +656,7 @@ namespace SabreTools
|
||||
MergeRoms = dedup,
|
||||
ExcludeOf = excludeOf,
|
||||
DatFormat = datFormat,
|
||||
StripHash = stripHash,
|
||||
|
||||
UseGame = usegame,
|
||||
Prefix = prefix,
|
||||
|
||||
@@ -125,6 +125,7 @@ namespace SabreTools
|
||||
OutputFormat outputFormat = OutputFormat.Folder;
|
||||
SplitType splitType = SplitType.None;
|
||||
StatDatFormat statDatFormat = 0x0;
|
||||
StripHash stripHash = 0x0;
|
||||
|
||||
// User inputs
|
||||
int gz = 2,
|
||||
@@ -487,6 +488,10 @@ namespace SabreTools
|
||||
case "--rev-cascade":
|
||||
diffMode |= DiffMode.ReverseCascade;
|
||||
break;
|
||||
case "-rmd5":
|
||||
case "--rem-md5":
|
||||
stripHash |= StripHash.MD5;
|
||||
break;
|
||||
case "-rme":
|
||||
case "--rem-ext":
|
||||
remext = true;
|
||||
@@ -495,6 +500,14 @@ namespace SabreTools
|
||||
case "--romba":
|
||||
romba = true;
|
||||
break;
|
||||
case "-rsha1":
|
||||
case "--rem-sha1":
|
||||
stripHash |= StripHash.SHA1;
|
||||
break;
|
||||
case "-rsha256":
|
||||
case "--rem-sha256":
|
||||
stripHash |= StripHash.SHA256;
|
||||
break;
|
||||
case "-run":
|
||||
case "--runnable":
|
||||
filter.Runnable = true;
|
||||
@@ -1187,7 +1200,7 @@ namespace SabreTools
|
||||
InitUpdate(inputs, filename, name, description, rootdir, category, version, date, author, email, homepage, url, comment, header,
|
||||
superdat, forcemerge, forcend, forcepack, excludeOf, datFormat, usegame, prefix,
|
||||
postfix, quotes, repext, addext, remext, datPrefix, romba, merge, diffMode, inplace, skip, removeDateFromAutomaticName,
|
||||
filter, splitType, trim, single, root, outDir, cleanGameNames, descAsName, dedup, maxParallelism);
|
||||
filter, splitType, trim, single, root, outDir, cleanGameNames, descAsName, dedup, stripHash, maxParallelism);
|
||||
}
|
||||
|
||||
// If we're using the verifier
|
||||
|
||||
Reference in New Issue
Block a user