[Enums] DiffMode -> UpdateMode

This commit is contained in:
Matt Nadareski
2017-10-30 16:29:34 -07:00
parent fce523f02d
commit 4652e8cdf9
4 changed files with 75 additions and 73 deletions

View File

@@ -1592,7 +1592,7 @@ namespace SabreTools.Library.DatFiles
/// <param name="basePaths">Names of base files and/or folders</param> /// <param name="basePaths">Names of base files and/or folders</param>
/// <param name="outDir">Optional param for output directory</param> /// <param name="outDir">Optional param for output directory</param>
/// <param name="merge">True if input files should be merged into a single file, false otherwise</param> /// <param name="merge">True if input files should be merged into a single file, false otherwise</param>
/// <param name="diff">Non-zero flag for diffing mode, zero otherwise</param> /// <param name="updateMode">Non-zero flag for diffing mode, zero otherwise</param>
/// <param name="inplace">True if the output files should overwrite their inputs, false otherwise</param> /// <param name="inplace">True if the output files should overwrite their inputs, false otherwise</param>
/// <param name="skip">True if the first cascaded diff file should be skipped on output, false otherwise</param> /// <param name="skip">True if the first cascaded diff file should be skipped on output, false otherwise</param>
/// <param name="bare">True if the date should not be appended to the default name, false otherwise [OBSOLETE]</param> /// <param name="bare">True if the date should not be appended to the default name, false otherwise [OBSOLETE]</param>
@@ -1604,20 +1604,20 @@ namespace SabreTools.Library.DatFiles
/// <param name="trim">True if we are supposed to trim names to NTFS length, false otherwise</param> /// <param name="trim">True if we are supposed to trim names to NTFS length, false otherwise</param>
/// <param name="single">True if all games should be replaced by '!', false otherwise</param> /// <param name="single">True if all games should be replaced by '!', false otherwise</param>
/// <param name="root">String representing root directory to compare against for length calculation</param> /// <param name="root">String representing root directory to compare against for length calculation</param>
public void DetermineUpdateType(List<string> inputPaths, List<string> basePaths, string outDir, bool merge, DiffMode diff, bool inplace, bool skip, public void DetermineUpdateType(List<string> inputPaths, List<string> basePaths, string outDir, bool merge, UpdateMode updateMode, bool inplace, bool skip,
bool bare, bool clean, bool remUnicode, bool descAsName, Filter filter, SplitType splitType, bool trim, bool single, string root) bool bare, bool clean, bool remUnicode, bool descAsName, Filter filter, SplitType splitType, bool trim, bool single, string root)
{ {
// If we're in merging or diffing mode, use the full list of inputs // If we're in merging or diffing mode, use the full list of inputs
if (merge || (diff != 0 if (merge || (updateMode != UpdateMode.None
&& (diff & DiffMode.Against) == 0) && (updateMode & UpdateMode.Against) == 0)
&& (diff & DiffMode.BaseReplace) == 0 && (updateMode & UpdateMode.BaseReplace) == 0
&& (diff & DiffMode.ReverseBaseReplace) == 0) && (updateMode & UpdateMode.ReverseBaseReplace) == 0)
{ {
// Make sure there are no folders in inputs // Make sure there are no folders in inputs
List<string> newInputFileNames = FileTools.GetOnlyFilesFromInputs(inputPaths, appendparent: true); List<string> newInputFileNames = FileTools.GetOnlyFilesFromInputs(inputPaths, appendparent: true);
// Reverse if we have to // Reverse if we have to
if ((diff & DiffMode.ReverseCascade) != 0) if ((updateMode & UpdateMode.ReverseCascade) != 0)
{ {
newInputFileNames.Reverse(); newInputFileNames.Reverse();
} }
@@ -1627,12 +1627,12 @@ namespace SabreTools.Library.DatFiles
remUnicode, descAsName, outDir, filter, splitType, trim, single, root); remUnicode, descAsName, outDir, filter, splitType, trim, single, root);
// Modify the Dictionary if necessary and output the results // Modify the Dictionary if necessary and output the results
if (diff != 0 && diff < DiffMode.Cascade) if (updateMode != 0 && updateMode < UpdateMode.Cascade)
{ {
DiffNoCascade(diff, outDir, newInputFileNames); DiffNoCascade(updateMode, outDir, newInputFileNames);
} }
// If we're in cascade and diff, output only cascaded diffs // If we're in cascade and diff, output only cascaded diffs
else if (diff != 0 && diff >= DiffMode.Cascade) else if (updateMode != 0 && updateMode >= UpdateMode.Cascade)
{ {
DiffCascade(outDir, inplace, newInputFileNames, datHeaders, skip); DiffCascade(outDir, inplace, newInputFileNames, datHeaders, skip);
} }
@@ -1643,17 +1643,17 @@ namespace SabreTools.Library.DatFiles
} }
} }
// If we're in "diff against" mode, we treat the inputs differently // If we're in "diff against" mode, we treat the inputs differently
else if ((diff & DiffMode.Against) != 0) else if ((updateMode & UpdateMode.Against) != 0)
{ {
DiffAgainst(inputPaths, basePaths, outDir, inplace, clean, remUnicode, descAsName, filter, splitType, trim, single, root); DiffAgainst(inputPaths, basePaths, outDir, inplace, clean, remUnicode, descAsName, filter, splitType, trim, single, root);
} }
// If we're in "base replacement" mode, we treat the inputs differently // If we're in "base replacement" mode, we treat the inputs differently
else if ((diff & DiffMode.BaseReplace) != 0) else if ((updateMode & UpdateMode.BaseReplace) != 0)
{ {
BaseReplace(inputPaths, basePaths, outDir, inplace, clean, remUnicode, descAsName, filter, splitType, trim, single, root, false); BaseReplace(inputPaths, basePaths, outDir, inplace, clean, remUnicode, descAsName, filter, splitType, trim, single, root, false);
} }
// If we're in "reverse base replacement" mode, we treat the inputs differently // If we're in "reverse base replacement" mode, we treat the inputs differently
else if ((diff & DiffMode.ReverseBaseReplace) != 0) else if ((updateMode & UpdateMode.ReverseBaseReplace) != 0)
{ {
BaseReplace(inputPaths, basePaths, outDir, inplace, clean, remUnicode, descAsName, filter, splitType, trim, single, root, true); BaseReplace(inputPaths, basePaths, outDir, inplace, clean, remUnicode, descAsName, filter, splitType, trim, single, root, true);
} }
@@ -2056,7 +2056,7 @@ namespace SabreTools.Library.DatFiles
/// <param name="diff">Non-zero flag for diffing mode, zero otherwise</param> /// <param name="diff">Non-zero flag for diffing mode, zero otherwise</param>
/// <param name="outDir">Output directory to write the DATs to</param> /// <param name="outDir">Output directory to write the DATs to</param>
/// <param name="inputs">List of inputs to write out from</param> /// <param name="inputs">List of inputs to write out from</param>
public void DiffNoCascade(DiffMode diff, string outDir, List<string> inputs) public void DiffNoCascade(UpdateMode diff, string outDir, List<string> inputs)
{ {
InternalStopwatch watch = new InternalStopwatch("Initializing all output DATs"); InternalStopwatch watch = new InternalStopwatch("Initializing all output DATs");
@@ -2080,7 +2080,7 @@ namespace SabreTools.Library.DatFiles
} }
// Don't have External dupes // Don't have External dupes
if ((diff & DiffMode.NoDupes) != 0) if ((diff & UpdateMode.NoDupes) != 0)
{ {
post = " (No Duplicates)"; post = " (No Duplicates)";
outerDiffData = new DatFile(this); outerDiffData = new DatFile(this);
@@ -2091,7 +2091,7 @@ namespace SabreTools.Library.DatFiles
} }
// Have External dupes // Have External dupes
if ((diff & DiffMode.Dupes) != 0) if ((diff & UpdateMode.Dupes) != 0)
{ {
post = " (Duplicates)"; post = " (Duplicates)";
dupeData = new DatFile(this); dupeData = new DatFile(this);
@@ -2105,7 +2105,7 @@ namespace SabreTools.Library.DatFiles
List<DatFile> outDats = new List<DatFile>(); List<DatFile> outDats = new List<DatFile>();
// Loop through each of the inputs and get or create a new DatData object // Loop through each of the inputs and get or create a new DatData object
if ((diff & DiffMode.Individuals) != 0) if ((diff & UpdateMode.Individuals) != 0)
{ {
DatFile[] outDatsArray = new DatFile[inputs.Count]; DatFile[] outDatsArray = new DatFile[inputs.Count];
@@ -2143,18 +2143,18 @@ namespace SabreTools.Library.DatFiles
foreach (DatItem item in items) foreach (DatItem item in items)
{ {
// No duplicates // No duplicates
if ((diff & DiffMode.NoDupes) != 0 || (diff & DiffMode.Individuals) != 0) if ((diff & UpdateMode.NoDupes) != 0 || (diff & UpdateMode.Individuals) != 0)
{ {
if ((item.Dupe & DupeType.Internal) != 0) if ((item.Dupe & DupeType.Internal) != 0)
{ {
// Individual DATs that are output // Individual DATs that are output
if ((diff & DiffMode.Individuals) != 0) if ((diff & UpdateMode.Individuals) != 0)
{ {
outDats[item.SystemID].Add(key, item); outDats[item.SystemID].Add(key, item);
} }
// Merged no-duplicates DAT // Merged no-duplicates DAT
if ((diff & DiffMode.NoDupes) != 0) if ((diff & UpdateMode.NoDupes) != 0)
{ {
DatItem newrom = item.Clone() as DatItem; DatItem newrom = item.Clone() as DatItem;
newrom.MachineName += " (" + Path.GetFileNameWithoutExtension(inputs[newrom.SystemID].Split('¬')[0]) + ")"; newrom.MachineName += " (" + Path.GetFileNameWithoutExtension(inputs[newrom.SystemID].Split('¬')[0]) + ")";
@@ -2165,7 +2165,7 @@ namespace SabreTools.Library.DatFiles
} }
// Duplicates only // Duplicates only
if ((diff & DiffMode.Dupes) != 0) if ((diff & UpdateMode.Dupes) != 0)
{ {
if ((item.Dupe & DupeType.External) != 0) if ((item.Dupe & DupeType.External) != 0)
{ {
@@ -2184,19 +2184,19 @@ namespace SabreTools.Library.DatFiles
watch.Start("Outputting all created DATs"); watch.Start("Outputting all created DATs");
// Output the difflist (a-b)+(b-a) diff // Output the difflist (a-b)+(b-a) diff
if ((diff & DiffMode.NoDupes) != 0) if ((diff & UpdateMode.NoDupes) != 0)
{ {
outerDiffData.WriteToFile(outDir); outerDiffData.WriteToFile(outDir);
} }
// Output the (ab) diff // Output the (ab) diff
if ((diff & DiffMode.Dupes) != 0) if ((diff & UpdateMode.Dupes) != 0)
{ {
dupeData.WriteToFile(outDir); dupeData.WriteToFile(outDir);
} }
// Output the individual (a-b) DATs // Output the individual (a-b) DATs
if ((diff & DiffMode.Individuals) != 0) if ((diff & UpdateMode.Individuals) != 0)
{ {
Parallel.For(0, inputs.Count, Globals.ParallelOptions, j => Parallel.For(0, inputs.Count, Globals.ParallelOptions, j =>
{ {

View File

@@ -222,12 +222,46 @@ namespace SabreTools.Library.Data
ALL = 0xFFFFFFF, ALL = 0xFFFFFFF,
} }
/// <summary> /// <summary>
/// Determines which diffs should be created /// Determine what hashes to strip from the DAT
/// </summary> /// </summary>
[Flags] [Flags]
public enum DiffMode public enum Hash
{ {
CRC = 0x0001,
MD5 = CRC << 1,
SHA1 = MD5 << 1,
SHA256 = SHA1 << 1,
SHA384 = SHA256 << 1,
SHA512 = SHA384 << 1,
xxHash = SHA512 << 1,
// Special combinations
Standard = CRC | MD5 | SHA1,
DeepHashes = SHA256 | SHA384 | SHA512 | xxHash,
SecureHashes = MD5 | SHA1 | SHA256 | SHA384 | SHA512 | xxHash,
}
/// <summary>
/// Determine which format to output Stats to
/// </summary>
/// [Flags]
public enum StatDatFormat
{
None = 0x01,
HTML = None << 1,
CSV = HTML << 1,
TSV = CSV << 1,
}
/// <summary>
/// Determines special update modes
/// </summary>
[Flags]
public enum UpdateMode
{
None = 0x00,
// Standard diffs // Standard diffs
Dupes = 0x01, Dupes = 0x01,
NoDupes = Dupes << 1, NoDupes = Dupes << 1,
@@ -246,38 +280,6 @@ namespace SabreTools.Library.Data
ReverseBaseReplace = BaseReplace << 1, ReverseBaseReplace = BaseReplace << 1,
} }
/// <summary>
/// Determine which format to output Stats to
/// </summary>
/// [Flags]
public enum StatDatFormat
{
None = 0x01,
HTML = None << 1,
CSV = HTML << 1,
TSV = CSV << 1,
}
/// <summary>
/// Determine what hashes to strip from the DAT
/// </summary>
[Flags]
public enum Hash
{
CRC = 0x0001,
MD5 = CRC << 1,
SHA1 = MD5 << 1,
SHA256 = SHA1 << 1,
SHA384 = SHA256 << 1,
SHA512 = SHA384 << 1,
xxHash = SHA512 << 1,
// Special combinations
Standard = CRC | MD5 | SHA1,
DeepHashes = SHA256 | SHA384 | SHA512 | xxHash,
SecureHashes = MD5 | SHA1 | SHA256 | SHA384 | SHA512 | xxHash,
}
#endregion #endregion
#region DatItem related #region DatItem related

View File

@@ -541,7 +541,7 @@ namespace SabreTools
/* Merging and Diffing info */ /* Merging and Diffing info */
bool merge, bool merge,
DiffMode diffMode, UpdateMode diffMode,
bool inplace, bool inplace,
bool skip, bool skip,
bool bare, bool bare,

View File

@@ -122,13 +122,13 @@ namespace SabreTools
usegame = true; usegame = true;
DatFormat datFormat = 0x0; DatFormat datFormat = 0x0;
DedupeType dedup = DedupeType.None; DedupeType dedup = DedupeType.None;
DiffMode diffMode = 0x0;
Hash omitFromScan = Hash.SHA256 | Hash.SHA384 | Hash.SHA512; // Should be set to 0x0 later Hash omitFromScan = Hash.SHA256 | Hash.SHA384 | Hash.SHA512; // Should be set to 0x0 later
Hash stripHash = 0x0; Hash stripHash = 0x0;
OutputFormat outputFormat = OutputFormat.Folder; OutputFormat outputFormat = OutputFormat.Folder;
SkipFileType skipFileType = SkipFileType.None; SkipFileType skipFileType = SkipFileType.None;
SplitType splitType = SplitType.None; SplitType splitType = SplitType.None;
StatDatFormat statDatFormat = 0x0; StatDatFormat statDatFormat = 0x0;
UpdateMode updateMode = UpdateMode.None;
// User inputs // User inputs
int gz = 2, int gz = 2,
@@ -290,7 +290,7 @@ namespace SabreTools
break; break;
case "-ag": case "-ag":
case "--against": case "--against":
diffMode |= DiffMode.Against; updateMode |= UpdateMode.Against;
break; break;
case "-b": case "-b":
case "--bare": case "--bare":
@@ -306,11 +306,11 @@ namespace SabreTools
break; break;
case "-bn": case "-bn":
case "--base-name": case "--base-name":
diffMode |= DiffMode.BaseReplace; updateMode |= UpdateMode.BaseReplace;
break; break;
case "-c": case "-c":
case "--cascade": case "--cascade":
diffMode |= DiffMode.Cascade; updateMode |= UpdateMode.Cascade;
break; break;
case "-cf": case "-cf":
case "--copy-files": case "--copy-files":
@@ -342,19 +342,19 @@ namespace SabreTools
break; break;
case "-di": case "-di":
case "--diff": case "--diff":
diffMode |= DiffMode.All; updateMode |= UpdateMode.All;
break; break;
case "-did": case "-did":
case "--diff-du": case "--diff-du":
diffMode |= DiffMode.Dupes; updateMode |= UpdateMode.Dupes;
break; break;
case "-dii": case "-dii":
case "--diff-in": case "--diff-in":
diffMode |= DiffMode.Individuals; updateMode |= UpdateMode.Individuals;
break; break;
case "-din": case "-din":
case "--diff-nd": case "--diff-nd":
diffMode |= DiffMode.NoDupes; updateMode |= UpdateMode.NoDupes;
break; break;
case "-dm": case "-dm":
case "--dat-merged": case "--dat-merged":
@@ -530,7 +530,7 @@ namespace SabreTools
break; break;
case "-rc": case "-rc":
case "--rev-cascade": case "--rev-cascade":
diffMode |= DiffMode.ReverseCascade; updateMode |= UpdateMode.ReverseCascade;
break; break;
case "-rmd5": case "-rmd5":
case "--rem-md5": case "--rem-md5":
@@ -832,7 +832,7 @@ namespace SabreTools
break; break;
case "-rbn": case "-rbn":
case "--reverse-base-name": case "--reverse-base-name":
diffMode |= DiffMode.ReverseBaseReplace; updateMode |= UpdateMode.ReverseBaseReplace;
break; break;
case "-rd": case "-rd":
case "--root-dir": case "--root-dir":
@@ -1319,7 +1319,7 @@ namespace SabreTools
{ {
InitUpdate(inputs, basePaths, filename, name, description, rootdir, category, version, date, author, email, homepage, url, comment, header, InitUpdate(inputs, basePaths, filename, name, description, rootdir, category, version, date, author, email, homepage, url, comment, header,
superdat, forcemerge, forcend, forcepack, excludeOf, sceneDateStrip, datFormat, usegame, prefix, postfix, quotes, repext, addext, remext, superdat, forcemerge, forcend, forcepack, excludeOf, sceneDateStrip, datFormat, usegame, prefix, postfix, quotes, repext, addext, remext,
datPrefix, romba, merge, diffMode, inplace, skip, removeDateFromAutomaticName, filter, oneGameOneRegion, regions, datPrefix, romba, merge, updateMode, inplace, skip, removeDateFromAutomaticName, filter, oneGameOneRegion, regions,
splitType, trim, single, root, outDir, cleanGameNames, removeUnicode, descAsName, dedup, stripHash); splitType, trim, single, root, outDir, cleanGameNames, removeUnicode, descAsName, dedup, stripHash);
} }