diff --git a/DATabase/DATabase.cs b/DATabase/DATabase.cs index c5cd812e..50a69c11 100644 --- a/DATabase/DATabase.cs +++ b/DATabase/DATabase.cs @@ -51,7 +51,6 @@ namespace SabreTools // Set all default values bool help = false, - ad = false, add = false, bare = false, convertMiss = false, @@ -109,10 +108,6 @@ namespace SabreTools case "--add": add = true; break; - case "-ad": - case "--all-diff": - ad = true; - break; case "-b": case "--bare": bare = true; @@ -432,7 +427,7 @@ namespace SabreTools // Merge, diff, and dedupe at least 2 DATs else if (merge || diff) { - InitMergeDiff(inputs, name, desc, cat, version, author, ad, diff, dedup, bare, forceunpack, old); + InitMergeDiff(inputs, name, desc, cat, version, author, diff, dedup, bare, forceunpack, old); } logger.Close(); @@ -859,7 +854,7 @@ Make a selection: private static void MergeDiffMenu() { string selection = "", input = "", name = "", desc = "", cat = "", version = "", author = ""; - bool ad = false, dedup = false, diff = false, bare = false, forceunpack = false, old = false; + bool dedup = false, diff = false, bare = false, forceunpack = false, old = false; while (selection.ToLowerInvariant() != "b") { Console.Clear(); @@ -874,13 +869,12 @@ Make a selection: 4) Category" + (cat != "" ? ":\t" + cat : "") + @" 5) Version" + (version != "" ? ":\t" + version : "") + @" 6) Author" + (author != "" ? ":\t" + author : "") + @" - 7) " + (ad ? "Only output normal diff" : "Output all diff variants (2 files only)") + @" - 8) " + (dedup ? "Don't dedup files in output" : "Dedup files in output") + @" - 9) " + (diff ? "Only merge the input files" : "Diff the input files") + @" - 10) " + (bare ? "Don't append the date to the name" : "Append the date to the name") + @" - 11) " + (forceunpack ? "Remove 'forcepacking=\"unzip\"' from output" : "Add 'forcepacking=\"unzip\"' to output") + @" - 12) " + (old ? "Enable XML output" : "Enable ClrMamePro output") + @" - 13) Merge the DATs + 7) " + (dedup ? "Don't dedup files in output" : "Dedup files in output") + @" + 8) " + (diff ? "Only merge the input files" : "Diff the input files") + @" + 9) " + (bare ? "Don't append the date to the name" : "Append the date to the name") + @" + 10) " + (forceunpack ? "Remove 'forcepacking=\"unzip\"' from output" : "Add 'forcepacking=\"unzip\"' to output") + @" + 11) " + (old ? "Enable XML output" : "Enable ClrMamePro output") + @" + 12) Merge the DATs B) Go back to the previous menu "); Console.Write("Enter selection: "); @@ -918,31 +912,28 @@ Make a selection: author = Console.ReadLine(); break; case "7": - ad = !ad; - break; - case "8": dedup = !dedup; break; - case "9": + case "8": diff = !diff; break; - case "10": + case "9": bare = !bare; break; - case "11": + case "10": forceunpack = !forceunpack; break; - case "12": + case "11": old = !old; break; - case "13": + case "12": Console.Clear(); List inputs = new List(input.Split(';')); - InitMergeDiff(inputs, name, desc, cat, version, author, ad, diff, dedup, bare, forceunpack, old); + InitMergeDiff(inputs, name, desc, cat, version, author, diff, dedup, bare, forceunpack, old); Console.Write("\nPress any key to continue..."); Console.ReadKey(); selection = ""; input = ""; name = ""; desc = ""; cat = ""; version = ""; author = ""; - ad = false; dedup = false; diff = false; bare = false; forceunpack = false; old = false; + dedup = false; diff = false; bare = false; forceunpack = false; old = false; break; } } @@ -1380,7 +1371,7 @@ Make a selection: /// True if the date should be omitted from the DAT, false otherwise /// True if the forcepacking="unzip" tag is to be added, false otherwise /// True if a old-style DAT should be output, false otherwise - private static void InitMergeDiff(List inputs, string name, string desc, string cat, string version, string author, bool ad, bool diff, bool dedup, bool bare, bool forceunpack, bool old) + 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) { // Make sure there are no folders in inputs List newInputs = new List(); @@ -1399,7 +1390,7 @@ Make a selection: } } - MergeDiff md = new MergeDiff(newInputs, name, desc, cat, version, author, ad, diff, dedup, bare, forceunpack, old, logger); + MergeDiff md = new MergeDiff(newInputs, name, desc, cat, version, author, diff, dedup, bare, forceunpack, old, logger); md.Process(); } diff --git a/DATabase/MergeDiff.cs b/DATabase/MergeDiff.cs index 57ce3eba..bdd46287 100644 --- a/DATabase/MergeDiff.cs +++ b/DATabase/MergeDiff.cs @@ -12,7 +12,6 @@ namespace SabreTools private List _inputs; // User specified flags - private bool _ad; private bool _diff; private bool _dedup; private bool _bare; @@ -47,7 +46,7 @@ namespace SabreTools /// True if a old-style DAT should be output, false otherwise /// Logger object for console and file output public MergeDiff(List inputs, string name, string desc, string cat, string version, string author, - bool ad, bool diff, bool dedup, bool bare, bool forceunpack, bool old, Logger logger) + bool diff, bool dedup, bool bare, bool forceunpack, bool old, Logger logger) { _inputs = inputs; _name = name; @@ -55,7 +54,6 @@ namespace SabreTools _cat = cat; _version = version; _author = author; - _ad = ad; _diff = diff; _dedup = dedup; _bare = bare; @@ -71,9 +69,9 @@ namespace SabreTools public bool Process() { // Check if there are enough inputs - if ((!_ad && _inputs.Count < 1) || (_ad && _inputs.Count < 2)) + if (_inputs.Count < 1) { - _logger.Warning("At least " + (_ad ? "2" : "1") + " input(s) are required!"); + _logger.Warning("At least 1 input is required!"); return false; } @@ -110,7 +108,7 @@ namespace SabreTools } // Modify the Dictionary if necessary and output the results - if (_diff || _ad) + if (_diff) { // Get all entries that don't have External dupes Dictionary> diffed = new Dictionary>(); @@ -121,7 +119,7 @@ namespace SabreTools foreach (RomData rom in temp) { - if ((_dedup && rom.Dupe != DupeType.InternalHash) || (!_dedup && rom.Dupe != DupeType.InternalAll)) + if ((_dedup && rom.Dupe != DupeType.ExternalHash) || (!_dedup && rom.Dupe != DupeType.ExternalAll)) { if (diffed.ContainsKey(key)) { @@ -137,44 +135,68 @@ namespace SabreTools } } - // Output the difflist only if we're in diff mode and not AB - if (_diff) - { - Output.WriteToDatFromDict(_name, _desc, _version, _date, _cat, _author, _forceunpack, _old, _dedup, "", diffed, _logger); - } + // Output the difflist (a-b)+(b-a) diff + Output.WriteToDatFromDict(_name, _desc, _version, _date, _cat, _author, _forceunpack, _old, _dedup, "", diffed, _logger); - // For the AB mode, get all required dictionaries and output with a new name - if (_ad) + // For the AB mode-style diffs, get all required dictionaries and output with a new name + // Loop through _inputs first and filter from all diffed roms to find the ones that have the same "System" + string post = ""; + int j = 0; + foreach (string filename in _inputs) { - // Loop through _inputs first and filter from all diffed roms to find the ones that have the same "System" - string post = ""; - foreach (string filename in _inputs) + Dictionary> sysDict = new Dictionary>(); + foreach (string key in diffed.Keys) { - Dictionary> sysDict = new Dictionary>(); - foreach (string key in diffed.Keys) + foreach (RomData rom in diffed[key]) { - if (diffed[key][0].System == filename) + if (rom.SystemID == j) { - sysDict.Add(key, diffed[key]); + if (sysDict.ContainsKey(key)) + { + sysDict[key].Add(rom); + } + else + { + List tl = new List(); + tl.Add(rom); + sysDict.Add(key, tl); + } } } - - post = " (" + Path.GetFileNameWithoutExtension(filename) + ")"; - Output.WriteToDatFromDict(_name + post, _desc + post, _version, _date, _cat, _author, _forceunpack, _old, _dedup, "", sysDict, _logger); } - // Then loop through all that have a count > 1 for the AB merged DAT - Dictionary> duplicates = new Dictionary>(); - post = " (dupes)"; - foreach (string key in dict.Keys) + post = " (" + Path.GetFileNameWithoutExtension(filename) + ")"; + Output.WriteToDatFromDict(_name + post, _desc + post, _version, _date, _cat, _author, _forceunpack, _old, _dedup, "", sysDict, _logger); + + j++; + } + + // Get all entries that have External dupes + Dictionary> duplicates = new Dictionary>(); + post = " (dupes)"; + foreach (string key in dict.Keys) + { + List temp = dict[key]; + temp = RomManipulation.Merge(temp); + + foreach (RomData rom in temp) { - if (dict[key].Count > 1) + if ((_dedup && rom.Dupe == DupeType.ExternalHash) || (!_dedup && rom.Dupe == DupeType.ExternalAll)) { - duplicates.Add(key, dict[key]); + if (duplicates.ContainsKey(key)) + { + duplicates[key].Add(rom); + } + else + { + List tl = new List(); + tl.Add(rom); + duplicates.Add(key, tl); + } } } - Output.WriteToDatFromDict(_name + post, _desc + post, _version, _date, _cat, _author, _forceunpack, _old, _dedup, "", duplicates, _logger); } + Output.WriteToDatFromDict(_name + post, _desc + post, _version, _date, _cat, _author, _forceunpack, _old, _dedup, "", duplicates, _logger); } // Output all entries with user-defined merge else diff --git a/SabreHelper/Build.cs b/SabreHelper/Build.cs index e073512d..6ab6828e 100644 --- a/SabreHelper/Build.cs +++ b/SabreHelper/Build.cs @@ -117,8 +117,7 @@ Options: -lso, --list-sources List all sources (id <= name) -lsy, --list-systems List all systems (id <= name) -m, --merge Merge one or more DATs - -ad, --all-diff Enable output of all diff variants - -di, --diff Switch to diffdat mode (merge flag not required) + -di, --diff Output all diffdats (merge flag not required) -dd, --dedup Enable deduping in the created DAT -b, --bare Don't include date in file name -u, --unzip Force unzipping in created DAT