diff --git a/SabreTools.Helper/Tools/DatTools.cs b/SabreTools.Helper/Tools/DatTools.cs index 6eca1440..06572790 100644 --- a/SabreTools.Helper/Tools/DatTools.cs +++ b/SabreTools.Helper/Tools/DatTools.cs @@ -1877,281 +1877,6 @@ namespace SabreTools.Helper return true; } - /// - /// Output non-cascading diffs - /// - /// Non-zero flag for diffing mode, zero otherwise - /// Output directory to write the DATs to - /// Main DatData to draw information from - /// List of inputs to write out from - /// Logging object for console and file output - public static void DiffNoCascade(DiffMode diff, string outdir, Dat userData, List inputs, Logger logger) - { - DateTime start = DateTime.Now; - 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 - if ((diff & DiffMode.NoDupes) != 0) - { - post = " (No Duplicates)"; - outerDiffData = (Dat)userData.CloneHeader(); - outerDiffData.FileName += post; - outerDiffData.Name += post; - outerDiffData.Description += post; - outerDiffData.Files = new Dictionary>(); - } - - // Have External dupes - if ((diff & DiffMode.Dupes) != 0) - { - post = " (Duplicates)"; - dupeData = (Dat)userData.CloneHeader(); - dupeData.FileName += post; - dupeData.Name += post; - dupeData.Description += post; - dupeData.Files = new Dictionary>(); - } - - // Create a list of DatData objects representing individual output files - List outDats = new List(); - - // Loop through each of the inputs and get or create a new DatData object - if ((diff & DiffMode.Individuals) != 0) - { - Dat[] outDatsArray = new Dat[inputs.Count]; - - Parallel.For(0, inputs.Count, j => - { - string innerpost = " (" + Path.GetFileNameWithoutExtension(inputs[j].Split('¬')[0]) + " Only)"; - Dat diffData = (Dat)userData.CloneHeader(); - diffData.FileName += innerpost; - diffData.Name += innerpost; - diffData.Description += innerpost; - diffData.Files = new Dictionary>(); - outDatsArray[j] = diffData; - }); - - outDats = outDatsArray.ToList(); - } - logger.User("Initializing complete in " + DateTime.Now.Subtract(start).ToString(@"hh\:mm\:ss\.fffff")); - - // Now, loop through the dictionary and populate the correct DATs - start = DateTime.Now; - logger.User("Populating all output DATs"); - List keys = userData.Files.Keys.ToList(); - foreach (string key in keys) - { - List roms = RomTools.Merge(userData.Files[key], logger); - - if (roms != null && roms.Count > 0) - { - foreach (Rom rom in roms) - { - // No duplicates - if ((diff & DiffMode.NoDupes) != 0 || (diff & DiffMode.Individuals) != 0) - { - if (rom.Dupe < DupeType.ExternalHash) - { - // Individual DATs that are output - if ((diff & DiffMode.Individuals) != 0) - { - if (outDats[rom.Metadata.SystemID].Files.ContainsKey(key)) - { - outDats[rom.Metadata.SystemID].Files[key].Add(rom); - } - else - { - List tl = new List(); - tl.Add(rom); - outDats[rom.Metadata.SystemID].Files.Add(key, tl); - } - } - - // Merged no-duplicates DAT - if ((diff & DiffMode.NoDupes) != 0) - { - Rom newrom = rom; - newrom.Machine.Name += " (" + Path.GetFileNameWithoutExtension(inputs[newrom.Metadata.SystemID].Split('¬')[0]) + ")"; - - if (outerDiffData.Files.ContainsKey(key)) - { - outerDiffData.Files[key].Add(newrom); - } - else - { - List tl = new List(); - tl.Add(rom); - outerDiffData.Files.Add(key, tl); - } - } - } - } - - // Duplicates only - if ((diff & DiffMode.Dupes) != 0) - { - if (rom.Dupe >= DupeType.ExternalHash) - { - Rom newrom = rom; - newrom.Machine.Name += " (" + Path.GetFileNameWithoutExtension(inputs[newrom.Metadata.SystemID].Split('¬')[0]) + ")"; - - if (dupeData.Files.ContainsKey(key)) - { - dupeData.Files[key].Add(newrom); - } - else - { - List tl = new List(); - tl.Add(rom); - dupeData.Files.Add(key, tl); - } - } - } - } - } - } - logger.User("Populating complete in " + DateTime.Now.Subtract(start).ToString(@"hh\:mm\:ss\.fffff")); - - // Finally, loop through and output each of the DATs - start = DateTime.Now; - logger.User("Outputting all created DATs"); - - // Output the difflist (a-b)+(b-a) diff - if ((diff & DiffMode.NoDupes) != 0) - { - WriteDatfile(outerDiffData, outdir, logger); - } - - // Output the (ab) diff - if ((diff & DiffMode.Dupes) != 0) - { - WriteDatfile(dupeData, outdir, logger); - } - - // Output the individual (a-b) DATs - if ((diff & DiffMode.Individuals) != 0) - { - for (int j = 0; j < inputs.Count; j++) - { - // If we have an output directory set, replace the path - string path = outdir + (Path.GetDirectoryName(inputs[j].Split('¬')[0]).Remove(0, inputs[j].Split('¬')[1].Length)); - - // If we have more than 0 roms, output - if (outDats[j].Files.Count > 0) - { - WriteDatfile(outDats[j], path, logger); - } - } - } - logger.User("Outputting complete in " + DateTime.Now.Subtract(start).ToString(@"hh\:mm\:ss\.fffff")); - } - - /// - /// Output cascading diffs - /// - /// Output directory to write the DATs to - /// True if cascaded diffs are outputted in-place, false otherwise - /// Main DatData to draw information from - /// List of inputs to write out from - /// Dat headers used optionally - /// True if the first cascaded diff file should be skipped on output, false otherwise - /// Logging object for console and file output - public static void DiffCascade(string outdir, bool inplace, Dat userData, List inputs, List datHeaders, bool skip, Logger logger) - { - string post = ""; - - // Create a list of DatData objects representing output files - List outDats = new List(); - - // Loop through each of the inputs and get or create a new DatData object - DateTime start = DateTime.Now; - logger.User("Initializing all output DATs"); - - Dat[] outDatsArray = new Dat[inputs.Count]; - - Parallel.For(0, inputs.Count, j => - { - string innerpost = " (" + Path.GetFileNameWithoutExtension(inputs[j].Split('¬')[0]) + " Only)"; - Dat diffData; - - // If we're in inplace mode, take the appropriate DatData object already stored - if (inplace || !String.IsNullOrEmpty(outdir)) - { - diffData = datHeaders[j]; - } - else - { - diffData = (Dat)userData.CloneHeader(); - diffData.FileName += post; - diffData.Name += post; - diffData.Description += post; - } - diffData.Files = new Dictionary>(); - - outDatsArray[j] = diffData; - }); - - outDats = outDatsArray.ToList(); - logger.User("Initializing complete in " + DateTime.Now.Subtract(start).ToString(@"hh\:mm\:ss\.fffff")); - - // Now, loop through the dictionary and populate the correct DATs - start = DateTime.Now; - logger.User("Populating all output DATs"); - List keys = userData.Files.Keys.ToList(); - - foreach (string key in keys) - { - List roms = RomTools.Merge(userData.Files[key], logger); - - if (roms != null && roms.Count > 0) - { - foreach (Rom rom in roms) - { - if (outDats[rom.Metadata.SystemID].Files.ContainsKey(key)) - { - outDats[rom.Metadata.SystemID].Files[key].Add(rom); - } - else - { - List tl = new List(); - tl.Add(rom); - outDats[rom.Metadata.SystemID].Files.Add(key, tl); - } - } - } - } - logger.User("Populating complete in " + DateTime.Now.Subtract(start).ToString(@"hh\:mm\:ss\.fffff")); - - // Finally, loop through and output each of the DATs - start = DateTime.Now; - logger.User("Outputting all created DATs"); - for (int j = (skip ? 1 : 0); j < inputs.Count; j++) - { - // If we have an output directory set, replace the path - string path = ""; - if (inplace) - { - path = Path.GetDirectoryName(inputs[j].Split('¬')[0]); - } - else if (!String.IsNullOrEmpty(outdir)) - { - path = outdir + (Path.GetDirectoryName(inputs[j].Split('¬')[0]).Remove(0, inputs[j].Split('¬')[1].Length)); - } - - // If we have more than 0 roms, output - if (outDats[j].Files.Count > 0) - { - WriteDatfile(outDats[j], path, logger); - } - } - logger.User("Outputting complete in " + DateTime.Now.Subtract(start).ToString(@"hh\:mm\:ss\.fffff")); - } - /// /// Output user defined merge /// @@ -2437,6 +2162,281 @@ namespace SabreTools.Helper return datHeaders.ToList(); } + /// + /// Output non-cascading diffs + /// + /// Non-zero flag for diffing mode, zero otherwise + /// Output directory to write the DATs to + /// Main DatData to draw information from + /// List of inputs to write out from + /// Logging object for console and file output + public static void DiffNoCascade(DiffMode diff, string outdir, Dat userData, List inputs, Logger logger) + { + DateTime start = DateTime.Now; + 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 + if ((diff & DiffMode.NoDupes) != 0) + { + post = " (No Duplicates)"; + outerDiffData = (Dat)userData.CloneHeader(); + outerDiffData.FileName += post; + outerDiffData.Name += post; + outerDiffData.Description += post; + outerDiffData.Files = new Dictionary>(); + } + + // Have External dupes + if ((diff & DiffMode.Dupes) != 0) + { + post = " (Duplicates)"; + dupeData = (Dat)userData.CloneHeader(); + dupeData.FileName += post; + dupeData.Name += post; + dupeData.Description += post; + dupeData.Files = new Dictionary>(); + } + + // Create a list of DatData objects representing individual output files + List outDats = new List(); + + // Loop through each of the inputs and get or create a new DatData object + if ((diff & DiffMode.Individuals) != 0) + { + Dat[] outDatsArray = new Dat[inputs.Count]; + + Parallel.For(0, inputs.Count, j => + { + string innerpost = " (" + Path.GetFileNameWithoutExtension(inputs[j].Split('¬')[0]) + " Only)"; + Dat diffData = (Dat)userData.CloneHeader(); + diffData.FileName += innerpost; + diffData.Name += innerpost; + diffData.Description += innerpost; + diffData.Files = new Dictionary>(); + outDatsArray[j] = diffData; + }); + + outDats = outDatsArray.ToList(); + } + logger.User("Initializing complete in " + DateTime.Now.Subtract(start).ToString(@"hh\:mm\:ss\.fffff")); + + // Now, loop through the dictionary and populate the correct DATs + start = DateTime.Now; + logger.User("Populating all output DATs"); + List keys = userData.Files.Keys.ToList(); + foreach (string key in keys) + { + List roms = RomTools.Merge(userData.Files[key], logger); + + if (roms != null && roms.Count > 0) + { + foreach (Rom rom in roms) + { + // No duplicates + if ((diff & DiffMode.NoDupes) != 0 || (diff & DiffMode.Individuals) != 0) + { + if (rom.Dupe < DupeType.ExternalHash) + { + // Individual DATs that are output + if ((diff & DiffMode.Individuals) != 0) + { + if (outDats[rom.Metadata.SystemID].Files.ContainsKey(key)) + { + outDats[rom.Metadata.SystemID].Files[key].Add(rom); + } + else + { + List tl = new List(); + tl.Add(rom); + outDats[rom.Metadata.SystemID].Files.Add(key, tl); + } + } + + // Merged no-duplicates DAT + if ((diff & DiffMode.NoDupes) != 0) + { + Rom newrom = rom; + newrom.Machine.Name += " (" + Path.GetFileNameWithoutExtension(inputs[newrom.Metadata.SystemID].Split('¬')[0]) + ")"; + + if (outerDiffData.Files.ContainsKey(key)) + { + outerDiffData.Files[key].Add(newrom); + } + else + { + List tl = new List(); + tl.Add(rom); + outerDiffData.Files.Add(key, tl); + } + } + } + } + + // Duplicates only + if ((diff & DiffMode.Dupes) != 0) + { + if (rom.Dupe >= DupeType.ExternalHash) + { + Rom newrom = rom; + newrom.Machine.Name += " (" + Path.GetFileNameWithoutExtension(inputs[newrom.Metadata.SystemID].Split('¬')[0]) + ")"; + + if (dupeData.Files.ContainsKey(key)) + { + dupeData.Files[key].Add(newrom); + } + else + { + List tl = new List(); + tl.Add(rom); + dupeData.Files.Add(key, tl); + } + } + } + } + } + } + logger.User("Populating complete in " + DateTime.Now.Subtract(start).ToString(@"hh\:mm\:ss\.fffff")); + + // Finally, loop through and output each of the DATs + start = DateTime.Now; + logger.User("Outputting all created DATs"); + + // Output the difflist (a-b)+(b-a) diff + if ((diff & DiffMode.NoDupes) != 0) + { + WriteDatfile(outerDiffData, outdir, logger); + } + + // Output the (ab) diff + if ((diff & DiffMode.Dupes) != 0) + { + WriteDatfile(dupeData, outdir, logger); + } + + // Output the individual (a-b) DATs + if ((diff & DiffMode.Individuals) != 0) + { + for (int j = 0; j < inputs.Count; j++) + { + // If we have an output directory set, replace the path + string path = outdir + (Path.GetDirectoryName(inputs[j].Split('¬')[0]).Remove(0, inputs[j].Split('¬')[1].Length)); + + // If we have more than 0 roms, output + if (outDats[j].Files.Count > 0) + { + WriteDatfile(outDats[j], path, logger); + } + } + } + logger.User("Outputting complete in " + DateTime.Now.Subtract(start).ToString(@"hh\:mm\:ss\.fffff")); + } + + /// + /// Output cascading diffs + /// + /// Output directory to write the DATs to + /// True if cascaded diffs are outputted in-place, false otherwise + /// Main DatData to draw information from + /// List of inputs to write out from + /// Dat headers used optionally + /// True if the first cascaded diff file should be skipped on output, false otherwise + /// Logging object for console and file output + public static void DiffCascade(string outdir, bool inplace, Dat userData, List inputs, List datHeaders, bool skip, Logger logger) + { + string post = ""; + + // Create a list of DatData objects representing output files + List outDats = new List(); + + // Loop through each of the inputs and get or create a new DatData object + DateTime start = DateTime.Now; + logger.User("Initializing all output DATs"); + + Dat[] outDatsArray = new Dat[inputs.Count]; + + Parallel.For(0, inputs.Count, j => + { + string innerpost = " (" + Path.GetFileNameWithoutExtension(inputs[j].Split('¬')[0]) + " Only)"; + Dat diffData; + + // If we're in inplace mode, take the appropriate DatData object already stored + if (inplace || !String.IsNullOrEmpty(outdir)) + { + diffData = datHeaders[j]; + } + else + { + diffData = (Dat)userData.CloneHeader(); + diffData.FileName += post; + diffData.Name += post; + diffData.Description += post; + } + diffData.Files = new Dictionary>(); + + outDatsArray[j] = diffData; + }); + + outDats = outDatsArray.ToList(); + logger.User("Initializing complete in " + DateTime.Now.Subtract(start).ToString(@"hh\:mm\:ss\.fffff")); + + // Now, loop through the dictionary and populate the correct DATs + start = DateTime.Now; + logger.User("Populating all output DATs"); + List keys = userData.Files.Keys.ToList(); + + foreach (string key in keys) + { + List roms = RomTools.Merge(userData.Files[key], logger); + + if (roms != null && roms.Count > 0) + { + foreach (Rom rom in roms) + { + if (outDats[rom.Metadata.SystemID].Files.ContainsKey(key)) + { + outDats[rom.Metadata.SystemID].Files[key].Add(rom); + } + else + { + List tl = new List(); + tl.Add(rom); + outDats[rom.Metadata.SystemID].Files.Add(key, tl); + } + } + } + } + logger.User("Populating complete in " + DateTime.Now.Subtract(start).ToString(@"hh\:mm\:ss\.fffff")); + + // Finally, loop through and output each of the DATs + start = DateTime.Now; + logger.User("Outputting all created DATs"); + for (int j = (skip ? 1 : 0); j < inputs.Count; j++) + { + // If we have an output directory set, replace the path + string path = ""; + if (inplace) + { + path = Path.GetDirectoryName(inputs[j].Split('¬')[0]); + } + else if (!String.IsNullOrEmpty(outdir)) + { + path = outdir + (Path.GetDirectoryName(inputs[j].Split('¬')[0]).Remove(0, inputs[j].Split('¬')[1].Length)); + } + + // If we have more than 0 roms, output + if (outDats[j].Files.Count > 0) + { + WriteDatfile(outDats[j], path, logger); + } + } + logger.User("Outputting complete in " + DateTime.Now.Subtract(start).ToString(@"hh\:mm\:ss\.fffff")); + } + #endregion #region DAT Writing