mirror of
https://github.com/SabreTools/SabreTools.Serialization.git
synced 2026-09-22 14:55:11 +00:00
Move hash-based equality checkers lower down the chain
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -64,6 +64,90 @@ namespace SabreTools.Data.Extensions
|
||||
|
||||
#endregion
|
||||
|
||||
#region Equality Checking
|
||||
|
||||
/// <summary>
|
||||
/// Check equality of two Disk objects
|
||||
/// </summary>
|
||||
public static bool PartialEquals(this Disk self, Disk other)
|
||||
{
|
||||
ItemStatus? selfStatus = self.Status;
|
||||
ItemStatus? otherStatus = other.Status;
|
||||
|
||||
string? selfName = self.Name;
|
||||
string? otherName = other.Name;
|
||||
|
||||
// If all hashes are empty but they're both nodump and the names match, then they're dupes
|
||||
if (selfStatus == ItemStatus.Nodump
|
||||
&& otherStatus == ItemStatus.Nodump
|
||||
&& string.Equals(selfName, otherName, StringComparison.OrdinalIgnoreCase)
|
||||
&& !self.HasHashes()
|
||||
&& !other.HasHashes())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// If we get a partial match
|
||||
if (self.HashMatch(other))
|
||||
return true;
|
||||
|
||||
// All other cases fail
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check equality of two Media objects
|
||||
/// </summary>
|
||||
public static bool PartialEquals(this Media self, Media other)
|
||||
{
|
||||
// If we get a partial match
|
||||
if (self.HashMatch(other))
|
||||
return true;
|
||||
|
||||
// All other cases fail
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check equality of two Rom objects
|
||||
/// </summary>
|
||||
public static bool PartialEquals(this Rom self, Rom other)
|
||||
{
|
||||
ItemStatus? selfStatus = self.Status;
|
||||
ItemStatus? otherStatus = other.Status;
|
||||
|
||||
string? selfName = self.Name;
|
||||
string? otherName = other.Name;
|
||||
|
||||
long? selfSize = self.Size;
|
||||
long? otherSize = other.Size;
|
||||
|
||||
// If all hashes are empty but they're both nodump and the names match, then they're dupes
|
||||
if (selfStatus == ItemStatus.Nodump
|
||||
&& otherStatus == ItemStatus.Nodump
|
||||
&& string.Equals(selfName, otherName, StringComparison.OrdinalIgnoreCase)
|
||||
&& !self.HasHashes()
|
||||
&& !other.HasHashes())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// If we have a file that has no known size, rely on the hashes only
|
||||
if (selfSize is null && self.HashMatch(other))
|
||||
return true;
|
||||
else if (otherSize is null && self.HashMatch(other))
|
||||
return true;
|
||||
|
||||
// If we get a partial match
|
||||
if (selfSize == otherSize && self.HashMatch(other))
|
||||
return true;
|
||||
|
||||
// All other cases fail
|
||||
return false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Hash Checking
|
||||
|
||||
/// <summary>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,93 +0,0 @@
|
||||
using System;
|
||||
using SabreTools.Data.Extensions;
|
||||
using SabreTools.Data.Models.Metadata;
|
||||
|
||||
namespace SabreTools.Metadata
|
||||
{
|
||||
public static class DictionaryBaseExtensions
|
||||
{
|
||||
#region Equality Checking
|
||||
|
||||
/// <summary>
|
||||
/// Check equality of two Disk objects
|
||||
/// </summary>
|
||||
public static bool PartialEquals(this Disk self, Disk other)
|
||||
{
|
||||
ItemStatus? selfStatus = self.Status;
|
||||
ItemStatus? otherStatus = other.Status;
|
||||
|
||||
string? selfName = self.Name;
|
||||
string? otherName = other.Name;
|
||||
|
||||
// If all hashes are empty but they're both nodump and the names match, then they're dupes
|
||||
if (selfStatus == ItemStatus.Nodump
|
||||
&& otherStatus == ItemStatus.Nodump
|
||||
&& string.Equals(selfName, otherName, StringComparison.OrdinalIgnoreCase)
|
||||
&& !self.HasHashes()
|
||||
&& !other.HasHashes())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// If we get a partial match
|
||||
if (self.HashMatch(other))
|
||||
return true;
|
||||
|
||||
// All other cases fail
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check equality of two Media objects
|
||||
/// </summary>
|
||||
public static bool PartialEquals(this Media self, Media other)
|
||||
{
|
||||
// If we get a partial match
|
||||
if (self.HashMatch(other))
|
||||
return true;
|
||||
|
||||
// All other cases fail
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check equality of two Rom objects
|
||||
/// </summary>
|
||||
public static bool PartialEquals(this Rom self, Rom other)
|
||||
{
|
||||
ItemStatus? selfStatus = self.Status;
|
||||
ItemStatus? otherStatus = other.Status;
|
||||
|
||||
string? selfName = self.Name;
|
||||
string? otherName = other.Name;
|
||||
|
||||
long? selfSize = self.Size;
|
||||
long? otherSize = other.Size;
|
||||
|
||||
// If all hashes are empty but they're both nodump and the names match, then they're dupes
|
||||
if (selfStatus == ItemStatus.Nodump
|
||||
&& otherStatus == ItemStatus.Nodump
|
||||
&& string.Equals(selfName, otherName, StringComparison.OrdinalIgnoreCase)
|
||||
&& !self.HasHashes()
|
||||
&& !other.HasHashes())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// If we have a file that has no known size, rely on the hashes only
|
||||
if (selfSize is null && self.HashMatch(other))
|
||||
return true;
|
||||
else if (otherSize is null && self.HashMatch(other))
|
||||
return true;
|
||||
|
||||
// If we get a partial match
|
||||
if (selfSize == otherSize && self.HashMatch(other))
|
||||
return true;
|
||||
|
||||
// All other cases fail
|
||||
return false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user