From a202dc3dbb27debac5f579c57283d9ee8f6bdd9d Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Thu, 28 Apr 2016 11:06:27 -0700 Subject: [PATCH] More changes to enable Dictionary merging --- DATabase/MergeDiff.cs | 22 ++++++++++++++++++++++ SabreHelper/Output.cs | 12 ++++++++---- SabreHelper/RomManipulation.cs | 12 ++++++------ 3 files changed, 36 insertions(+), 10 deletions(-) diff --git a/DATabase/MergeDiff.cs b/DATabase/MergeDiff.cs index a7e4112a..d8317a07 100644 --- a/DATabase/MergeDiff.cs +++ b/DATabase/MergeDiff.cs @@ -113,7 +113,29 @@ namespace SabreTools 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); + } + // Modify the Dictionary if necessary and output the results + if (_diff) + { + // Get all entries that have only one item in their list + } + 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 + } return true; } diff --git a/SabreHelper/Output.cs b/SabreHelper/Output.cs index 9f96b39b..41123b4c 100644 --- a/SabreHelper/Output.cs +++ b/SabreHelper/Output.cs @@ -320,14 +320,13 @@ namespace SabreTools.Helper /// DAT author /// Force all sets to be unzipped /// Set output mode to old-style DAT - /// Only output files that don't have dupes - /// Enable output of files just in each DAT and also just duped. Best if combined with diff=true. + /// Enable output in merged mode (one game per hash) /// Set the output directory /// Dictionary containing all the roms to be written /// Logger object for console and/or file output /// Tru if the DAT was written correctly, false otherwise public static bool WriteToDatFromDict(string name, string description, string version, string date, string category, string author, - bool forceunpack, bool old, bool diff, bool ab, string outDir, Dictionary> dict, Logger logger) + bool forceunpack, bool old, bool merge, string outDir, Dictionary> dict, Logger logger) { // If it's empty, use the current folder if (outDir.Trim() == "") @@ -415,8 +414,13 @@ namespace SabreTools.Helper } lastgame = value.Game; - sw.Write(state); + + // If we're in merged mode, only write the first file in each list + if (merge) + { + break; + } } } diff --git a/SabreHelper/RomManipulation.cs b/SabreHelper/RomManipulation.cs index 4996aa3f..a7539f3d 100644 --- a/SabreHelper/RomManipulation.cs +++ b/SabreHelper/RomManipulation.cs @@ -556,11 +556,11 @@ VALUES ('" + tempname.Replace("'", "''") + "', '" + /// Name of the file to be parsed /// System ID for the DAT /// Source ID for the DAT + /// 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 Dictionary> ParseDict(string filename, int sysid, int srcid, Logger logger) + public static bool ParseDict(string filename, int sysid, int srcid, Dictionary> dict, Logger logger) { - Dictionary> roms = new Dictionary>(); XmlTextReader xtr = GetXmlTextReader(filename, logger); xtr.WhitespaceHandling = WhitespaceHandling.None; bool superdat = false, shouldbreak = false; @@ -667,15 +667,15 @@ VALUES ('" + tempname.Replace("'", "''") + "', '" + System = filename, }; - if (roms.ContainsKey(key)) + if (dict.ContainsKey(key)) { - roms[key].Add(value); + dict[key].Add(value); } else { List newvalue = new List(); newvalue.Add(value); - roms.Add(key, newvalue); + dict.Add(key, newvalue); } break; } @@ -701,7 +701,7 @@ VALUES ('" + tempname.Replace("'", "''") + "', '" + } } - return roms; + return true; } ///