mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[RomManipution] Add logging support to Merge
This commit is contained in:
@@ -284,7 +284,7 @@ JOIN checksums
|
|||||||
{
|
{
|
||||||
foreach (string key in roms.Keys)
|
foreach (string key in roms.Keys)
|
||||||
{
|
{
|
||||||
roms[key] = RomManipulation.Merge(roms[key]);
|
roms[key] = RomManipulation.Merge(roms[key], _logger);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// END COMMENT
|
// END COMMENT
|
||||||
|
|||||||
@@ -378,7 +378,7 @@ namespace SabreTools
|
|||||||
List<RomData> newroms = roms;
|
List<RomData> newroms = roms;
|
||||||
if (datdata.MergeRoms)
|
if (datdata.MergeRoms)
|
||||||
{
|
{
|
||||||
newroms = RomManipulation.Merge(newroms);
|
newroms = RomManipulation.Merge(newroms, _logger);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (RomData rom in newroms)
|
foreach (RomData rom in newroms)
|
||||||
|
|||||||
@@ -193,7 +193,7 @@ namespace SabreTools
|
|||||||
foreach (string key in userData.Roms.Keys)
|
foreach (string key in userData.Roms.Keys)
|
||||||
{
|
{
|
||||||
List<RomData> temp = userData.Roms[key];
|
List<RomData> temp = userData.Roms[key];
|
||||||
temp = RomManipulation.Merge(temp);
|
temp = RomManipulation.Merge(temp, _logger);
|
||||||
|
|
||||||
foreach (RomData rom in temp)
|
foreach (RomData rom in temp)
|
||||||
{
|
{
|
||||||
@@ -281,7 +281,7 @@ namespace SabreTools
|
|||||||
foreach (string key in userData.Roms.Keys)
|
foreach (string key in userData.Roms.Keys)
|
||||||
{
|
{
|
||||||
List<RomData> temp = userData.Roms[key];
|
List<RomData> temp = userData.Roms[key];
|
||||||
temp = RomManipulation.Merge(temp);
|
temp = RomManipulation.Merge(temp, _logger);
|
||||||
|
|
||||||
foreach (RomData rom in temp)
|
foreach (RomData rom in temp)
|
||||||
{
|
{
|
||||||
@@ -342,7 +342,7 @@ namespace SabreTools
|
|||||||
List<string> keys = userData.Roms.Keys.ToList();
|
List<string> keys = userData.Roms.Keys.ToList();
|
||||||
foreach (string key in keys)
|
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>();
|
List<RomData> newroms = new List<RomData>();
|
||||||
|
|
||||||
foreach (RomData rom in oldroms)
|
foreach (RomData rom in oldroms)
|
||||||
|
|||||||
@@ -153,7 +153,7 @@ namespace SabreTools
|
|||||||
Dictionary<string, List<RomData>> netNew = new Dictionary<string, List<RomData>>();
|
Dictionary<string, List<RomData>> netNew = new Dictionary<string, List<RomData>>();
|
||||||
foreach (string key in completeDats.Roms.Keys)
|
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)
|
foreach (RomData rom in templist)
|
||||||
{
|
{
|
||||||
if (rom.Dupe == DupeType.None && rom.System == _currentNewMerged)
|
if (rom.Dupe == DupeType.None && rom.System == _currentNewMerged)
|
||||||
@@ -177,7 +177,7 @@ namespace SabreTools
|
|||||||
Dictionary<string, List<RomData>> unneeded = new Dictionary<string, List<RomData>>();
|
Dictionary<string, List<RomData>> unneeded = new Dictionary<string, List<RomData>>();
|
||||||
foreach (string key in completeDats.Roms.Keys)
|
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)
|
foreach (RomData rom in templist)
|
||||||
{
|
{
|
||||||
if (rom.Dupe == DupeType.None && rom.System == _currentAllMerged)
|
if (rom.Dupe == DupeType.None && rom.System == _currentAllMerged)
|
||||||
@@ -214,7 +214,7 @@ namespace SabreTools
|
|||||||
Dictionary<string, List<RomData>> newMissing = new Dictionary<string, List<RomData>>();
|
Dictionary<string, List<RomData>> newMissing = new Dictionary<string, List<RomData>>();
|
||||||
foreach (string key in midMissing.Roms.Keys)
|
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)
|
foreach (RomData rom in templist)
|
||||||
{
|
{
|
||||||
if (rom.Dupe == DupeType.None && rom.System == _currentMissingMerged)
|
if (rom.Dupe == DupeType.None && rom.System == _currentMissingMerged)
|
||||||
@@ -286,7 +286,7 @@ namespace SabreTools
|
|||||||
Dictionary<string, List<RomData>> have = new Dictionary<string, List<RomData>>();
|
Dictionary<string, List<RomData>> have = new Dictionary<string, List<RomData>>();
|
||||||
foreach (string key in midHave.Keys)
|
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)
|
foreach (RomData rom in templist)
|
||||||
{
|
{
|
||||||
if (rom.Dupe == DupeType.None && rom.System == _currentNewMerged)
|
if (rom.Dupe == DupeType.None && rom.System == _currentNewMerged)
|
||||||
@@ -454,7 +454,7 @@ namespace SabreTools
|
|||||||
Dictionary<string, List<RomData>> have = new Dictionary<string, List<RomData>>();
|
Dictionary<string, List<RomData>> have = new Dictionary<string, List<RomData>>();
|
||||||
foreach (string key in midHave.Roms.Keys)
|
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)
|
foreach (RomData rom in templist)
|
||||||
{
|
{
|
||||||
if (rom.Dupe == DupeType.None && rom.System == _currentAllMerged)
|
if (rom.Dupe == DupeType.None && rom.System == _currentAllMerged)
|
||||||
@@ -524,7 +524,7 @@ namespace SabreTools
|
|||||||
Dictionary<string, List<RomData>> have = new Dictionary<string, List<RomData>>();
|
Dictionary<string, List<RomData>> have = new Dictionary<string, List<RomData>>();
|
||||||
foreach (string key in midHave.Roms.Keys)
|
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)
|
foreach (RomData rom in templist)
|
||||||
{
|
{
|
||||||
if (rom.Dupe == DupeType.None && rom.System == _currentNewMerged)
|
if (rom.Dupe == DupeType.None && rom.System == _currentNewMerged)
|
||||||
|
|||||||
@@ -59,7 +59,6 @@ namespace SabreTools.Helper
|
|||||||
}
|
}
|
||||||
|
|
||||||
XmlTextReader xtr;
|
XmlTextReader xtr;
|
||||||
StringReader sr;
|
|
||||||
xtr = new XmlTextReader(filename);
|
xtr = new XmlTextReader(filename);
|
||||||
xtr.WhitespaceHandling = WhitespaceHandling.None;
|
xtr.WhitespaceHandling = WhitespaceHandling.None;
|
||||||
xtr.DtdProcessing = DtdProcessing.Ignore;
|
xtr.DtdProcessing = DtdProcessing.Ignore;
|
||||||
@@ -395,7 +394,6 @@ namespace SabreTools.Helper
|
|||||||
StreamReader sr = new StreamReader(File.OpenRead(filename));
|
StreamReader sr = new StreamReader(File.OpenRead(filename));
|
||||||
|
|
||||||
string blocktype = "";
|
string blocktype = "";
|
||||||
string lastgame = null;
|
|
||||||
while (!sr.EndOfStream)
|
while (!sr.EndOfStream)
|
||||||
{
|
{
|
||||||
string line = sr.ReadLine();
|
string line = sr.ReadLine();
|
||||||
@@ -1263,32 +1261,29 @@ namespace SabreTools.Helper
|
|||||||
/// Merge an arbitrary set of ROMs based on the supplied information
|
/// Merge an arbitrary set of ROMs based on the supplied information
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="inroms">List of RomData objects representing the roms to be merged</param>
|
/// <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>
|
/// <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>();
|
List<RomData> outroms = new List<RomData>();
|
||||||
|
|
||||||
// First sort the roms by size, crc, md5, sha1 (in order), if not sorted already
|
// First sort the roms by size, crc, md5, sha1 (in order)
|
||||||
if (!presorted)
|
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.SHA1, y.SHA1);
|
|
||||||
}
|
|
||||||
return String.Compare(x.MD5, y.MD5);
|
|
||||||
}
|
}
|
||||||
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
|
// Then, deduplicate them by checking to see if data matches
|
||||||
foreach (RomData rom in inroms)
|
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 it's a duplicate, skip adding it to the output but add any missing information
|
||||||
if (dupefound)
|
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;
|
savedrom = lastrom;
|
||||||
pos = i;
|
pos = i;
|
||||||
|
|
||||||
@@ -1456,7 +1453,7 @@ namespace SabreTools.Helper
|
|||||||
List<RomData> newroms = roms;
|
List<RomData> newroms = roms;
|
||||||
if (mergeroms)
|
if (mergeroms)
|
||||||
{
|
{
|
||||||
newroms = RomManipulation.Merge(newroms);
|
newroms = RomManipulation.Merge(newroms, logger);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (RomData rom in newroms)
|
foreach (RomData rom in newroms)
|
||||||
|
|||||||
Reference in New Issue
Block a user