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:
@@ -182,14 +182,39 @@ namespace SabreTools.Helper.Data
|
|||||||
ExtraData = 0x2
|
ExtraData = 0x2
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region DatFile related
|
#region DatFile related
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Determines which diffs should be created
|
/// Determines the DAT output format
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Flags]
|
[Flags]
|
||||||
|
public enum DatFormat
|
||||||
|
{
|
||||||
|
Logiqx = 0x0001,
|
||||||
|
ClrMamePro = 0x0002,
|
||||||
|
RomCenter = 0x0004,
|
||||||
|
DOSCenter = 0x0008,
|
||||||
|
MissFile = 0x0010,
|
||||||
|
SabreDat = 0x0020,
|
||||||
|
RedumpMD5 = 0x0040,
|
||||||
|
RedumpSHA1 = 0x0080,
|
||||||
|
RedumpSFV = 0x0100,
|
||||||
|
SoftwareList = 0x0200,
|
||||||
|
OfflineList = 0x0400,
|
||||||
|
TSV = 0x0800,
|
||||||
|
CSV = 0x1000,
|
||||||
|
AttractMode = 0x2000,
|
||||||
|
RedumpSHA256 = 0x4000,
|
||||||
|
|
||||||
|
ALL = 0xFFFF,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Determines which diffs should be created
|
||||||
|
/// </summary>
|
||||||
|
[Flags]
|
||||||
public enum DiffMode
|
public enum DiffMode
|
||||||
{
|
{
|
||||||
// Standard diffs
|
// Standard diffs
|
||||||
@@ -203,31 +228,6 @@ namespace SabreTools.Helper.Data
|
|||||||
ReverseCascade = 0x10,
|
ReverseCascade = 0x10,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Determines the DAT output format
|
|
||||||
/// </summary>
|
|
||||||
[Flags]
|
|
||||||
public enum DatFormat
|
|
||||||
{
|
|
||||||
Logiqx = 0x0001,
|
|
||||||
ClrMamePro = 0x0002,
|
|
||||||
RomCenter = 0x0004,
|
|
||||||
DOSCenter = 0x0008,
|
|
||||||
MissFile = 0x0010,
|
|
||||||
SabreDat = 0x0020,
|
|
||||||
RedumpMD5 = 0x0040,
|
|
||||||
RedumpSHA1 = 0x0080,
|
|
||||||
RedumpSFV = 0x0100,
|
|
||||||
SoftwareList = 0x0200,
|
|
||||||
OfflineList = 0x0400,
|
|
||||||
TSV = 0x0800,
|
|
||||||
CSV = 0x1000,
|
|
||||||
AttractMode = 0x2000,
|
|
||||||
RedumpSHA256 = 0x4000,
|
|
||||||
|
|
||||||
ALL = 0xFFFF,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Determine which format to output Stats to
|
/// Determine which format to output Stats to
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -240,14 +240,25 @@ namespace SabreTools.Helper.Data
|
|||||||
TSV = 0x08,
|
TSV = 0x08,
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
/// <summary>
|
||||||
|
/// Determine what hashes to strip from the DAT
|
||||||
|
/// </summary>
|
||||||
|
[Flags]
|
||||||
|
public enum StripHash
|
||||||
|
{
|
||||||
|
MD5 = 0x01,
|
||||||
|
SHA1 = 0x02,
|
||||||
|
SHA256 = 0x04,
|
||||||
|
}
|
||||||
|
|
||||||
#region DatItem related
|
#endregion
|
||||||
|
|
||||||
/// <summary>
|
#region DatItem related
|
||||||
/// Determines which type of duplicate a file is
|
|
||||||
/// </summary>
|
/// <summary>
|
||||||
[Flags]
|
/// Determines which type of duplicate a file is
|
||||||
|
/// </summary>
|
||||||
|
[Flags]
|
||||||
public enum DupeType
|
public enum DupeType
|
||||||
{
|
{
|
||||||
// Type of match
|
// Type of match
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ namespace SabreTools.Helper.Dats
|
|||||||
private DatFormat _datFormat;
|
private DatFormat _datFormat;
|
||||||
private bool _excludeOf;
|
private bool _excludeOf;
|
||||||
private bool _mergeRoms;
|
private bool _mergeRoms;
|
||||||
|
private StripHash _stripHash;
|
||||||
private SortedDictionary<string, List<DatItem>> _files = new SortedDictionary<string, List<DatItem>>();
|
private SortedDictionary<string, List<DatItem>> _files = new SortedDictionary<string, List<DatItem>>();
|
||||||
private SortedBy _sortedBy;
|
private SortedBy _sortedBy;
|
||||||
|
|
||||||
@@ -160,6 +161,11 @@ namespace SabreTools.Helper.Dats
|
|||||||
get { return _mergeRoms; }
|
get { return _mergeRoms; }
|
||||||
set { _mergeRoms = value; }
|
set { _mergeRoms = value; }
|
||||||
}
|
}
|
||||||
|
public StripHash StripHash
|
||||||
|
{
|
||||||
|
get { return _stripHash; }
|
||||||
|
set { _stripHash = value; }
|
||||||
|
}
|
||||||
public SortedBy SortedBy
|
public SortedBy SortedBy
|
||||||
{
|
{
|
||||||
get { return _sortedBy; }
|
get { return _sortedBy; }
|
||||||
@@ -540,6 +546,7 @@ namespace SabreTools.Helper.Dats
|
|||||||
_excludeOf = datFile.ExcludeOf;
|
_excludeOf = datFile.ExcludeOf;
|
||||||
_datFormat = datFile.DatFormat;
|
_datFormat = datFile.DatFormat;
|
||||||
_mergeRoms = datFile.MergeRoms;
|
_mergeRoms = datFile.MergeRoms;
|
||||||
|
_stripHash = datFile.StripHash;
|
||||||
_sortedBy = SortedBy.Default;
|
_sortedBy = SortedBy.Default;
|
||||||
_useGame = datFile.UseGame;
|
_useGame = datFile.UseGame;
|
||||||
_prefix = datFile.Prefix;
|
_prefix = datFile.Prefix;
|
||||||
|
|||||||
@@ -434,6 +434,88 @@ namespace SabreTools.Helper.Dats
|
|||||||
WriteToFile(outDir, logger);
|
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>
|
/// <summary>
|
||||||
/// Convert, update, and filter a DAT file or set of files using a base
|
/// Convert, update, and filter a DAT file or set of files using a base
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -111,6 +111,12 @@ namespace SabreTools.Helper.Dats
|
|||||||
// Bucket roms by game name and optionally dedupe
|
// Bucket roms by game name and optionally dedupe
|
||||||
BucketByGame(MergeRoms, norename, logger);
|
BucketByGame(MergeRoms, norename, logger);
|
||||||
|
|
||||||
|
// If we are removing hashes, do that now
|
||||||
|
if (_stripHash != 0x0)
|
||||||
|
{
|
||||||
|
StripHashesFromItems(logger);
|
||||||
|
}
|
||||||
|
|
||||||
// Get the outfile names
|
// Get the outfile names
|
||||||
Dictionary<DatFormat, string> outfiles = Style.CreateOutfileNames(outDir, this, overwrite);
|
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
|
Game names will be santitized to remove what the original WoD standards
|
||||||
deemed as unneeded information, such as parenthized or bracketed strings
|
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
|
-dan, --desc-name Use Software List name instead of description
|
||||||
By default, all DATs are converted exactly as they are input. Enabling this flag
|
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
|
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",
|
"Clean game names according to WoD standards",
|
||||||
FeatureType.Flag,
|
FeatureType.Flag,
|
||||||
null));
|
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(
|
update.AddFeature("desc-name", new Feature(
|
||||||
new List<string>() { "-dan", "--desc-name" },
|
new List<string>() { "-dan", "--desc-name" },
|
||||||
"Use description instead of machine 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="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="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="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 */
|
/// /* Multithreading info */
|
||||||
/// <param name="maxDegreeOfParallelism">Integer representing the maximum amount of parallelization to be used</param>
|
/// <param name="maxDegreeOfParallelism">Integer representing the maximum amount of parallelization to be used</param>
|
||||||
private static void InitUpdate(List<string> inputs,
|
private static void InitUpdate(List<string> inputs,
|
||||||
@@ -529,6 +530,7 @@ namespace SabreTools
|
|||||||
bool clean,
|
bool clean,
|
||||||
bool descAsName,
|
bool descAsName,
|
||||||
bool dedup,
|
bool dedup,
|
||||||
|
StripHash stripHash,
|
||||||
|
|
||||||
/* Multithreading info */
|
/* Multithreading info */
|
||||||
int maxDegreeOfParallelism)
|
int maxDegreeOfParallelism)
|
||||||
@@ -654,6 +656,7 @@ namespace SabreTools
|
|||||||
MergeRoms = dedup,
|
MergeRoms = dedup,
|
||||||
ExcludeOf = excludeOf,
|
ExcludeOf = excludeOf,
|
||||||
DatFormat = datFormat,
|
DatFormat = datFormat,
|
||||||
|
StripHash = stripHash,
|
||||||
|
|
||||||
UseGame = usegame,
|
UseGame = usegame,
|
||||||
Prefix = prefix,
|
Prefix = prefix,
|
||||||
|
|||||||
@@ -125,6 +125,7 @@ namespace SabreTools
|
|||||||
OutputFormat outputFormat = OutputFormat.Folder;
|
OutputFormat outputFormat = OutputFormat.Folder;
|
||||||
SplitType splitType = SplitType.None;
|
SplitType splitType = SplitType.None;
|
||||||
StatDatFormat statDatFormat = 0x0;
|
StatDatFormat statDatFormat = 0x0;
|
||||||
|
StripHash stripHash = 0x0;
|
||||||
|
|
||||||
// User inputs
|
// User inputs
|
||||||
int gz = 2,
|
int gz = 2,
|
||||||
@@ -487,6 +488,10 @@ namespace SabreTools
|
|||||||
case "--rev-cascade":
|
case "--rev-cascade":
|
||||||
diffMode |= DiffMode.ReverseCascade;
|
diffMode |= DiffMode.ReverseCascade;
|
||||||
break;
|
break;
|
||||||
|
case "-rmd5":
|
||||||
|
case "--rem-md5":
|
||||||
|
stripHash |= StripHash.MD5;
|
||||||
|
break;
|
||||||
case "-rme":
|
case "-rme":
|
||||||
case "--rem-ext":
|
case "--rem-ext":
|
||||||
remext = true;
|
remext = true;
|
||||||
@@ -495,6 +500,14 @@ namespace SabreTools
|
|||||||
case "--romba":
|
case "--romba":
|
||||||
romba = true;
|
romba = true;
|
||||||
break;
|
break;
|
||||||
|
case "-rsha1":
|
||||||
|
case "--rem-sha1":
|
||||||
|
stripHash |= StripHash.SHA1;
|
||||||
|
break;
|
||||||
|
case "-rsha256":
|
||||||
|
case "--rem-sha256":
|
||||||
|
stripHash |= StripHash.SHA256;
|
||||||
|
break;
|
||||||
case "-run":
|
case "-run":
|
||||||
case "--runnable":
|
case "--runnable":
|
||||||
filter.Runnable = true;
|
filter.Runnable = true;
|
||||||
@@ -1187,7 +1200,7 @@ namespace SabreTools
|
|||||||
InitUpdate(inputs, filename, name, description, rootdir, category, version, date, author, email, homepage, url, comment, header,
|
InitUpdate(inputs, filename, name, description, rootdir, category, version, date, author, email, homepage, url, comment, header,
|
||||||
superdat, forcemerge, forcend, forcepack, excludeOf, datFormat, usegame, prefix,
|
superdat, forcemerge, forcend, forcepack, excludeOf, datFormat, usegame, prefix,
|
||||||
postfix, quotes, repext, addext, remext, datPrefix, romba, merge, diffMode, inplace, skip, removeDateFromAutomaticName,
|
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
|
// If we're using the verifier
|
||||||
|
|||||||
Reference in New Issue
Block a user