mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Make deduping EVEN MORE accurate
With thanks to Obiwantje and EliUmniCk for testing and helping with the design update.
This commit is contained in:
@@ -437,84 +437,97 @@ namespace SabreTools.Helper
|
|||||||
if (outroms.Count != 0)
|
if (outroms.Count != 0)
|
||||||
{
|
{
|
||||||
// Check if the rom is a duplicate
|
// Check if the rom is a duplicate
|
||||||
RomData last = outroms[outroms.Count - 1];
|
bool dupefound = false;
|
||||||
|
RomData savedrom = new RomData();
|
||||||
bool shouldcont = false;
|
int pos = -1;
|
||||||
if (rom.Type == "rom" && last.Type == "rom")
|
for (int i = 0; i < outroms.Count; i++)
|
||||||
{
|
{
|
||||||
shouldcont = ((rom.Size == last.Size) &&
|
RomData lastrom = outroms[i];
|
||||||
((rom.CRC == "" || last.CRC == "") || rom.CRC == last.CRC) &&
|
|
||||||
((rom.MD5 == "" || last.MD5 == "") || rom.MD5 == last.MD5) &&
|
if (rom.Type == "rom" && lastrom.Type == "rom")
|
||||||
((rom.SHA1 == "" || last.SHA1 == "") || rom.SHA1 == last.SHA1)
|
{
|
||||||
|
dupefound = ((rom.Size == lastrom.Size) &&
|
||||||
|
((rom.CRC == "" || lastrom.CRC == "") || rom.CRC == lastrom.CRC) &&
|
||||||
|
((rom.MD5 == "" || lastrom.MD5 == "") || rom.MD5 == lastrom.MD5) &&
|
||||||
|
((rom.SHA1 == "" || lastrom.SHA1 == "") || rom.SHA1 == lastrom.SHA1)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else if (rom.Type == "disk" && last.Type == "disk")
|
else if (rom.Type == "disk" && lastrom.Type == "disk")
|
||||||
{
|
{
|
||||||
shouldcont = (((rom.MD5 == "" || last.MD5 == "") || rom.MD5 == last.MD5) &&
|
dupefound = (((rom.MD5 == "" || lastrom.MD5 == "") || rom.MD5 == lastrom.MD5) &&
|
||||||
((rom.SHA1 == "" || last.SHA1 == "") || rom.SHA1 == last.SHA1)
|
((rom.SHA1 == "" || lastrom.SHA1 == "") || rom.SHA1 == lastrom.SHA1)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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 (shouldcont)
|
if (dupefound)
|
||||||
{
|
{
|
||||||
last.CRC = (last.CRC == "" && rom.CRC != "" ? rom.CRC : last.CRC);
|
savedrom = lastrom;
|
||||||
last.MD5 = (last.MD5 == "" && rom.MD5 != "" ? rom.MD5 : last.MD5);
|
pos = i;
|
||||||
last.SHA1 = (last.SHA1 == "" && rom.SHA1 != "" ? rom.SHA1 : last.SHA1);
|
|
||||||
|
savedrom.CRC = (savedrom.CRC == "" && rom.CRC != "" ? rom.CRC : savedrom.CRC);
|
||||||
|
savedrom.MD5 = (savedrom.MD5 == "" && rom.MD5 != "" ? rom.MD5 : savedrom.MD5);
|
||||||
|
savedrom.SHA1 = (savedrom.SHA1 == "" && rom.SHA1 != "" ? rom.SHA1 : savedrom.SHA1);
|
||||||
|
|
||||||
// If the duplicate is external already or should be, set it
|
// If the duplicate is external already or should be, set it
|
||||||
if (last.Dupe >= DupeType.ExternalHash || last.SystemID != rom.SystemID || last.SourceID != rom.SourceID)
|
if (savedrom.Dupe >= DupeType.ExternalHash || savedrom.SystemID != rom.SystemID || savedrom.SourceID != rom.SourceID)
|
||||||
{
|
{
|
||||||
if (last.Game == rom.Game && last.Name == rom.Name)
|
if (savedrom.Game == rom.Game && savedrom.Name == rom.Name)
|
||||||
{
|
{
|
||||||
last.Dupe = DupeType.ExternalAll;
|
savedrom.Dupe = DupeType.ExternalAll;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
last.Dupe = DupeType.ExternalHash;
|
savedrom.Dupe = DupeType.ExternalHash;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, it's considered an internal dupe
|
// Otherwise, it's considered an internal dupe
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (last.Game == rom.Game && last.Name == rom.Name)
|
if (savedrom.Game == rom.Game && savedrom.Name == rom.Name)
|
||||||
{
|
{
|
||||||
last.Dupe = DupeType.InternalAll;
|
savedrom.Dupe = DupeType.InternalAll;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
last.Dupe = DupeType.InternalHash;
|
savedrom.Dupe = DupeType.InternalHash;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the current system has a lower ID than the previous, set the system accordingly
|
// If the current system has a lower ID than the previous, set the system accordingly
|
||||||
if (rom.SystemID < last.SystemID)
|
if (rom.SystemID < savedrom.SystemID)
|
||||||
{
|
{
|
||||||
last.SystemID = rom.SystemID;
|
savedrom.SystemID = rom.SystemID;
|
||||||
last.System = rom.System;
|
savedrom.System = rom.System;
|
||||||
last.Game = rom.Game;
|
savedrom.Game = rom.Game;
|
||||||
last.Name = rom.Name;
|
savedrom.Name = rom.Name;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the current source has a lower ID than the previous, set the source accordingly
|
// If the current source has a lower ID than the previous, set the source accordingly
|
||||||
if (rom.SourceID < last.SourceID)
|
if (rom.SourceID < savedrom.SourceID)
|
||||||
{
|
{
|
||||||
last.SourceID = rom.SourceID;
|
savedrom.SourceID = rom.SourceID;
|
||||||
last.Source = rom.Source;
|
savedrom.Source = rom.Source;
|
||||||
last.Game = rom.Game;
|
savedrom.Game = rom.Game;
|
||||||
last.Name = rom.Name;
|
savedrom.Name = rom.Name;
|
||||||
}
|
}
|
||||||
|
|
||||||
outroms.RemoveAt(outroms.Count - 1);
|
break;
|
||||||
outroms.Insert(outroms.Count, last);
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
|
||||||
|
// If no duplicate is found, add it to the list
|
||||||
|
if (!dupefound)
|
||||||
{
|
{
|
||||||
outroms.Add(rom);
|
outroms.Add(rom);
|
||||||
}
|
}
|
||||||
|
// Otherwise, if a new rom information is found, add that
|
||||||
|
else
|
||||||
|
{
|
||||||
|
outroms.RemoveAt(pos);
|
||||||
|
outroms.Insert(pos, savedrom);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user