diff --git a/SabreTools.Core/DictionaryBaseExtensions.cs b/SabreTools.Core/DictionaryBaseExtensions.cs
index 7965291e..d4a4ffa1 100644
--- a/SabreTools.Core/DictionaryBaseExtensions.cs
+++ b/SabreTools.Core/DictionaryBaseExtensions.cs
@@ -499,5 +499,106 @@ namespace SabreTools.Core
}
#endregion
+
+ #region Information Filling
+
+ ///
+ /// Fill any missing size and hash information from another Disk
+ ///
+ public static void FillMissingHashes(this Disk? self, Disk? other)
+ {
+ if (self == null || other == null)
+ return;
+
+ string? selfMd5 = self.ReadString(Disk.MD5Key);
+ string? otherMd5 = other.ReadString(Disk.MD5Key);
+ if (string.IsNullOrWhiteSpace(selfMd5) && !string.IsNullOrWhiteSpace(otherMd5))
+ self[Disk.MD5Key] = otherMd5;
+
+ string? selfSha1 = self.ReadString(Disk.SHA1Key);
+ string? otherSha1 = other.ReadString(Disk.SHA1Key);
+ if (string.IsNullOrWhiteSpace(selfSha1) && !string.IsNullOrWhiteSpace(otherSha1))
+ self[Disk.SHA1Key] = otherSha1;
+ }
+
+ ///
+ /// Fill any missing size and hash information from another Media
+ ///
+ public static void FillMissingHashes(this Media? self, Media? other)
+ {
+ if (self == null || other == null)
+ return;
+
+ string? selfMd5 = self.ReadString(Media.MD5Key);
+ string? otherMd5 = other.ReadString(Media.MD5Key);
+ if (string.IsNullOrWhiteSpace(selfMd5) && !string.IsNullOrWhiteSpace(otherMd5))
+ self[Media.MD5Key] = otherMd5;
+
+ string? selfSha1 = self.ReadString(Media.SHA1Key);
+ string? otherSha1 = other.ReadString(Media.SHA1Key);
+ if (string.IsNullOrWhiteSpace(selfSha1) && !string.IsNullOrWhiteSpace(otherSha1))
+ self[Media.SHA1Key] = otherSha1;
+
+ string? selfSha256 = self.ReadString(Media.SHA256Key);
+ string? otherSha256 = other.ReadString(Media.SHA256Key);
+ if (string.IsNullOrWhiteSpace(selfSha256) && !string.IsNullOrWhiteSpace(otherSha256))
+ self[Media.SHA256Key] = otherSha256;
+
+ string? selfSpamSum = self.ReadString(Media.SpamSumKey);
+ string? otherSpamSum = other.ReadString(Media.SpamSumKey);
+ if (string.IsNullOrWhiteSpace(selfSpamSum) && !string.IsNullOrWhiteSpace(otherSpamSum))
+ self[Media.SpamSumKey] = otherSpamSum;
+ }
+
+ ///
+ /// Fill any missing size and hash information from another Rom
+ ///
+ public static void FillMissingHashes(this Rom? self, Rom? other)
+ {
+ if (self == null || other == null)
+ return;
+
+ long? selfSize = self.ReadLong(Rom.SizeKey);
+ long? otherSize = other.ReadLong(Rom.SizeKey);
+ if (selfSize == null && otherSize != null)
+ self[Rom.SizeKey] = otherSize;
+
+ string? selfCrc = self.ReadString(Rom.CRCKey);
+ string? otherCrc = other.ReadString(Rom.CRCKey);
+ if (string.IsNullOrWhiteSpace(selfCrc) && !string.IsNullOrWhiteSpace(otherCrc))
+ self[Rom.CRCKey] = otherCrc;
+
+ string? selfMd5 = self.ReadString(Rom.MD5Key);
+ string? otherMd5 = other.ReadString(Rom.MD5Key);
+ if (string.IsNullOrWhiteSpace(selfMd5) && !string.IsNullOrWhiteSpace(otherMd5))
+ self[Rom.MD5Key] = otherMd5;
+
+ string? selfSha1 = self.ReadString(Rom.SHA1Key);
+ string? otherSha1 = other.ReadString(Rom.SHA1Key);
+ if (string.IsNullOrWhiteSpace(selfSha1) && !string.IsNullOrWhiteSpace(otherSha1))
+ self[Rom.SHA1Key] = otherSha1;
+
+ string? selfSha256 = self.ReadString(Rom.SHA256Key);
+ string? otherSha256 = other.ReadString(Rom.SHA256Key);
+ if (string.IsNullOrWhiteSpace(selfSha256) && !string.IsNullOrWhiteSpace(otherSha256))
+ self[Rom.SHA256Key] = otherSha256;
+
+ string? selfSha384 = self.ReadString(Rom.SHA384Key);
+ string? otherSha384 = other.ReadString(Rom.SHA384Key);
+ if (string.IsNullOrWhiteSpace(selfSha384) && !string.IsNullOrWhiteSpace(otherSha384))
+ self[Rom.SHA384Key] = otherSha384;
+
+ string? selfSha512 = self.ReadString(Rom.SHA512Key);
+ string? otherSha512 = other.ReadString(Rom.SHA512Key);
+ if (string.IsNullOrWhiteSpace(selfSha512) && !string.IsNullOrWhiteSpace(otherSha512))
+ self[Rom.SHA512Key] = otherSha512;
+
+ string? selfSpamSum = self.ReadString(Rom.SpamSumKey);
+ string? otherSpamSum = other.ReadString(Rom.SpamSumKey);
+ if (string.IsNullOrWhiteSpace(selfSpamSum) && !string.IsNullOrWhiteSpace(otherSpamSum))
+ self[Rom.SpamSumKey] = otherSpamSum;
+ }
+
+ #endregion
}
}
\ No newline at end of file
diff --git a/SabreTools.DatItems/DatItem.cs b/SabreTools.DatItems/DatItem.cs
index 59ad94ba..392367ef 100644
--- a/SabreTools.DatItems/DatItem.cs
+++ b/SabreTools.DatItems/DatItem.cs
@@ -1,6 +1,5 @@
using System;
using System.IO;
-using System.Linq;
using System.Xml.Serialization;
using NaturalSort;
using Newtonsoft.Json;
@@ -247,7 +246,7 @@ namespace SabreTools.DatItems
if (item?.Machine == null)
return;
- Machine = (Machine)item.Machine.Clone();
+ Machine = item.Machine.Clone() as Machine;
}
///
@@ -259,7 +258,7 @@ namespace SabreTools.DatItems
if (machine == null)
return;
- Machine = (Machine)machine.Clone();
+ Machine = machine.Clone() as Machine;
}
#endregion
diff --git a/SabreTools.DatItems/Formats/Disk.cs b/SabreTools.DatItems/Formats/Disk.cs
index ab016d73..81f758aa 100644
--- a/SabreTools.DatItems/Formats/Disk.cs
+++ b/SabreTools.DatItems/Formats/Disk.cs
@@ -283,14 +283,7 @@ namespace SabreTools.DatItems.Formats
/// Fill any missing size and hash information from another Disk
///
/// Disk to fill information from
- public void FillMissingInformation(Disk other)
- {
- if (string.IsNullOrWhiteSpace(MD5) && !string.IsNullOrWhiteSpace(other.MD5))
- MD5 = other.MD5;
-
- if (string.IsNullOrWhiteSpace(SHA1) && !string.IsNullOrWhiteSpace(other.SHA1))
- SHA1 = other.SHA1;
- }
+ public void FillMissingInformation(Disk other) => _disk?.FillMissingHashes(other?._disk);
///
/// Get unique duplicate suffix on name collision
diff --git a/SabreTools.DatItems/Formats/Media.cs b/SabreTools.DatItems/Formats/Media.cs
index fdd2638b..b31219fb 100644
--- a/SabreTools.DatItems/Formats/Media.cs
+++ b/SabreTools.DatItems/Formats/Media.cs
@@ -185,20 +185,7 @@ namespace SabreTools.DatItems.Formats
/// Fill any missing size and hash information from another Media
///
/// Media to fill information from
- public void FillMissingInformation(Media other)
- {
- if (string.IsNullOrWhiteSpace(MD5) && !string.IsNullOrWhiteSpace(other.MD5))
- MD5 = other.MD5;
-
- if (string.IsNullOrWhiteSpace(SHA1) && !string.IsNullOrWhiteSpace(other.SHA1))
- SHA1 = other.SHA1;
-
- if (string.IsNullOrWhiteSpace(SHA256) && !string.IsNullOrWhiteSpace(other.SHA256))
- SHA256 = other.SHA256;
-
- if (string.IsNullOrWhiteSpace(SpamSum) && !string.IsNullOrWhiteSpace(other.SpamSum))
- SpamSum = other.SpamSum;
- }
+ public void FillMissingInformation(Media other) => _media?.FillMissingHashes(other?._media);
///
/// Get unique duplicate suffix on name collision
diff --git a/SabreTools.DatItems/Formats/Rom.cs b/SabreTools.DatItems/Formats/Rom.cs
index bf435e67..3155286a 100644
--- a/SabreTools.DatItems/Formats/Rom.cs
+++ b/SabreTools.DatItems/Formats/Rom.cs
@@ -572,32 +572,7 @@ namespace SabreTools.DatItems.Formats
/// Fill any missing size and hash information from another Rom
///
/// Rom to fill information from
- public void FillMissingInformation(Rom other)
- {
- if (Size == null && other.Size != null)
- Size = other.Size;
-
- if (string.IsNullOrWhiteSpace(CRC) && !string.IsNullOrWhiteSpace(other.CRC))
- CRC = other.CRC;
-
- if (string.IsNullOrWhiteSpace(MD5) && !string.IsNullOrWhiteSpace(other.MD5))
- MD5 = other.MD5;
-
- if (string.IsNullOrWhiteSpace(SHA1) && !string.IsNullOrWhiteSpace(other.SHA1))
- SHA1 = other.SHA1;
-
- if (string.IsNullOrWhiteSpace(SHA256) && !string.IsNullOrWhiteSpace(other.SHA256))
- SHA256 = other.SHA256;
-
- if (string.IsNullOrWhiteSpace(SHA384) && !string.IsNullOrWhiteSpace(other.SHA384))
- SHA384 = other.SHA384;
-
- if (string.IsNullOrWhiteSpace(SHA512) && !string.IsNullOrWhiteSpace(other.SHA512))
- SHA512 = other.SHA512;
-
- if (string.IsNullOrWhiteSpace(SpamSum) && !string.IsNullOrWhiteSpace(other.SpamSum))
- SpamSum = other.SpamSum;
- }
+ public void FillMissingInformation(Rom other) => _rom?.FillMissingHashes(other?._rom);
///
/// Get unique duplicate suffix on name collision