More changes to enable Dictionary merging

This commit is contained in:
Matt Nadareski
2016-04-28 11:06:27 -07:00
parent 9672a5962d
commit a202dc3dbb
3 changed files with 36 additions and 10 deletions

View File

@@ -113,7 +113,29 @@ namespace SabreTools
dbc.Close(); dbc.Close();
// Create a dictionary of all ROMs from the input DATs // Create a dictionary of all ROMs from the input DATs
Dictionary<string, List<RomData>> dict = new Dictionary<string, List<RomData>>();
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; return true;
} }

View File

@@ -320,14 +320,13 @@ namespace SabreTools.Helper
/// <param name="author">DAT author</param> /// <param name="author">DAT author</param>
/// <param name="forceunpack">Force all sets to be unzipped</param> /// <param name="forceunpack">Force all sets to be unzipped</param>
/// <param name="old">Set output mode to old-style DAT</param> /// <param name="old">Set output mode to old-style DAT</param>
/// <param name="diff">Only output files that don't have dupes</param> /// <param name="merge">Enable output in merged mode (one game per hash)</param>
/// <param name="ab">Enable output of files just in each DAT and also just duped. Best if combined with diff=true.</param>
/// <param name="outDir">Set the output directory</param> /// <param name="outDir">Set the output directory</param>
/// <param name="dict">Dictionary containing all the roms to be written</param> /// <param name="dict">Dictionary containing all the roms to be written</param>
/// <param name="logger">Logger object for console and/or file output</param> /// <param name="logger">Logger object for console and/or file output</param>
/// <returns>Tru if the DAT was written correctly, false otherwise</returns> /// <returns>Tru if the DAT was written correctly, false otherwise</returns>
public static bool WriteToDatFromDict(string name, string description, string version, string date, string category, string author, 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<string, List<RomData>> dict, Logger logger) bool forceunpack, bool old, bool merge, string outDir, Dictionary<string, List<RomData>> dict, Logger logger)
{ {
// If it's empty, use the current folder // If it's empty, use the current folder
if (outDir.Trim() == "") if (outDir.Trim() == "")
@@ -415,8 +414,13 @@ namespace SabreTools.Helper
} }
lastgame = value.Game; lastgame = value.Game;
sw.Write(state); sw.Write(state);
// If we're in merged mode, only write the first file in each list
if (merge)
{
break;
}
} }
} }

View File

@@ -556,11 +556,11 @@ VALUES ('" + tempname.Replace("'", "''") + "', '" +
/// <param name="filename">Name of the file to be parsed</param> /// <param name="filename">Name of the file to be parsed</param>
/// <param name="sysid">System ID for the DAT</param> /// <param name="sysid">System ID for the DAT</param>
/// <param name="srcid">Source ID for the DAT</param> /// <param name="srcid">Source ID for the DAT</param>
/// <param name="dict">The dictionary to add found roms to</param>
/// <param name="logger">Logger object for console and/or file output</param> /// <param name="logger">Logger object for console and/or file output</param>
/// <returns>Dictionary with "crc-sha1-size" key and List of RomData objects value representing the found data</returns> /// <returns>Dictionary with "crc-sha1-size" key and List of RomData objects value representing the found data</returns>
public static Dictionary<string, List<RomData>> ParseDict(string filename, int sysid, int srcid, Logger logger) public static bool ParseDict(string filename, int sysid, int srcid, Dictionary<string, List<RomData>> dict, Logger logger)
{ {
Dictionary<string, List<RomData>> roms = new Dictionary<string, List<RomData>>();
XmlTextReader xtr = GetXmlTextReader(filename, logger); XmlTextReader xtr = GetXmlTextReader(filename, logger);
xtr.WhitespaceHandling = WhitespaceHandling.None; xtr.WhitespaceHandling = WhitespaceHandling.None;
bool superdat = false, shouldbreak = false; bool superdat = false, shouldbreak = false;
@@ -667,15 +667,15 @@ VALUES ('" + tempname.Replace("'", "''") + "', '" +
System = filename, System = filename,
}; };
if (roms.ContainsKey(key)) if (dict.ContainsKey(key))
{ {
roms[key].Add(value); dict[key].Add(value);
} }
else else
{ {
List<RomData> newvalue = new List<RomData>(); List<RomData> newvalue = new List<RomData>();
newvalue.Add(value); newvalue.Add(value);
roms.Add(key, newvalue); dict.Add(key, newvalue);
} }
break; break;
} }
@@ -701,7 +701,7 @@ VALUES ('" + tempname.Replace("'", "''") + "', '" +
} }
} }
return roms; return true;
} }
/// <summary> /// <summary>