[RomManipution] Add logging support to Merge

This commit is contained in:
Matt Nadareski
2016-05-29 00:57:17 -07:00
parent 6a37ab53e0
commit f9cc461100
5 changed files with 27 additions and 30 deletions

View File

@@ -284,7 +284,7 @@ JOIN checksums
{
foreach (string key in roms.Keys)
{
roms[key] = RomManipulation.Merge(roms[key]);
roms[key] = RomManipulation.Merge(roms[key], _logger);
}
}
// END COMMENT

View File

@@ -378,7 +378,7 @@ namespace SabreTools
List<RomData> newroms = roms;
if (datdata.MergeRoms)
{
newroms = RomManipulation.Merge(newroms);
newroms = RomManipulation.Merge(newroms, _logger);
}
foreach (RomData rom in newroms)

View File

@@ -193,7 +193,7 @@ namespace SabreTools
foreach (string key in userData.Roms.Keys)
{
List<RomData> temp = userData.Roms[key];
temp = RomManipulation.Merge(temp);
temp = RomManipulation.Merge(temp, _logger);
foreach (RomData rom in temp)
{
@@ -281,7 +281,7 @@ namespace SabreTools
foreach (string key in userData.Roms.Keys)
{
List<RomData> temp = userData.Roms[key];
temp = RomManipulation.Merge(temp);
temp = RomManipulation.Merge(temp, _logger);
foreach (RomData rom in temp)
{
@@ -342,7 +342,7 @@ namespace SabreTools
List<string> keys = userData.Roms.Keys.ToList();
foreach (string key in keys)
{
List<RomData> oldroms = RomManipulation.Merge(userData.Roms[key]);
List<RomData> oldroms = RomManipulation.Merge(userData.Roms[key], _logger);
List<RomData> newroms = new List<RomData>();
foreach (RomData rom in oldroms)

View File

@@ -153,7 +153,7 @@ namespace SabreTools
Dictionary<string, List<RomData>> netNew = new Dictionary<string, List<RomData>>();
foreach (string key in completeDats.Roms.Keys)
{
List<RomData> templist = RomManipulation.Merge(completeDats.Roms[key]);
List<RomData> templist = RomManipulation.Merge(completeDats.Roms[key], _logger);
foreach (RomData rom in templist)
{
if (rom.Dupe == DupeType.None && rom.System == _currentNewMerged)
@@ -177,7 +177,7 @@ namespace SabreTools
Dictionary<string, List<RomData>> unneeded = new Dictionary<string, List<RomData>>();
foreach (string key in completeDats.Roms.Keys)
{
List<RomData> templist = RomManipulation.Merge(completeDats.Roms[key]);
List<RomData> templist = RomManipulation.Merge(completeDats.Roms[key], _logger);
foreach (RomData rom in templist)
{
if (rom.Dupe == DupeType.None && rom.System == _currentAllMerged)
@@ -214,7 +214,7 @@ namespace SabreTools
Dictionary<string, List<RomData>> newMissing = new Dictionary<string, List<RomData>>();
foreach (string key in midMissing.Roms.Keys)
{
List<RomData> templist = RomManipulation.Merge(midMissing.Roms[key]);
List<RomData> templist = RomManipulation.Merge(midMissing.Roms[key], _logger);
foreach (RomData rom in templist)
{
if (rom.Dupe == DupeType.None && rom.System == _currentMissingMerged)
@@ -286,7 +286,7 @@ namespace SabreTools
Dictionary<string, List<RomData>> have = new Dictionary<string, List<RomData>>();
foreach (string key in midHave.Keys)
{
List<RomData> templist = RomManipulation.Merge(midHave[key]);
List<RomData> templist = RomManipulation.Merge(midHave[key], _logger);
foreach (RomData rom in templist)
{
if (rom.Dupe == DupeType.None && rom.System == _currentNewMerged)
@@ -454,7 +454,7 @@ namespace SabreTools
Dictionary<string, List<RomData>> have = new Dictionary<string, List<RomData>>();
foreach (string key in midHave.Roms.Keys)
{
List<RomData> templist = RomManipulation.Merge(midHave.Roms[key]);
List<RomData> templist = RomManipulation.Merge(midHave.Roms[key], _logger);
foreach (RomData rom in templist)
{
if (rom.Dupe == DupeType.None && rom.System == _currentAllMerged)
@@ -524,7 +524,7 @@ namespace SabreTools
Dictionary<string, List<RomData>> have = new Dictionary<string, List<RomData>>();
foreach (string key in midHave.Roms.Keys)
{
List<RomData> templist = RomManipulation.Merge(midHave.Roms[key]);
List<RomData> templist = RomManipulation.Merge(midHave.Roms[key], _logger);
foreach (RomData rom in templist)
{
if (rom.Dupe == DupeType.None && rom.System == _currentNewMerged)

View File

@@ -59,7 +59,6 @@ namespace SabreTools.Helper
}
XmlTextReader xtr;
StringReader sr;
xtr = new XmlTextReader(filename);
xtr.WhitespaceHandling = WhitespaceHandling.None;
xtr.DtdProcessing = DtdProcessing.Ignore;
@@ -395,7 +394,6 @@ namespace SabreTools.Helper
StreamReader sr = new StreamReader(File.OpenRead(filename));
string blocktype = "";
string lastgame = null;
while (!sr.EndOfStream)
{
string line = sr.ReadLine();
@@ -1263,32 +1261,29 @@ namespace SabreTools.Helper
/// Merge an arbitrary set of ROMs based on the supplied information
/// </summary>
/// <param name="inroms">List of RomData objects representing the roms to be merged</param>
/// <param name="presorted">True if the list should be considered pre-sorted (default false)</param>
/// <param name="logger">Logger object for console and/or file output</param>
/// <returns>A List of RomData objects representing the merged roms</returns>
public static List<RomData> Merge(List<RomData> inroms, bool presorted = false)
public static List<RomData> Merge(List<RomData> inroms, Logger logger)
{
List<RomData> outroms = new List<RomData>();
// First sort the roms by size, crc, md5, sha1 (in order), if not sorted already
if (!presorted)
// First sort the roms by size, crc, md5, sha1 (in order)
inroms.Sort(delegate (RomData x, RomData y)
{
inroms.Sort(delegate (RomData x, RomData y)
if (x.Size == y.Size)
{
if (x.Size == y.Size)
if (x.CRC == y.CRC)
{
if (x.CRC == y.CRC)
if (x.MD5 == y.MD5)
{
if (x.MD5 == y.MD5)
{
return String.Compare(x.SHA1, y.SHA1);
}
return String.Compare(x.MD5, y.MD5);
return String.Compare(x.SHA1, y.SHA1);
}
return String.Compare(x.CRC, y.CRC);
return String.Compare(x.MD5, y.MD5);
}
return (int)(x.Size - y.Size);
});
}
return String.Compare(x.CRC, y.CRC);
}
return (int)(x.Size - y.Size);
});
// Then, deduplicate them by checking to see if data matches
foreach (RomData rom in inroms)
@@ -1335,6 +1330,8 @@ namespace SabreTools.Helper
// If it's a duplicate, skip adding it to the output but add any missing information
if (dupefound)
{
logger.Log("Rom information of found duplicate: " + rom.Game + "\t" + rom.Name + "\t" + rom.Size + "\t" + rom.CRC + "\t" + rom.MD5 + "\t" + rom.SHA1);
savedrom = lastrom;
pos = i;
@@ -1456,7 +1453,7 @@ namespace SabreTools.Helper
List<RomData> newroms = roms;
if (mergeroms)
{
newroms = RomManipulation.Merge(newroms);
newroms = RomManipulation.Merge(newroms, logger);
}
foreach (RomData rom in newroms)