[DatTools] Add flag usage to Diff

This commit is contained in:
Matt Nadareski
2016-08-26 12:12:32 -07:00
parent 5f6294af9a
commit 05d81c3591

View File

@@ -1603,7 +1603,7 @@ namespace SabreTools.Helper
// Modify the Dictionary if necessary and output the results // Modify the Dictionary if necessary and output the results
if (diff != 0 && cascade == null) if (diff != 0 && cascade == null)
{ {
DiffNoCascade(outputDirectory, userData, newInputFileNames, logger); DiffNoCascade(diff, outputDirectory, userData, newInputFileNames, logger);
} }
// 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 && cascade != null) else if (diff != 0 && cascade != null)
@@ -1924,33 +1924,47 @@ namespace SabreTools.Helper
/// <summary> /// <summary>
/// Output non-cascading diffs /// Output non-cascading diffs
/// </summary> /// </summary>
/// <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="userData">Main DatData to draw information from</param> /// <param name="userData">Main DatData to draw information from</param>
/// <param name="inputs">List of inputs to write out from</param> /// <param name="inputs">List of inputs to write out from</param>
/// <param name="logger">Logging object for console and file output</param> /// <param name="logger">Logging object for console and file output</param>
public static void DiffNoCascade(string outdir, Dat userData, List<string> inputs, Logger logger) public static void DiffNoCascade(DiffMode diff, string outdir, Dat userData, List<string> inputs, Logger logger)
{ {
DateTime start = DateTime.Now; DateTime start = DateTime.Now;
logger.User("Initializing all output DATs"); logger.User("Initializing all output DATs");
// Default vars for use
string post = "";
Dat outerDiffData = new Dat();
Dat dupeData = new Dat();
// Don't have External dupes // Don't have External dupes
string post = " (No Duplicates)"; if ((diff & DiffMode.NoDupes) != 0)
Dat outerDiffData = (Dat)userData.CloneHeader(); {
post = " (No Duplicates)";
outerDiffData = (Dat)userData.CloneHeader();
outerDiffData.FileName += post; outerDiffData.FileName += post;
outerDiffData.Name += post; outerDiffData.Name += post;
outerDiffData.Description += post; outerDiffData.Description += post;
}
// Have External dupes // Have External dupes
if ((diff & DiffMode.Dupes) != 0)
{
post = " (Duplicates)"; post = " (Duplicates)";
Dat dupeData = (Dat)userData.CloneHeader(); dupeData = (Dat)userData.CloneHeader();
dupeData.FileName += post; dupeData.FileName += post;
dupeData.Name += post; dupeData.Name += post;
dupeData.Description += post; dupeData.Description += post;
}
// Create a list of DatData objects representing individual output files // Create a list of DatData objects representing individual output files
List<Dat> outDats = new List<Dat>(); List<Dat> outDats = new List<Dat>();
// 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)
{
for (int j = 0; j < inputs.Count; j++) for (int j = 0; j < inputs.Count; j++)
{ {
post = " (" + Path.GetFileNameWithoutExtension(inputs[j].Split('¬')[0]) + " Only)"; post = " (" + Path.GetFileNameWithoutExtension(inputs[j].Split('¬')[0]) + " Only)";
@@ -1960,6 +1974,7 @@ namespace SabreTools.Helper
diffData.Description += post; diffData.Description += post;
outDats.Add(diffData); outDats.Add(diffData);
} }
}
logger.User("Initializing complete in " + DateTime.Now.Subtract(start).ToString(@"hh\:mm\:ss\.fffff")); logger.User("Initializing complete in " + DateTime.Now.Subtract(start).ToString(@"hh\:mm\:ss\.fffff"));
// Now, loop through the dictionary and populate the correct DATs // Now, loop through the dictionary and populate the correct DATs
@@ -1975,9 +1990,13 @@ namespace SabreTools.Helper
foreach (Rom rom in roms) foreach (Rom rom in roms)
{ {
// No duplicates // No duplicates
if ((diff & DiffMode.NoDupes) != 0 || (diff & DiffMode.Individuals) != 0)
{
if (rom.Dupe < DupeType.ExternalHash) if (rom.Dupe < DupeType.ExternalHash)
{ {
// Individual DATs that are output // Individual DATs that are output
if ((diff & DiffMode.Individuals) != 0)
{
if (outDats[rom.Metadata.SystemID].Roms.ContainsKey(key)) if (outDats[rom.Metadata.SystemID].Roms.ContainsKey(key))
{ {
outDats[rom.Metadata.SystemID].Roms[key].Add(rom); outDats[rom.Metadata.SystemID].Roms[key].Add(rom);
@@ -1988,8 +2007,11 @@ namespace SabreTools.Helper
tl.Add(rom); tl.Add(rom);
outDats[rom.Metadata.SystemID].Roms.Add(key, tl); outDats[rom.Metadata.SystemID].Roms.Add(key, tl);
} }
}
// Merged no-duplicates DAT // Merged no-duplicates DAT
if ((diff & DiffMode.NoDupes) != 0)
{
Rom newrom = rom; Rom newrom = rom;
newrom.Game += " (" + Path.GetFileNameWithoutExtension(inputs[newrom.Metadata.SystemID].Split('¬')[0]) + ")"; newrom.Game += " (" + Path.GetFileNameWithoutExtension(inputs[newrom.Metadata.SystemID].Split('¬')[0]) + ")";
@@ -2004,8 +2026,12 @@ namespace SabreTools.Helper
outerDiffData.Roms.Add(key, tl); outerDiffData.Roms.Add(key, tl);
} }
} }
}
}
// Duplicates only // Duplicates only
if ((diff & DiffMode.Dupes) != 0)
{
if (rom.Dupe >= DupeType.ExternalHash) if (rom.Dupe >= DupeType.ExternalHash)
{ {
Rom newrom = rom; Rom newrom = rom;
@@ -2025,6 +2051,7 @@ namespace SabreTools.Helper
} }
} }
} }
}
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"));
// Finally, loop through and output each of the DATs // Finally, loop through and output each of the DATs