From ae2b8fd44d9b067be8ac48e0a8049dcea0b073a5 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Thu, 28 Apr 2016 11:31:35 -0700 Subject: [PATCH] Add more code for dictionary based merging --- DATabase/MergeDiff.cs | 63 ++++++++++++++++++++++++++++------ SabreHelper/RomManipulation.cs | 4 +-- 2 files changed, 55 insertions(+), 12 deletions(-) diff --git a/DATabase/MergeDiff.cs b/DATabase/MergeDiff.cs index d8317a07..c9172021 100644 --- a/DATabase/MergeDiff.cs +++ b/DATabase/MergeDiff.cs @@ -100,6 +100,7 @@ namespace SabreTools _author = "SabreTools"; } + /* // Create the database of ROMs from the input DATs SqliteConnection dbc = DBTools.InMemoryDb(); foreach (string input in _inputs) @@ -111,30 +112,72 @@ namespace SabreTools // Output all DATs specified by user inputs Output.WriteToDatFromDb(_name, _desc, _version, _date, _cat, _author, _forceunpack, _old, _diff, _ad, "", dbc, _logger); dbc.Close(); + */ // Create a dictionary of all ROMs from the input DATs Dictionary> dict = new Dictionary>(); foreach (string input in _inputs) { _logger.Log("Adding DAT: " + input); - RomManipulation.ParseDict(input, 0, 0, dict, _logger); + dict = RomManipulation.ParseDict(input, 0, 0, dict, _logger); } // Modify the Dictionary if necessary and output the results - if (_diff) + if (_diff || _ad) { // Get all entries that have only one item in their list + Dictionary> diffed = new Dictionary>(); + foreach (string key in dict.Keys) + { + if (dict[key].Count == 1) + { + diffed.Add(key, dict[key]); + } + } + + // 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); + } + + // For the AB mode, get all required dictionaries and output with a new name + if (_ad) + { + // 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) + { + if (diffed[key][0].System == filename) + { + sysDict.Add(key, diffed[key]); + } + } + + 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) + { + if (dict[key].Count > 1) + { + duplicates.Add(key, diffed[key]); + } + } + Output.WriteToDatFromDict(_name + post, _desc + post, _version, _date, _cat, _author, _forceunpack, _old, true, "", duplicates, _logger); + } } + // Output all entries with user-defined merge else { - // Output all entries with user-defined merge - } - - // For the AB mode, get all required dictionaries and output with a new name - if (_ad) - { - // Loop through _inputs first and filter from all diffed roms to find the ones that have the same "System" - // Then loop through all that have a count > 1 for the AB merged DAT + Output.WriteToDatFromDict(_name, _desc, _version, _date, _cat, _author, _forceunpack, _old, _dedup, "", dict, _logger); } return true; diff --git a/SabreHelper/RomManipulation.cs b/SabreHelper/RomManipulation.cs index a7539f3d..acc9fe58 100644 --- a/SabreHelper/RomManipulation.cs +++ b/SabreHelper/RomManipulation.cs @@ -559,7 +559,7 @@ VALUES ('" + tempname.Replace("'", "''") + "', '" + /// The dictionary to add found roms to /// Logger object for console and/or file output /// Dictionary with "crc-sha1-size" key and List of RomData objects value representing the found data - public static bool ParseDict(string filename, int sysid, int srcid, Dictionary> dict, Logger logger) + public static Dictionary> ParseDict(string filename, int sysid, int srcid, Dictionary> dict, Logger logger) { XmlTextReader xtr = GetXmlTextReader(filename, logger); xtr.WhitespaceHandling = WhitespaceHandling.None; @@ -701,7 +701,7 @@ VALUES ('" + tempname.Replace("'", "''") + "', '" + } } - return true; + return dict; } ///