diff --git a/DATabase/DATabase.cs b/DATabase/DATabase.cs index 696f9ad7..04ba1b36 100644 --- a/DATabase/DATabase.cs +++ b/DATabase/DATabase.cs @@ -53,6 +53,7 @@ namespace SabreTools bool help = false, add = false, bare = false, + cascade = false, convertMiss = false, convertCMP = false, convertRC = false, @@ -116,6 +117,10 @@ namespace SabreTools case "--bare": bare = true; break; + case "-c": + case "--cascade": + cascade = true; + break; case "-cc": case "--convert-cmp": convertCMP = true; @@ -466,7 +471,7 @@ namespace SabreTools // Merge, diff, and dedupe at least 2 DATs else if (merge || diff) { - InitMergeDiff(inputs, name, desc, cat, version, author, diff, dedup, bare, forceunpack, old, superdat); + InitMergeDiff(inputs, name, desc, cat, version, author, diff, dedup, bare, forceunpack, old, superdat, cascade); } logger.Close(); @@ -920,7 +925,7 @@ Make a selection: private static void MergeDiffMenu() { string selection = "", input = "", name = "", desc = "", cat = "", version = "", author = ""; - bool dedup = false, diff = false, bare = false, forceunpack = false, old = false, superdat = false; + bool dedup = false, diff = false, bare = false, forceunpack = false, old = false, superdat = false, cascade = false; while (selection.ToLowerInvariant() != "b") { Console.Clear(); @@ -941,7 +946,8 @@ Make a selection: 10) " + (forceunpack ? "Remove 'forcepacking=\"unzip\"' from output" : "Add 'forcepacking=\"unzip\"' to output") + @" 11) " + (old ? "Enable XML output" : "Enable ClrMamePro output") + @" 12) " + (superdat ? "Disable SuperDAT output" : "Enable SuperDAT output") + @" - 13) Merge the DATs + 13) " + (cascade ? "Disable cascaded diffing (only if diff enabled)" : "Enable cascaded diffing (only if diff enabled)") + @" + 14) Merge the DATs B) Go back to the previous menu "); Console.Write("Enter selection: "); @@ -997,9 +1003,12 @@ Make a selection: superdat = !superdat; break; case "13": + cascade = !cascade; + break; + case "14": Console.Clear(); List inputs = new List(input.Split(';')); - InitMergeDiff(inputs, name, desc, cat, version, author, diff, dedup, bare, forceunpack, old, superdat); + InitMergeDiff(inputs, name, desc, cat, version, author, diff, dedup, bare, forceunpack, old, superdat, cascade); Console.Write("\nPress any key to continue..."); Console.ReadKey(); selection = ""; input = ""; name = ""; desc = ""; cat = ""; version = ""; author = ""; @@ -1485,8 +1494,9 @@ Make a selection: /// True if the forcepacking="unzip" tag is to be added, false otherwise /// True if a old-style DAT should be output, false otherwise /// True if DATs should be merged in SuperDAT style, false otherwise + /// True if the outputted diffs should be cascaded, false otherwise private static void InitMergeDiff(List inputs, string name, string desc, string cat, string version, string author, - bool diff, bool dedup, bool bare, bool forceunpack, bool old, bool superdat) + bool diff, bool dedup, bool bare, bool forceunpack, bool old, bool superdat, bool cascade) { // Make sure there are no folders in inputs List newInputs = new List(); @@ -1519,7 +1529,7 @@ Make a selection: } } - MergeDiff md = new MergeDiff(newInputs, name, desc, cat, version, author, diff, dedup, bare, forceunpack, old, superdat, logger); + MergeDiff md = new MergeDiff(newInputs, name, desc, cat, version, author, diff, dedup, bare, forceunpack, old, superdat, cascade, logger); md.Process(); } diff --git a/DATabase/MergeDiff.cs b/DATabase/MergeDiff.cs index 7d66633b..dab2e2fe 100644 --- a/DATabase/MergeDiff.cs +++ b/DATabase/MergeDiff.cs @@ -19,6 +19,7 @@ namespace SabreTools private bool _forceunpack; private bool _old; private bool _superdat; + private bool _cascade; // User specified strings private string _name; @@ -47,9 +48,10 @@ namespace SabreTools /// True if the forcepacking="unzip" tag is to be added, false otherwise /// True if a old-style DAT should be output, false otherwise /// True if DATs should be parsed into SuperDAT format, false otherwise + /// True if the outputted diffs should be cascaded, false otherwise /// Logger object for console and file output public MergeDiff(List inputs, string name, string desc, string cat, string version, string author, - bool diff, bool dedup, bool bare, bool forceunpack, bool old, bool superdat, Logger logger) + bool diff, bool dedup, bool bare, bool forceunpack, bool old, bool superdat, bool cascade, Logger logger) { _inputs = inputs; _name = name; @@ -63,6 +65,7 @@ namespace SabreTools _forceunpack = forceunpack; _old = old; _superdat = superdat; + _cascade = cascade; _logger = logger; } @@ -123,11 +126,12 @@ namespace SabreTools userData = RomManipulation.Parse(input.Split('¬')[0], i, 0, userData, _logger); i++; } - + // Modify the Dictionary if necessary and output the results - if (_diff) + string post = ""; + if (_diff && !_cascade) { - string post = " (No Duplicates)"; + post = " (No Duplicates)"; // Get all entries that don't have External dupes DatData outerDiffData = new DatData @@ -251,6 +255,59 @@ namespace SabreTools Output.WriteDatfile(dupeData, "", _logger); } + // If we're in cascade and diff, output only cascaded diffs + else if (_diff && _cascade) + { + // Loop through _inputs first and filter from all diffed roms to find the ones that have the same "System" + for (int j = 0; j < _inputs.Count; j++) + { + post = " (" + Path.GetFileNameWithoutExtension(_inputs[j].Split('¬')[0]) + " Only)"; + DatData diffData = new DatData + { + Name = _name + post, + Description = _desc + post, + Version = _version, + Date = _date, + Category = _cat, + Author = _author, + ForcePacking = (_forceunpack ? ForcePacking.Unzip : ForcePacking.None), + OutputFormat = (_old ? OutputFormat.ClrMamePro : OutputFormat.Xml), + MergeRoms = _dedup, + Roms = new Dictionary>(), + }; + + List keys = userData.Roms.Keys.ToList(); + foreach (string key in keys) + { + List oldroms = RomManipulation.Merge(userData.Roms[key]); + List newroms = new List(); + + foreach (RomData rom in oldroms) + { + if (rom.SystemID == j) + { + if (diffData.Roms.ContainsKey(key)) + { + diffData.Roms[key].Add(rom); + } + else + { + List tl = new List(); + tl.Add(rom); + diffData.Roms.Add(key, tl); + } + } + else + { + newroms.Add(rom); + } + } + userData.Roms[key] = newroms; + } + + Output.WriteDatfile(diffData, "", _logger); + } + } // Output all entries with user-defined merge else { diff --git a/SabreHelper/Build.cs b/SabreHelper/Build.cs index 7940a50b..bb707d29 100644 --- a/SabreHelper/Build.cs +++ b/SabreHelper/Build.cs @@ -123,6 +123,7 @@ Options: -lsy, --list-systems List all systems (id <= name) -m, --merge Merge one or more DATs -di, --diff Output all diffdats (merge flag not required) + -c, --cascade Enable cascaded diffing -dd, --dedup Enable deduping in the created DAT -b, --bare Don't include date in file name -u, --unzip Force unzipping in created DAT diff --git a/SabreHelper/Converters.cs b/SabreHelper/Converters.cs index 046efd65..f8bcd97d 100644 --- a/SabreHelper/Converters.cs +++ b/SabreHelper/Converters.cs @@ -28,7 +28,7 @@ namespace SabreTools.Helper { XElement elem = new XElement("datafile"); - bool block = false, romfound = false; + bool block = false; for (int k = 0; k < filecontents.Length; k++) { string line = filecontents[k]; @@ -61,7 +61,6 @@ namespace SabreTools.Helper // If the line is a rom or disk and we're in a block else if ((line.Trim().StartsWith("rom (") || line.Trim().StartsWith("disk (")) && block) { - romfound = true; string[] gc = line.Trim().Split(' '); XElement temp = new XElement(gc[0]); @@ -152,7 +151,6 @@ namespace SabreTools.Helper // If we find an end bracket that's not associated with anything else, the block is done else if (Regex.IsMatch(line, _endPatternCMP) && block) { - romfound = false; block = false; elem = elem.Parent; }