Reduce generic DictionaryBase use

This commit is contained in:
Matt Nadareski
2026-04-04 13:31:12 -04:00
parent 0458489a4f
commit 4acd2d9fd6
5 changed files with 207 additions and 310 deletions

View File

@@ -8,18 +8,10 @@ namespace SabreTools.Data.Extensions.Test
{
#region ConvertToRom
[Fact]
public void ConvertToRom_Null_Null()
{
DictionaryBase? self = null;
Rom? actual = self.ConvertToRom();
Assert.Null(actual);
}
[Fact]
public void ConvertToRom_EmptyDisk_EmptyRom()
{
DictionaryBase? self = new Disk();
var self = new Disk();
Rom? actual = self.ConvertToRom();
Assert.NotNull(actual);
@@ -37,7 +29,7 @@ namespace SabreTools.Data.Extensions.Test
[Fact]
public void ConvertToRom_FilledDisk_FilledRom()
{
DictionaryBase? self = new Disk
var self = new Disk
{
Name = "name",
Merge = "merge",
@@ -65,7 +57,7 @@ namespace SabreTools.Data.Extensions.Test
[Fact]
public void ConvertToRom_EmptyMedia_EmptyRom()
{
DictionaryBase? self = new Media();
var self = new Media();
Rom? actual = self.ConvertToRom();
Assert.NotNull(actual);
@@ -81,7 +73,7 @@ namespace SabreTools.Data.Extensions.Test
[Fact]
public void ConvertToRom_FilledMedia_FilledRom()
{
DictionaryBase? self = new Media
var self = new Media
{
Name = "name",
MD5 = "md5",
@@ -102,14 +94,6 @@ namespace SabreTools.Data.Extensions.Test
Assert.Equal("spamsum", actual[Rom.SpamSumKey]);
}
[Fact]
public void ConvertToRom_Other_Null()
{
DictionaryBase? self = new Sample();
Rom? actual = self.ConvertToRom();
Assert.Null(actual);
}
#endregion
#region ConditionalHashEquals
@@ -959,7 +943,7 @@ namespace SabreTools.Data.Extensions.Test
[Fact]
public void HasZeroHash_Disk_NoHash_True()
{
DictionaryBase self = new Disk();
var self = new Disk();
bool actual = self.HasZeroHash();
Assert.True(actual);
}
@@ -967,7 +951,7 @@ namespace SabreTools.Data.Extensions.Test
[Fact]
public void HasZeroHash_Disk_NonZeroHash_False()
{
DictionaryBase self = new Disk
var self = new Disk
{
MD5 = "XXXXXX",
SHA1 = "XXXXXX",
@@ -980,7 +964,7 @@ namespace SabreTools.Data.Extensions.Test
[Fact]
public void HasZeroHash_Disk_ZeroMD5_True()
{
DictionaryBase self = new Disk
var self = new Disk
{
MD5 = HashType.MD5.ZeroString,
SHA1 = string.Empty,
@@ -993,7 +977,7 @@ namespace SabreTools.Data.Extensions.Test
[Fact]
public void HasZeroHash_Disk_ZeroSHA1_True()
{
DictionaryBase self = new Disk
var self = new Disk
{
MD5 = string.Empty,
SHA1 = HashType.SHA1.ZeroString,
@@ -1006,7 +990,7 @@ namespace SabreTools.Data.Extensions.Test
[Fact]
public void HasZeroHash_Disk_ZeroAll_True()
{
DictionaryBase self = new Disk
var self = new Disk
{
MD5 = HashType.MD5.ZeroString,
SHA1 = HashType.SHA1.ZeroString,
@@ -1019,7 +1003,7 @@ namespace SabreTools.Data.Extensions.Test
[Fact]
public void HasZeroHash_Media_NoHash_True()
{
DictionaryBase self = new Media();
var self = new Media();
bool actual = self.HasZeroHash();
Assert.True(actual);
}
@@ -1027,7 +1011,7 @@ namespace SabreTools.Data.Extensions.Test
[Fact]
public void HasZeroHash_Media_NonZeroHash_False()
{
DictionaryBase self = new Media
var self = new Media
{
MD5 = "XXXXXX",
SHA1 = "XXXXXX",
@@ -1042,7 +1026,7 @@ namespace SabreTools.Data.Extensions.Test
[Fact]
public void HasZeroHash_Media_ZeroMD5_True()
{
DictionaryBase self = new Media
var self = new Media
{
MD5 = HashType.MD5.ZeroString,
SHA1 = string.Empty,
@@ -1057,7 +1041,7 @@ namespace SabreTools.Data.Extensions.Test
[Fact]
public void HasZeroHash_Media_ZeroSHA1_True()
{
DictionaryBase self = new Media
var self = new Media
{
MD5 = string.Empty,
SHA1 = HashType.SHA1.ZeroString,
@@ -1072,7 +1056,7 @@ namespace SabreTools.Data.Extensions.Test
[Fact]
public void HasZeroHash_Media_ZeroSHA256_True()
{
DictionaryBase self = new Media
var self = new Media
{
MD5 = string.Empty,
SHA1 = string.Empty,
@@ -1087,7 +1071,7 @@ namespace SabreTools.Data.Extensions.Test
[Fact]
public void HasZeroHash_Media_ZeroSpamSum_True()
{
DictionaryBase self = new Media
var self = new Media
{
MD5 = string.Empty,
SHA1 = string.Empty,
@@ -1102,7 +1086,7 @@ namespace SabreTools.Data.Extensions.Test
[Fact]
public void HasZeroHash_Media_ZeroAll_True()
{
DictionaryBase self = new Media
var self = new Media
{
MD5 = HashType.MD5.ZeroString,
SHA1 = HashType.SHA1.ZeroString,
@@ -1117,7 +1101,7 @@ namespace SabreTools.Data.Extensions.Test
[Fact]
public void HasZeroHash_Rom_NoHash_True()
{
DictionaryBase self = new Rom();
var self = new Rom();
bool actual = self.HasZeroHash();
Assert.True(actual);
}
@@ -1125,7 +1109,7 @@ namespace SabreTools.Data.Extensions.Test
[Fact]
public void HasZeroHash_Rom_NonZeroHash_False()
{
DictionaryBase self = new Rom
var self = new Rom
{
[Rom.CRC16Key] = "XXXXXX",
[Rom.CRCKey] = "XXXXXX",
@@ -1149,7 +1133,7 @@ namespace SabreTools.Data.Extensions.Test
[Fact]
public void HasZeroHash_Rom_ZeroCRC16_True()
{
DictionaryBase self = new Rom
var self = new Rom
{
[Rom.CRC16Key] = HashType.CRC16.ZeroString,
[Rom.CRCKey] = string.Empty,
@@ -1173,7 +1157,7 @@ namespace SabreTools.Data.Extensions.Test
[Fact]
public void HasZeroHash_Rom_ZeroCRC_True()
{
DictionaryBase self = new Rom
var self = new Rom
{
[Rom.CRC16Key] = string.Empty,
[Rom.CRCKey] = HashType.CRC32.ZeroString,
@@ -1197,7 +1181,7 @@ namespace SabreTools.Data.Extensions.Test
[Fact]
public void HasZeroHash_Rom_ZeroCRC64_True()
{
DictionaryBase self = new Rom
var self = new Rom
{
[Rom.CRC16Key] = string.Empty,
[Rom.CRCKey] = string.Empty,
@@ -1221,7 +1205,7 @@ namespace SabreTools.Data.Extensions.Test
[Fact]
public void HasZeroHash_Rom_ZeroMD2_True()
{
DictionaryBase self = new Rom
var self = new Rom
{
[Rom.CRC16Key] = string.Empty,
[Rom.CRCKey] = string.Empty,
@@ -1245,7 +1229,7 @@ namespace SabreTools.Data.Extensions.Test
[Fact]
public void HasZeroHash_Rom_ZeroMD4_True()
{
DictionaryBase self = new Rom
var self = new Rom
{
[Rom.CRC16Key] = string.Empty,
[Rom.CRCKey] = string.Empty,
@@ -1269,7 +1253,7 @@ namespace SabreTools.Data.Extensions.Test
[Fact]
public void HasZeroHash_Rom_ZeroMD5_True()
{
DictionaryBase self = new Rom
var self = new Rom
{
[Rom.CRC16Key] = string.Empty,
[Rom.CRCKey] = string.Empty,
@@ -1293,7 +1277,7 @@ namespace SabreTools.Data.Extensions.Test
[Fact]
public void HasZeroHash_Rom_ZeroRIPEMD128_True()
{
DictionaryBase self = new Rom
var self = new Rom
{
[Rom.CRC16Key] = string.Empty,
[Rom.CRCKey] = string.Empty,
@@ -1317,7 +1301,7 @@ namespace SabreTools.Data.Extensions.Test
[Fact]
public void HasZeroHash_Rom_ZeroRIPEMD160_True()
{
DictionaryBase self = new Rom
var self = new Rom
{
[Rom.CRC16Key] = string.Empty,
[Rom.CRCKey] = string.Empty,
@@ -1341,7 +1325,7 @@ namespace SabreTools.Data.Extensions.Test
[Fact]
public void HasZeroHash_Rom_ZeroSHA1_True()
{
DictionaryBase self = new Rom
var self = new Rom
{
[Rom.CRC16Key] = string.Empty,
[Rom.CRCKey] = string.Empty,
@@ -1365,7 +1349,7 @@ namespace SabreTools.Data.Extensions.Test
[Fact]
public void HasZeroHash_Rom_ZeroSHA256_True()
{
DictionaryBase self = new Rom
var self = new Rom
{
[Rom.CRC16Key] = string.Empty,
[Rom.CRCKey] = string.Empty,
@@ -1389,7 +1373,7 @@ namespace SabreTools.Data.Extensions.Test
[Fact]
public void HasZeroHash_Rom_ZeroSHA384_True()
{
DictionaryBase self = new Rom
var self = new Rom
{
[Rom.CRC16Key] = string.Empty,
[Rom.CRCKey] = string.Empty,
@@ -1413,7 +1397,7 @@ namespace SabreTools.Data.Extensions.Test
[Fact]
public void HasZeroHash_Rom_ZeroSHA512_True()
{
DictionaryBase self = new Rom
var self = new Rom
{
[Rom.CRC16Key] = string.Empty,
[Rom.CRCKey] = string.Empty,
@@ -1437,7 +1421,7 @@ namespace SabreTools.Data.Extensions.Test
[Fact]
public void HasZeroHash_Rom_ZeroSpamSum_True()
{
DictionaryBase self = new Rom
var self = new Rom
{
[Rom.CRC16Key] = string.Empty,
[Rom.CRCKey] = string.Empty,
@@ -1461,7 +1445,7 @@ namespace SabreTools.Data.Extensions.Test
[Fact]
public void HasZeroHash_Rom_ZeroAll_True()
{
DictionaryBase self = new Rom
var self = new Rom
{
[Rom.CRC16Key] = HashType.CRC16.ZeroString,
[Rom.CRCKey] = HashType.CRC32.ZeroString,
@@ -1482,14 +1466,6 @@ namespace SabreTools.Data.Extensions.Test
Assert.True(actual);
}
[Fact]
public void HasZeroHash_Other_False()
{
DictionaryBase self = new Sample();
bool actual = self.HasZeroHash();
Assert.False(actual);
}
#endregion
#region FillMissingHashes
@@ -1497,8 +1473,8 @@ namespace SabreTools.Data.Extensions.Test
[Fact]
public void FillMissingHashes_Disk_BothEmpty()
{
DictionaryBase self = new Disk();
DictionaryBase other = new Disk();
var self = new Disk();
var other = new Disk();
self.FillMissingHashes(other);
Assert.Empty(self);
@@ -1507,8 +1483,8 @@ namespace SabreTools.Data.Extensions.Test
[Fact]
public void FillMissingHashes_Disk_AllMissing()
{
DictionaryBase self = new Disk();
DictionaryBase other = new Disk
var self = new Disk();
var other = new Disk
{
MD5 = "XXXXXX",
SHA1 = "XXXXXX",
@@ -1520,8 +1496,8 @@ namespace SabreTools.Data.Extensions.Test
[Fact]
public void FillMissingHashes_Media_BothEmpty()
{
DictionaryBase self = new Media();
DictionaryBase other = new Media();
var self = new Media();
var other = new Media();
self.FillMissingHashes(other);
Assert.Empty(self);
}
@@ -1529,8 +1505,8 @@ namespace SabreTools.Data.Extensions.Test
[Fact]
public void FillMissingHashes_Media_AllMissing()
{
DictionaryBase self = new Media();
DictionaryBase other = new Media
var self = new Media();
var other = new Media
{
MD5 = "XXXXXX",
SHA1 = "XXXXXX",
@@ -1544,8 +1520,8 @@ namespace SabreTools.Data.Extensions.Test
[Fact]
public void FillMissingHashes_Rom_BothEmpty()
{
DictionaryBase self = new Rom();
DictionaryBase other = new Rom();
var self = new Rom();
var other = new Rom();
self.FillMissingHashes(other);
Assert.Empty(self);
}
@@ -1553,8 +1529,8 @@ namespace SabreTools.Data.Extensions.Test
[Fact]
public void FillMissingHashes_Rom_AllMissing()
{
DictionaryBase self = new Rom();
DictionaryBase other = new Rom
var self = new Rom();
var other = new Rom
{
[Rom.CRC16Key] = "XXXXXX",
[Rom.CRCKey] = "XXXXXX",

View File

@@ -357,27 +357,10 @@ namespace SabreTools.Data.Extensions
#region Conversion
/// <summary>
/// Convert a DictionaryBase to a Rom
/// </summary>
public static Rom? ConvertToRom(this DictionaryBase? self)
{
// If the DatItem is missing, we can't do anything
if (self is null)
return null;
return self switch
{
Disk diskSelf => ConvertToRom(diskSelf),
Media mediaSelf => ConvertToRom(mediaSelf),
_ => null,
};
}
/// <summary>
/// Convert a Disk to a Rom
/// </summary>
private static Rom? ConvertToRom(this Disk? disk)
public static Rom? ConvertToRom(this Disk? disk)
{
// If the Disk is missing, we can't do anything
if (disk is null)
@@ -403,7 +386,7 @@ namespace SabreTools.Data.Extensions
/// <summary>
/// Convert a Media to a Rom
/// </summary>
private static Rom? ConvertToRom(this Media? media)
public static Rom? ConvertToRom(this Media? media)
{
// If the Media is missing, we can't do anything
if (media is null)
@@ -592,29 +575,160 @@ namespace SabreTools.Data.Extensions
/// <summary>
/// Returns if any hashes exist
/// </summary>
public static bool HasHashes(this DictionaryBase self)
public static bool HasHashes(this Disk disk)
{
return self switch
{
Disk diskSelf => diskSelf.HasHashes(),
Media mediaSelf => mediaSelf.HasHashes(),
Rom romSelf => romSelf.HasHashes(),
_ => false,
};
bool md5Null = string.IsNullOrEmpty(disk.MD5);
bool sha1Null = string.IsNullOrEmpty(disk.SHA1);
return !md5Null
|| !sha1Null;
}
/// <summary>
/// Returns if any hashes exist
/// </summary>
public static bool HasHashes(this Media media)
{
bool md5Null = string.IsNullOrEmpty(media.MD5);
bool sha1Null = string.IsNullOrEmpty(media.SHA1);
bool sha256Null = string.IsNullOrEmpty(media.SHA256);
bool spamsumNull = string.IsNullOrEmpty(media.SpamSum);
return !md5Null
|| !sha1Null
|| !sha256Null
|| !spamsumNull;
}
/// <summary>
/// Returns if any hashes exist
/// </summary>
public static bool HasHashes(this Rom rom)
{
bool crc16Null = string.IsNullOrEmpty(rom.ReadString(Rom.CRC16Key));
bool crcNull = string.IsNullOrEmpty(rom.ReadString(Rom.CRCKey));
bool crc64Null = string.IsNullOrEmpty(rom.ReadString(Rom.CRC64Key));
bool md2Null = string.IsNullOrEmpty(rom.ReadString(Rom.MD2Key));
bool md4Null = string.IsNullOrEmpty(rom.ReadString(Rom.MD4Key));
bool md5Null = string.IsNullOrEmpty(rom.ReadString(Rom.MD5Key));
bool ripeMD128Null = string.IsNullOrEmpty(rom.ReadString(Rom.RIPEMD128Key));
bool ripeMD160Null = string.IsNullOrEmpty(rom.ReadString(Rom.RIPEMD160Key));
bool sha1Null = string.IsNullOrEmpty(rom.ReadString(Rom.SHA1Key));
bool sha256Null = string.IsNullOrEmpty(rom.ReadString(Rom.SHA256Key));
bool sha384Null = string.IsNullOrEmpty(rom.ReadString(Rom.SHA384Key));
bool sha512Null = string.IsNullOrEmpty(rom.ReadString(Rom.SHA512Key));
bool spamsumNull = string.IsNullOrEmpty(rom.ReadString(Rom.SpamSumKey));
return !crc16Null
|| !crcNull
|| !crc64Null
|| !md2Null
|| !md4Null
|| !md5Null
|| !ripeMD128Null
|| !ripeMD160Null
|| !sha1Null
|| !sha256Null
|| !sha384Null
|| !sha512Null
|| !spamsumNull;
}
/// <summary>
/// Returns if all of the hashes are set to their 0-byte values or null
/// </summary>
public static bool HasZeroHash(this DictionaryBase self)
public static bool HasZeroHash(this Disk disk)
{
return self switch
{
Disk diskSelf => diskSelf.HasZeroHash(),
Media mediaSelf => mediaSelf.HasZeroHash(),
Rom romSelf => romSelf.HasZeroHash(),
_ => false,
};
string? md5 = disk.MD5;
bool md5Null = string.IsNullOrEmpty(md5) || string.Equals(md5, HashType.MD5.ZeroString, StringComparison.OrdinalIgnoreCase);
string? sha1 = disk.SHA1;
bool sha1Null = string.IsNullOrEmpty(sha1) || string.Equals(sha1, HashType.SHA1.ZeroString, StringComparison.OrdinalIgnoreCase);
return md5Null
&& sha1Null;
}
/// <summary>
/// Returns if all of the hashes are set to their 0-byte values or null
/// </summary>
public static bool HasZeroHash(this Media media)
{
string? md5 = media.MD5;
bool md5Null = string.IsNullOrEmpty(md5) || string.Equals(md5, HashType.MD5.ZeroString, StringComparison.OrdinalIgnoreCase);
string? sha1 = media.SHA1;
bool sha1Null = string.IsNullOrEmpty(sha1) || string.Equals(sha1, HashType.SHA1.ZeroString, StringComparison.OrdinalIgnoreCase);
string? sha256 = media.SHA256;
bool sha256Null = string.IsNullOrEmpty(sha256) || string.Equals(sha256, HashType.SHA256.ZeroString, StringComparison.OrdinalIgnoreCase);
string? spamsum = media.SpamSum;
bool spamsumNull = string.IsNullOrEmpty(spamsum) || string.Equals(spamsum, HashType.SpamSum.ZeroString, StringComparison.OrdinalIgnoreCase);
return md5Null
&& sha1Null
&& sha256Null
&& spamsumNull;
}
/// <summary>
/// Returns if all of the hashes are set to their 0-byte values or null
/// </summary>
public static bool HasZeroHash(this Rom rom)
{
string? crc16 = rom.ReadString(Rom.CRC16Key);
bool crc16Null = string.IsNullOrEmpty(crc16) || string.Equals(crc16, HashType.CRC16.ZeroString, StringComparison.OrdinalIgnoreCase);
string? crc = rom.ReadString(Rom.CRCKey);
bool crcNull = string.IsNullOrEmpty(crc) || string.Equals(crc, HashType.CRC32.ZeroString, StringComparison.OrdinalIgnoreCase);
string? crc64 = rom.ReadString(Rom.CRC64Key);
bool crc64Null = string.IsNullOrEmpty(crc64) || string.Equals(crc64, HashType.CRC64.ZeroString, StringComparison.OrdinalIgnoreCase);
string? md2 = rom.ReadString(Rom.MD2Key);
bool md2Null = string.IsNullOrEmpty(md2) || string.Equals(md2, HashType.MD2.ZeroString, StringComparison.OrdinalIgnoreCase);
string? md4 = rom.ReadString(Rom.MD4Key);
bool md4Null = string.IsNullOrEmpty(md4) || string.Equals(md4, HashType.MD4.ZeroString, StringComparison.OrdinalIgnoreCase);
string? md5 = rom.ReadString(Rom.MD5Key);
bool md5Null = string.IsNullOrEmpty(md5) || string.Equals(md5, HashType.MD5.ZeroString, StringComparison.OrdinalIgnoreCase);
string? ripeMD128 = rom.ReadString(Rom.RIPEMD128Key);
bool ripeMD128Null = string.IsNullOrEmpty(value: ripeMD128) || string.Equals(ripeMD128, HashType.RIPEMD128.ZeroString, StringComparison.OrdinalIgnoreCase);
string? ripeMD160 = rom.ReadString(Rom.RIPEMD160Key);
bool ripeMD160Null = string.IsNullOrEmpty(ripeMD160) || string.Equals(ripeMD160, HashType.RIPEMD160.ZeroString, StringComparison.OrdinalIgnoreCase);
string? sha1 = rom.ReadString(Rom.SHA1Key);
bool sha1Null = string.IsNullOrEmpty(sha1) || string.Equals(sha1, HashType.SHA1.ZeroString, StringComparison.OrdinalIgnoreCase);
string? sha256 = rom.ReadString(Rom.SHA256Key);
bool sha256Null = string.IsNullOrEmpty(sha256) || string.Equals(sha256, HashType.SHA256.ZeroString, StringComparison.OrdinalIgnoreCase);
string? sha384 = rom.ReadString(Rom.SHA384Key);
bool sha384Null = string.IsNullOrEmpty(sha384) || string.Equals(sha384, HashType.SHA384.ZeroString, StringComparison.OrdinalIgnoreCase);
string? sha512 = rom.ReadString(Rom.SHA512Key);
bool sha512Null = string.IsNullOrEmpty(sha512) || string.Equals(sha512, HashType.SHA512.ZeroString, StringComparison.OrdinalIgnoreCase);
string? spamsum = rom.ReadString(Rom.SpamSumKey);
bool spamsumNull = string.IsNullOrEmpty(spamsum) || string.Equals(spamsum, HashType.SpamSum.ZeroString, StringComparison.OrdinalIgnoreCase);
return crc16Null
&& crcNull
&& crc64Null
&& md2Null
&& md4Null
&& md5Null
&& ripeMD128Null
&& ripeMD160Null
&& sha1Null
&& sha256Null
&& sha384Null
&& sha512Null
&& spamsumNull;
}
/// <summary>
@@ -714,207 +828,14 @@ namespace SabreTools.Data.Extensions
|| !spamsumNull;
}
/// <summary>
/// Returns if any hashes exist
/// </summary>
private static bool HasHashes(this Disk disk)
{
bool md5Null = string.IsNullOrEmpty(disk.MD5);
bool sha1Null = string.IsNullOrEmpty(disk.SHA1);
return !md5Null
|| !sha1Null;
}
/// <summary>
/// Returns if any hashes exist
/// </summary>
private static bool HasHashes(this Media media)
{
bool md5Null = string.IsNullOrEmpty(media.MD5);
bool sha1Null = string.IsNullOrEmpty(media.SHA1);
bool sha256Null = string.IsNullOrEmpty(media.SHA256);
bool spamsumNull = string.IsNullOrEmpty(media.SpamSum);
return !md5Null
|| !sha1Null
|| !sha256Null
|| !spamsumNull;
}
/// <summary>
/// Returns if any hashes exist
/// </summary>
private static bool HasHashes(this Rom rom)
{
bool crc16Null = string.IsNullOrEmpty(rom.ReadString(Rom.CRC16Key));
bool crcNull = string.IsNullOrEmpty(rom.ReadString(Rom.CRCKey));
bool crc64Null = string.IsNullOrEmpty(rom.ReadString(Rom.CRC64Key));
bool md2Null = string.IsNullOrEmpty(rom.ReadString(Rom.MD2Key));
bool md4Null = string.IsNullOrEmpty(rom.ReadString(Rom.MD4Key));
bool md5Null = string.IsNullOrEmpty(rom.ReadString(Rom.MD5Key));
bool ripeMD128Null = string.IsNullOrEmpty(rom.ReadString(Rom.RIPEMD128Key));
bool ripeMD160Null = string.IsNullOrEmpty(rom.ReadString(Rom.RIPEMD160Key));
bool sha1Null = string.IsNullOrEmpty(rom.ReadString(Rom.SHA1Key));
bool sha256Null = string.IsNullOrEmpty(rom.ReadString(Rom.SHA256Key));
bool sha384Null = string.IsNullOrEmpty(rom.ReadString(Rom.SHA384Key));
bool sha512Null = string.IsNullOrEmpty(rom.ReadString(Rom.SHA512Key));
bool spamsumNull = string.IsNullOrEmpty(rom.ReadString(Rom.SpamSumKey));
return !crc16Null
|| !crcNull
|| !crc64Null
|| !md2Null
|| !md4Null
|| !md5Null
|| !ripeMD128Null
|| !ripeMD160Null
|| !sha1Null
|| !sha256Null
|| !sha384Null
|| !sha512Null
|| !spamsumNull;
}
/// <summary>
/// Returns if all of the hashes are set to their 0-byte values or null
/// </summary>
private static bool HasZeroHash(this Disk disk)
{
string? md5 = disk.MD5;
bool md5Null = string.IsNullOrEmpty(md5) || string.Equals(md5, HashType.MD5.ZeroString, StringComparison.OrdinalIgnoreCase);
string? sha1 = disk.SHA1;
bool sha1Null = string.IsNullOrEmpty(sha1) || string.Equals(sha1, HashType.SHA1.ZeroString, StringComparison.OrdinalIgnoreCase);
return md5Null
&& sha1Null;
}
/// <summary>
/// Returns if all of the hashes are set to their 0-byte values or null
/// </summary>
private static bool HasZeroHash(this Media media)
{
string? md5 = media.MD5;
bool md5Null = string.IsNullOrEmpty(md5) || string.Equals(md5, HashType.MD5.ZeroString, StringComparison.OrdinalIgnoreCase);
string? sha1 = media.SHA1;
bool sha1Null = string.IsNullOrEmpty(sha1) || string.Equals(sha1, HashType.SHA1.ZeroString, StringComparison.OrdinalIgnoreCase);
string? sha256 = media.SHA256;
bool sha256Null = string.IsNullOrEmpty(sha256) || string.Equals(sha256, HashType.SHA256.ZeroString, StringComparison.OrdinalIgnoreCase);
string? spamsum = media.SpamSum;
bool spamsumNull = string.IsNullOrEmpty(spamsum) || string.Equals(spamsum, HashType.SpamSum.ZeroString, StringComparison.OrdinalIgnoreCase);
return md5Null
&& sha1Null
&& sha256Null
&& spamsumNull;
}
/// <summary>
/// Returns if all of the hashes are set to their 0-byte values or null
/// </summary>
private static bool HasZeroHash(this Rom rom)
{
string? crc16 = rom.ReadString(Rom.CRC16Key);
bool crc16Null = string.IsNullOrEmpty(crc16) || string.Equals(crc16, HashType.CRC16.ZeroString, StringComparison.OrdinalIgnoreCase);
string? crc = rom.ReadString(Rom.CRCKey);
bool crcNull = string.IsNullOrEmpty(crc) || string.Equals(crc, HashType.CRC32.ZeroString, StringComparison.OrdinalIgnoreCase);
string? crc64 = rom.ReadString(Rom.CRC64Key);
bool crc64Null = string.IsNullOrEmpty(crc64) || string.Equals(crc64, HashType.CRC64.ZeroString, StringComparison.OrdinalIgnoreCase);
string? md2 = rom.ReadString(Rom.MD2Key);
bool md2Null = string.IsNullOrEmpty(md2) || string.Equals(md2, HashType.MD2.ZeroString, StringComparison.OrdinalIgnoreCase);
string? md4 = rom.ReadString(Rom.MD4Key);
bool md4Null = string.IsNullOrEmpty(md4) || string.Equals(md4, HashType.MD4.ZeroString, StringComparison.OrdinalIgnoreCase);
string? md5 = rom.ReadString(Rom.MD5Key);
bool md5Null = string.IsNullOrEmpty(md5) || string.Equals(md5, HashType.MD5.ZeroString, StringComparison.OrdinalIgnoreCase);
string? ripeMD128 = rom.ReadString(Rom.RIPEMD128Key);
bool ripeMD128Null = string.IsNullOrEmpty(value: ripeMD128) || string.Equals(ripeMD128, HashType.RIPEMD128.ZeroString, StringComparison.OrdinalIgnoreCase);
string? ripeMD160 = rom.ReadString(Rom.RIPEMD160Key);
bool ripeMD160Null = string.IsNullOrEmpty(ripeMD160) || string.Equals(ripeMD160, HashType.RIPEMD160.ZeroString, StringComparison.OrdinalIgnoreCase);
string? sha1 = rom.ReadString(Rom.SHA1Key);
bool sha1Null = string.IsNullOrEmpty(sha1) || string.Equals(sha1, HashType.SHA1.ZeroString, StringComparison.OrdinalIgnoreCase);
string? sha256 = rom.ReadString(Rom.SHA256Key);
bool sha256Null = string.IsNullOrEmpty(sha256) || string.Equals(sha256, HashType.SHA256.ZeroString, StringComparison.OrdinalIgnoreCase);
string? sha384 = rom.ReadString(Rom.SHA384Key);
bool sha384Null = string.IsNullOrEmpty(sha384) || string.Equals(sha384, HashType.SHA384.ZeroString, StringComparison.OrdinalIgnoreCase);
string? sha512 = rom.ReadString(Rom.SHA512Key);
bool sha512Null = string.IsNullOrEmpty(sha512) || string.Equals(sha512, HashType.SHA512.ZeroString, StringComparison.OrdinalIgnoreCase);
string? spamsum = rom.ReadString(Rom.SpamSumKey);
bool spamsumNull = string.IsNullOrEmpty(spamsum) || string.Equals(spamsum, HashType.SpamSum.ZeroString, StringComparison.OrdinalIgnoreCase);
return crc16Null
&& crcNull
&& crc64Null
&& md2Null
&& md4Null
&& md5Null
&& ripeMD128Null
&& ripeMD160Null
&& sha1Null
&& sha256Null
&& sha384Null
&& sha512Null
&& spamsumNull;
}
#endregion
#region Information Filling
/// <summary>
/// Fill any missing size and hash information from another DictionaryBase
/// </summary>
public static void FillMissingHashes(this DictionaryBase? self, DictionaryBase? other)
{
if (self is null || other is null)
return;
#if NETCOREAPP || NETSTANDARD2_0_OR_GREATER
switch (self, other)
{
case (Disk diskSelf, Disk diskOther):
diskSelf.FillMissingHashes(diskOther);
break;
case (Media mediaSelf, Media mediaOther):
mediaSelf.FillMissingHashes(mediaOther);
break;
case (Rom romSelf, Rom romOther):
romSelf.FillMissingHashes(romOther);
break;
default:
break;
}
#else
if (self is Disk diskSelf && other is Disk diskOther)
diskSelf.FillMissingHashes(diskOther);
else if (self is Media mediaSelf && other is Media mediaOther)
mediaSelf.FillMissingHashes(mediaOther);
else if (self is Rom romSelf && other is Rom romOther)
romSelf.FillMissingHashes(romOther);
#endif
}
/// <summary>
/// Fill any missing size and hash information from another Disk
/// </summary>
private static void FillMissingHashes(this Disk? self, Disk? other)
public static void FillMissingHashes(this Disk? self, Disk? other)
{
if (self is null || other is null)
return;
@@ -933,7 +854,7 @@ namespace SabreTools.Data.Extensions
/// <summary>
/// Fill any missing size and hash information from another Media
/// </summary>
private static void FillMissingHashes(this Media? self, Media? other)
public static void FillMissingHashes(this Media? self, Media? other)
{
if (self is null || other is null)
return;
@@ -962,7 +883,7 @@ namespace SabreTools.Data.Extensions
/// <summary>
/// Fill any missing size and hash information from another Rom
/// </summary>
private static void FillMissingHashes(this Rom? self, Rom? other)
public static void FillMissingHashes(this Rom? self, Rom? other)
{
if (self is null || other is null)
return;

View File

@@ -151,7 +151,7 @@ namespace SabreTools.Metadata.DatItems.Formats
/// <returns></returns>
public Rom ConvertToRom()
{
var rom = new Rom(_internal.ConvertToRom()!);
var rom = new Rom((_internal as Data.Models.Metadata.Disk).ConvertToRom()!);
// Create a DataArea if there was an existing DiskArea
if (DiskArea is not null)
@@ -178,19 +178,19 @@ namespace SabreTools.Metadata.DatItems.Formats
/// </summary>
/// <param name="other">Disk to fill information from</param>
public void FillMissingInformation(Disk other)
=> _internal.FillMissingHashes(other._internal);
=> (_internal as Data.Models.Metadata.Disk).FillMissingHashes(other._internal as Data.Models.Metadata.Disk);
/// <summary>
/// Returns if the Rom contains any hashes
/// </summary>
/// <returns>True if any hash exists, false otherwise</returns>
public bool HasHashes() => _internal.HasHashes();
public bool HasHashes() => (_internal as Data.Models.Metadata.Disk)?.HasHashes() ?? false;
/// <summary>
/// Returns if all of the hashes are set to their 0-byte values
/// </summary>
/// <returns>True if any hash matches the 0-byte value, false otherwise</returns>
public bool HasZeroHash() => _internal.HasZeroHash();
public bool HasZeroHash() => (_internal as Data.Models.Metadata.Disk)?.HasZeroHash() ?? false;
#endregion

View File

@@ -104,7 +104,7 @@ namespace SabreTools.Metadata.DatItems.Formats
/// <returns></returns>
public Rom ConvertToRom()
{
var rom = new Rom(_internal.ConvertToRom()!);
var rom = new Rom((_internal as Data.Models.Metadata.Media).ConvertToRom()!);
rom.DupeType = DupeType;
rom.Machine = Machine?.Clone() as Machine;
@@ -123,19 +123,19 @@ namespace SabreTools.Metadata.DatItems.Formats
/// </summary>
/// <param name="other">Media to fill information from</param>
public void FillMissingInformation(Media other)
=> _internal.FillMissingHashes(other._internal);
=> (_internal as Data.Models.Metadata.Media).FillMissingHashes(other._internal as Data.Models.Metadata.Media);
/// <summary>
/// Returns if the Rom contains any hashes
/// </summary>
/// <returns>True if any hash exists, false otherwise</returns>
public bool HasHashes() => _internal.HasHashes();
public bool HasHashes() => (_internal as Data.Models.Metadata.Media)?.HasHashes() ?? false;
/// <summary>
/// Returns if all of the hashes are set to their 0-byte values
/// </summary>
/// <returns>True if any hash matches the 0-byte value, false otherwise</returns>
public bool HasZeroHash() => _internal.HasZeroHash();
public bool HasZeroHash() => (_internal as Data.Models.Metadata.Media)?.HasZeroHash() ?? false;
#endregion

View File

@@ -417,19 +417,19 @@ namespace SabreTools.Metadata.DatItems.Formats
/// </summary>
/// <param name="other">Rom to fill information from</param>
public void FillMissingInformation(Rom other)
=> _internal.FillMissingHashes(other._internal);
=> (_internal as Data.Models.Metadata.Rom).FillMissingHashes(other._internal as Data.Models.Metadata.Rom);
/// <summary>
/// Returns if the Rom contains any hashes
/// </summary>
/// <returns>True if any hash exists, false otherwise</returns>
public bool HasHashes() => _internal.HasHashes();
public bool HasHashes() => (_internal as Data.Models.Metadata.Rom)?.HasHashes() ?? false;
/// <summary>
/// Returns if all of the hashes are set to their 0-byte values
/// </summary>
/// <returns>True if any hash matches the 0-byte value, false otherwise</returns>
public bool HasZeroHash() => _internal.HasZeroHash();
public bool HasZeroHash() => (_internal as Data.Models.Metadata.Rom)?.HasZeroHash() ?? false;
#endregion