mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
More changes using DatData objects
This commit is contained in:
@@ -99,11 +99,23 @@ namespace SabreTools
|
||||
|
||||
// Create a dictionary of all ROMs from the input DATs
|
||||
int i = 0;
|
||||
Dictionary<string, List<RomData>> dict = new Dictionary<string, List<RomData>>();
|
||||
DatData userData = new DatData
|
||||
{
|
||||
Name = _name,
|
||||
Description = _desc,
|
||||
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<string, List<RomData>>(),
|
||||
};
|
||||
foreach (string input in _inputs)
|
||||
{
|
||||
_logger.User("Adding DAT: " + input);
|
||||
dict = RomManipulation.ParseDict(input, i, 0, dict, _logger);
|
||||
userData = RomManipulation.ParseDict(input, i, 0, userData, _logger);
|
||||
i++;
|
||||
}
|
||||
|
||||
@@ -113,33 +125,6 @@ namespace SabreTools
|
||||
string post = "";
|
||||
|
||||
// Get all entries that don't have External dupes
|
||||
Dictionary<string, List<RomData>> diffed = new Dictionary<string, List<RomData>>();
|
||||
foreach (string key in dict.Keys)
|
||||
{
|
||||
List<RomData> temp = dict[key];
|
||||
temp = RomManipulation.Merge(temp);
|
||||
|
||||
foreach (RomData rom in temp)
|
||||
{
|
||||
if (rom.Dupe < DupeType.ExternalHash)
|
||||
{
|
||||
if (diffed.ContainsKey(key))
|
||||
{
|
||||
diffed[key].Add(rom);
|
||||
}
|
||||
else
|
||||
{
|
||||
List<RomData> tl = new List<RomData>();
|
||||
tl.Add(rom);
|
||||
diffed.Add(key, tl);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
post = " (No Duplicates)";
|
||||
|
||||
// Output the difflist (a-b)+(b-a) diff
|
||||
DatData outerDiffData = new DatData
|
||||
{
|
||||
Name = _name + post,
|
||||
@@ -150,36 +135,41 @@ namespace SabreTools
|
||||
Author = _author,
|
||||
ForcePacking = (_forceunpack ? ForcePacking.Unzip : ForcePacking.None),
|
||||
OutputFormat = (_old ? OutputFormat.ClrMamePro : OutputFormat.Xml),
|
||||
MergeRoms = _dedup,
|
||||
Roms = new Dictionary<string, List<RomData>>(),
|
||||
};
|
||||
Output.WriteToDatFromDict(outerDiffData, _dedup, "", diffed, _logger);
|
||||
foreach (string key in userData.Roms.Keys)
|
||||
{
|
||||
List<RomData> temp = userData.Roms[key];
|
||||
temp = RomManipulation.Merge(temp);
|
||||
|
||||
foreach (RomData rom in temp)
|
||||
{
|
||||
if (rom.Dupe < DupeType.ExternalHash)
|
||||
{
|
||||
if (outerDiffData.Roms.ContainsKey(key))
|
||||
{
|
||||
outerDiffData.Roms[key].Add(rom);
|
||||
}
|
||||
else
|
||||
{
|
||||
List<RomData> tl = new List<RomData>();
|
||||
tl.Add(rom);
|
||||
outerDiffData.Roms.Add(key, tl);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
post = " (No Duplicates)";
|
||||
|
||||
// Output the difflist (a-b)+(b-a) diff
|
||||
Output.WriteToDatFromDict(outerDiffData, "", _logger);
|
||||
|
||||
// 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"
|
||||
for (int j = 0; j < _inputs.Count; j++)
|
||||
{
|
||||
Dictionary<string, List<RomData>> sysDict = new Dictionary<string, List<RomData>>();
|
||||
foreach (string key in diffed.Keys)
|
||||
{
|
||||
foreach (RomData rom in diffed[key])
|
||||
{
|
||||
if (rom.SystemID == j)
|
||||
{
|
||||
if (sysDict.ContainsKey(key))
|
||||
{
|
||||
sysDict[key].Add(rom);
|
||||
}
|
||||
else
|
||||
{
|
||||
List<RomData> tl = new List<RomData>();
|
||||
tl.Add(rom);
|
||||
sysDict.Add(key, tl);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
post = " (" + Path.GetFileNameWithoutExtension(_inputs[j]) + " Only)";
|
||||
|
||||
DatData diffData = new DatData
|
||||
{
|
||||
Name = _name + post,
|
||||
@@ -190,36 +180,35 @@ namespace SabreTools
|
||||
Author = _author,
|
||||
ForcePacking = (_forceunpack ? ForcePacking.Unzip : ForcePacking.None),
|
||||
OutputFormat = (_old ? OutputFormat.ClrMamePro : OutputFormat.Xml),
|
||||
MergeRoms = _dedup,
|
||||
Roms = new Dictionary<string, List<RomData>>(),
|
||||
};
|
||||
Output.WriteToDatFromDict(diffData, _dedup, "", sysDict, _logger);
|
||||
}
|
||||
|
||||
// Get all entries that have External dupes
|
||||
Dictionary<string, List<RomData>> duplicates = new Dictionary<string, List<RomData>>();
|
||||
post = " (Duplicates)";
|
||||
foreach (string key in dict.Keys)
|
||||
{
|
||||
List<RomData> temp = dict[key];
|
||||
temp = RomManipulation.Merge(temp);
|
||||
|
||||
foreach (RomData rom in temp)
|
||||
foreach (string key in outerDiffData.Roms.Keys)
|
||||
{
|
||||
if (rom.Dupe >= DupeType.ExternalHash)
|
||||
foreach (RomData rom in outerDiffData.Roms[key])
|
||||
{
|
||||
if (duplicates.ContainsKey(key))
|
||||
if (rom.SystemID == j)
|
||||
{
|
||||
duplicates[key].Add(rom);
|
||||
}
|
||||
else
|
||||
{
|
||||
List<RomData> tl = new List<RomData>();
|
||||
tl.Add(rom);
|
||||
duplicates.Add(key, tl);
|
||||
if (diffData.Roms.ContainsKey(key))
|
||||
{
|
||||
diffData.Roms[key].Add(rom);
|
||||
}
|
||||
else
|
||||
{
|
||||
List<RomData> tl = new List<RomData>();
|
||||
tl.Add(rom);
|
||||
diffData.Roms.Add(key, tl);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
post = " (" + Path.GetFileNameWithoutExtension(_inputs[j]) + " Only)";
|
||||
Output.WriteToDatFromDict(diffData, "", _logger);
|
||||
}
|
||||
|
||||
// Get all entries that have External dupes
|
||||
DatData dupeData = new DatData
|
||||
{
|
||||
Name = _name + post,
|
||||
@@ -230,24 +219,39 @@ namespace SabreTools
|
||||
Author = _author,
|
||||
ForcePacking = (_forceunpack ? ForcePacking.Unzip : ForcePacking.None),
|
||||
OutputFormat = (_old ? OutputFormat.ClrMamePro : OutputFormat.Xml),
|
||||
MergeRoms = _dedup,
|
||||
Roms = new Dictionary<string, List<RomData>>(),
|
||||
};
|
||||
Output.WriteToDatFromDict(dupeData, _dedup, "", duplicates, _logger);
|
||||
post = " (Duplicates)";
|
||||
foreach (string key in userData.Roms.Keys)
|
||||
{
|
||||
List<RomData> temp = userData.Roms[key];
|
||||
temp = RomManipulation.Merge(temp);
|
||||
|
||||
foreach (RomData rom in temp)
|
||||
{
|
||||
if (rom.Dupe >= DupeType.ExternalHash)
|
||||
{
|
||||
if (dupeData.Roms.ContainsKey(key))
|
||||
{
|
||||
dupeData.Roms[key].Add(rom);
|
||||
}
|
||||
else
|
||||
{
|
||||
List<RomData> tl = new List<RomData>();
|
||||
tl.Add(rom);
|
||||
dupeData.Roms.Add(key, tl);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Output.WriteToDatFromDict(dupeData, "", _logger);
|
||||
}
|
||||
// Output all entries with user-defined merge
|
||||
else
|
||||
{
|
||||
DatData userData = new DatData
|
||||
{
|
||||
Name = _name,
|
||||
Description = _desc,
|
||||
Version = _version,
|
||||
Date = _date,
|
||||
Category = _cat,
|
||||
Author = _author,
|
||||
ForcePacking = (_forceunpack ? ForcePacking.Unzip : ForcePacking.None),
|
||||
OutputFormat = (_old ? OutputFormat.ClrMamePro : OutputFormat.Xml),
|
||||
};
|
||||
Output.WriteToDatFromDict(userData, _dedup, "", dict, _logger);
|
||||
Output.WriteToDatFromDict(userData, "", _logger);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -144,9 +144,23 @@ namespace SabreTools
|
||||
}
|
||||
}
|
||||
|
||||
// Create the output DatData object
|
||||
DatData datdata = new DatData
|
||||
{
|
||||
Name = name,
|
||||
Description = description,
|
||||
Version = "",
|
||||
Date = date,
|
||||
Category = "SabreTools",
|
||||
Author = "SabreTools",
|
||||
ForcePacking = ForcePacking.None,
|
||||
OutputFormat = (_old ? OutputFormat.ClrMamePro : OutputFormat.Xml),
|
||||
MergeRoms = true,
|
||||
Roms = new Dictionary<string, List<RomData>>(),
|
||||
};
|
||||
|
||||
// Now read in all of the files
|
||||
SHA1 sha1 = SHA1.Create();
|
||||
Dictionary<string, List<RomData>> roms = new Dictionary<string, List<RomData>>();
|
||||
foreach (string file in Directory.GetFiles(path, "*", SearchOption.AllDirectories))
|
||||
{
|
||||
string hash = "";
|
||||
@@ -160,11 +174,11 @@ namespace SabreTools
|
||||
{
|
||||
Int32.TryParse(sourcemap[hash], out tempSrcId);
|
||||
}
|
||||
roms = RomManipulation.ParseDict(file, 0, tempSrcId, roms, _logger);
|
||||
datdata = RomManipulation.ParseDict(file, 0, tempSrcId, datdata, _logger);
|
||||
}
|
||||
|
||||
// If the dictionary is empty for any reason, tell the user and exit
|
||||
if (roms.Keys.Count == 0 || roms.Count == 0)
|
||||
if (datdata.Roms.Keys.Count == 0 || datdata.Roms.Count == 0)
|
||||
{
|
||||
_logger.Log("No roms found for system ID " + _systemid);
|
||||
return false;
|
||||
@@ -172,11 +186,11 @@ namespace SabreTools
|
||||
|
||||
// Now process all of the roms
|
||||
_logger.User("Cleaning rom data");
|
||||
List<string> keys = roms.Keys.ToList();
|
||||
List<string> keys = datdata.Roms.Keys.ToList();
|
||||
foreach (string key in keys)
|
||||
{
|
||||
List<RomData> temp = new List<RomData>();
|
||||
List<RomData> newroms = roms[key];
|
||||
List<RomData> newroms = datdata.Roms[key];
|
||||
for (int i = 0; i < newroms.Count; i++)
|
||||
{
|
||||
RomData rom = newroms[i];
|
||||
@@ -221,22 +235,11 @@ namespace SabreTools
|
||||
|
||||
temp.Add(rom);
|
||||
}
|
||||
roms[key] = temp;
|
||||
datdata.Roms[key] = temp;
|
||||
}
|
||||
|
||||
// Then write out the file
|
||||
DatData datdata = new DatData
|
||||
{
|
||||
Name = name,
|
||||
Description = description,
|
||||
Version = "",
|
||||
Date = date,
|
||||
Category = "SabreTools",
|
||||
Author = "SabreTools",
|
||||
ForcePacking = ForcePacking.None,
|
||||
OutputFormat = (_old ? OutputFormat.ClrMamePro : OutputFormat.Xml),
|
||||
};
|
||||
Output.WriteToDatFromDict(datdata, true, _outroot, roms, _logger, _norename);
|
||||
Output.WriteToDatFromDict(datdata, _outroot, _logger, _norename);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -392,6 +392,8 @@ namespace SabreTools
|
||||
Author = "SabreTools",
|
||||
ForcePacking = ForcePacking.None,
|
||||
OutputFormat = OutputFormat.Xml,
|
||||
MergeRoms = true,
|
||||
Roms = netNew,
|
||||
};
|
||||
DatData unneededData = new DatData
|
||||
{
|
||||
@@ -403,6 +405,8 @@ namespace SabreTools
|
||||
Author = "SabreTools",
|
||||
ForcePacking = ForcePacking.None,
|
||||
OutputFormat = OutputFormat.Xml,
|
||||
MergeRoms = true,
|
||||
Roms = unneeded,
|
||||
};
|
||||
DatData newMissingData = new DatData
|
||||
{
|
||||
@@ -414,6 +418,8 @@ namespace SabreTools
|
||||
Author = "SabreTools",
|
||||
ForcePacking = ForcePacking.None,
|
||||
OutputFormat = OutputFormat.Xml,
|
||||
MergeRoms = true,
|
||||
Roms = newMissing,
|
||||
};
|
||||
DatData haveData = new DatData
|
||||
{
|
||||
@@ -425,12 +431,14 @@ namespace SabreTools
|
||||
Author = "SabreTools",
|
||||
ForcePacking = ForcePacking.None,
|
||||
OutputFormat = OutputFormat.Xml,
|
||||
MergeRoms = true,
|
||||
Roms = have,
|
||||
};
|
||||
|
||||
Output.WriteToDatFromDict(netNewData, true, "", netNew, _logger);
|
||||
Output.WriteToDatFromDict(unneededData, true, "", unneeded, _logger);
|
||||
Output.WriteToDatFromDict(newMissingData, true, "", newMissing, _logger);
|
||||
Output.WriteToDatFromDict(haveData, true, "", have, _logger);
|
||||
Output.WriteToDatFromDict(netNewData, "", _logger);
|
||||
Output.WriteToDatFromDict(unneededData, "", _logger);
|
||||
Output.WriteToDatFromDict(newMissingData, "", _logger);
|
||||
Output.WriteToDatFromDict(haveData, "", _logger);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -497,8 +505,10 @@ namespace SabreTools
|
||||
Author = "SabreTools",
|
||||
ForcePacking = ForcePacking.None,
|
||||
OutputFormat = OutputFormat.Xml,
|
||||
MergeRoms = true,
|
||||
Roms = have,
|
||||
};
|
||||
Output.WriteToDatFromDict(haveData, true, "", have, _logger);
|
||||
Output.WriteToDatFromDict(haveData, "", _logger);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -565,8 +575,10 @@ namespace SabreTools
|
||||
Author = "SabreTools",
|
||||
ForcePacking = ForcePacking.None,
|
||||
OutputFormat = OutputFormat.Xml,
|
||||
MergeRoms = true,
|
||||
Roms = have,
|
||||
};
|
||||
Output.WriteToDatFromDict(haveData, true, "", have, _logger);
|
||||
Output.WriteToDatFromDict(haveData, "", _logger);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -142,9 +142,7 @@ namespace SabreTools.Helper
|
||||
/// Create and open an output file for writing direct from a dictionary
|
||||
/// </summary>
|
||||
/// <param name="datdata">All information for creating the datfile header</param>
|
||||
/// <param name="merge">Enable output in merged mode (one game per hash)</param>
|
||||
/// <param name="outDir">Set the output directory</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="norename">True if games should only be compared on game and file name (default), false if system and source are counted</param>
|
||||
/// <returns>True if the DAT was written correctly, false otherwise</returns>
|
||||
@@ -153,15 +151,15 @@ namespace SabreTools.Helper
|
||||
/// - Have the ability to strip special (non-ASCII) characters from rom information
|
||||
/// - Add a flag for ignoring roms with blank sizes
|
||||
/// </remarks>
|
||||
public static bool WriteToDatFromDict(DatData datdata, bool merge, string outDir, Dictionary<string, List<RomData>> dict, Logger logger, bool norename = true)
|
||||
public static bool WriteToDatFromDict(DatData datdata, string outDir, Logger logger, bool norename = true)
|
||||
{
|
||||
// Get all values in the dictionary and write out
|
||||
SortedDictionary<string, List<RomData>> sortable = new SortedDictionary<string, List<RomData>>();
|
||||
long count = 0;
|
||||
foreach (List<RomData> roms in dict.Values)
|
||||
foreach (List<RomData> roms in datdata.Roms.Values)
|
||||
{
|
||||
List<RomData> newroms = roms;
|
||||
if (merge)
|
||||
if (datdata.MergeRoms)
|
||||
{
|
||||
newroms = RomManipulation.Merge(newroms);
|
||||
}
|
||||
|
||||
@@ -365,6 +365,22 @@ namespace SabreTools.Helper
|
||||
return roms;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a DAT and return all found games and roms within
|
||||
/// </summary>
|
||||
/// <param name="filename">Name of the file to be parsed</param>
|
||||
/// <param name="sysid">System ID for the DAT</param>
|
||||
/// <param name="srcid">Source ID for the DAT</param>
|
||||
/// <param name="datdata">The DatData object representing found roms to this point</param>
|
||||
/// <param name="logger">Logger object for console and/or file output</param>
|
||||
/// <returns>DatData object representing the read-in data</returns>
|
||||
public static DatData ParseDict(string filename, int sysid, int srcid, DatData datdata, Logger logger)
|
||||
{
|
||||
Dictionary<string, List<RomData>> roms = ParseDict(filename, sysid, srcid, datdata.Roms, logger);
|
||||
datdata.Roms = roms;
|
||||
return datdata;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a DAT and return all found games and roms within
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user