[DatFile, Disk, Rom] Better equality checking

This commit is contained in:
Matt Nadareski
2017-11-09 00:20:47 -08:00
parent 3ac2b6c074
commit 130e4255fb
3 changed files with 27 additions and 21 deletions

View File

@@ -1468,19 +1468,8 @@ namespace SabreTools.Library.DatFiles
// If the key is different, move the item to the new key
if (newkey != key)
{
// We have to circumvent the proper process here because of issues with nodumps
// TODO: Properly handle nodumps in key-to-key transfers
if (_items.ContainsKey(newkey))
{
_items[newkey].Add(rom);
}
else
{
_items.Add(newkey, new List<DatItem>() { rom });
}
// Now remove the rom from its original location
roms.RemoveAt(i);
Add(newkey, rom);
Remove(key, rom);
i--; // This make sure that the pointer stays on the correct since one was removed
}
}

View File

@@ -138,14 +138,20 @@ namespace SabreTools.Library.DatItems
// Otherwise, treat it as a rom
Disk newOther = (Disk)other;
// If either is a nodump, it's never a match
if (_itemStatus == ItemStatus.Nodump || newOther.ItemStatus == ItemStatus.Nodump)
// If all hashes are empty but they're both nodump and the names match, then they're dupes
if ((this._itemStatus == ItemStatus.Nodump && newOther._itemStatus == ItemStatus.Nodump)
&& (this._name == newOther._name)
&& (this._md5.IsNullOrWhiteSpace() && newOther._md5.IsNullOrWhiteSpace())
&& (this._sha1.IsNullOrWhiteSpace() && newOther._sha1.IsNullOrWhiteSpace())
&& (this._sha256.IsNullOrWhiteSpace() && newOther._sha256.IsNullOrWhiteSpace())
&& (this._sha384.IsNullOrWhiteSpace() && newOther._sha384.IsNullOrWhiteSpace())
&& (this._sha512.IsNullOrWhiteSpace() && newOther._sha512.IsNullOrWhiteSpace()))
{
return dupefound;
dupefound = true;
}
// If we can determine that the disks have no non-empty hashes in common, we return false
if ((this._md5.IsNullOrWhiteSpace() || newOther._md5.IsNullOrWhiteSpace())
else if ((this._md5.IsNullOrWhiteSpace() || newOther._md5.IsNullOrWhiteSpace())
&& (this._sha1.IsNullOrWhiteSpace() || newOther._sha1.IsNullOrWhiteSpace())
&& (this._sha256.IsNullOrWhiteSpace() || newOther._sha256.IsNullOrWhiteSpace())
&& (this._sha384.IsNullOrWhiteSpace() || newOther._sha384.IsNullOrWhiteSpace())
@@ -153,6 +159,8 @@ namespace SabreTools.Library.DatItems
{
dupefound = false;
}
// Otherwise if we get a partial match
else if (((this._md5.IsNullOrWhiteSpace() || newOther._md5.IsNullOrWhiteSpace()) || Enumerable.SequenceEqual(this._md5, newOther._md5))
&& ((this._sha1.IsNullOrWhiteSpace() || newOther._sha1.IsNullOrWhiteSpace()) || Enumerable.SequenceEqual(this._sha1, newOther._sha1))
&& ((this._sha256.IsNullOrWhiteSpace() || newOther._sha256.IsNullOrWhiteSpace()) || Enumerable.SequenceEqual(this._sha256, newOther._sha256))

View File

@@ -205,14 +205,21 @@ namespace SabreTools.Library.DatItems
// Otherwise, treat it as a rom
Rom newOther = (Rom)other;
// If either is a nodump, it's never a match
if (_itemStatus == ItemStatus.Nodump || newOther.ItemStatus == ItemStatus.Nodump)
// If all hashes are empty but they're both nodump and the names match, then they're dupes
if ((this._itemStatus == ItemStatus.Nodump && newOther._itemStatus == ItemStatus.Nodump)
&& (this._name == newOther._name)
&& (this._crc.IsNullOrWhiteSpace() && newOther._crc.IsNullOrWhiteSpace())
&& (this._md5.IsNullOrWhiteSpace() && newOther._md5.IsNullOrWhiteSpace())
&& (this._sha1.IsNullOrWhiteSpace() && newOther._sha1.IsNullOrWhiteSpace())
&& (this._sha256.IsNullOrWhiteSpace() && newOther._sha256.IsNullOrWhiteSpace())
&& (this._sha384.IsNullOrWhiteSpace() && newOther._sha384.IsNullOrWhiteSpace())
&& (this._sha512.IsNullOrWhiteSpace() && newOther._sha512.IsNullOrWhiteSpace()))
{
return dupefound;
dupefound = true;
}
// If we can determine that the roms have no non-empty hashes in common, we return false
if ((_crc.IsNullOrWhiteSpace() || newOther._crc.IsNullOrWhiteSpace())
else if ((this._crc.IsNullOrWhiteSpace() || newOther._crc.IsNullOrWhiteSpace())
&& (this._md5.IsNullOrWhiteSpace() || newOther._md5.IsNullOrWhiteSpace())
&& (this._sha1.IsNullOrWhiteSpace() || newOther._sha1.IsNullOrWhiteSpace())
&& (this._sha256.IsNullOrWhiteSpace() || newOther._sha256.IsNullOrWhiteSpace())
@@ -221,6 +228,8 @@ namespace SabreTools.Library.DatItems
{
dupefound = false;
}
// Otherwise if we get a partial match
else if ((this.Size == newOther.Size)
&& ((this._crc.IsNullOrWhiteSpace() || newOther._crc.IsNullOrWhiteSpace()) || Enumerable.SequenceEqual(this._crc, newOther._crc))
&& ((this._md5.IsNullOrWhiteSpace() || newOther._md5.IsNullOrWhiteSpace()) || Enumerable.SequenceEqual(this._md5, newOther._md5))