diff --git a/SabreTools.Core/DictionaryBaseExtensions.cs b/SabreTools.Core/DictionaryBaseExtensions.cs index 1b163c2a..d0f0c1df 100644 --- a/SabreTools.Core/DictionaryBaseExtensions.cs +++ b/SabreTools.Core/DictionaryBaseExtensions.cs @@ -603,5 +603,94 @@ namespace SabreTools.Core } #endregion + + #region Suffix Generation + + /// + /// Get unique duplicate suffix on name collision + /// + public static string GetDuplicateSuffix(this Disk? self) + { + if (self == null) + return string.Empty; + + string? md5 = self.ReadString(Disk.MD5Key); + if (!string.IsNullOrWhiteSpace(md5)) + return $"_{md5}"; + + string? sha1 = self.ReadString(Disk.SHA1Key); + if (!string.IsNullOrWhiteSpace(sha1)) + return $"_{sha1}"; + + return "_1"; + } + + /// + /// Get unique duplicate suffix on name collision + /// + public static string GetDuplicateSuffix(this Media? self) + { + if (self == null) + return string.Empty; + + string? md5 = self.ReadString(Media.MD5Key); + if (!string.IsNullOrWhiteSpace(md5)) + return $"_{md5}"; + + string? sha1 = self.ReadString(Media.SHA1Key); + if (!string.IsNullOrWhiteSpace(sha1)) + return $"_{sha1}"; + + string? sha256 = self.ReadString(Media.SHA256Key); + if (!string.IsNullOrWhiteSpace(sha256)) + return $"_{sha256}"; + + string? spamSum = self.ReadString(Media.SpamSumKey); + if (!string.IsNullOrWhiteSpace(spamSum)) + return $"_{spamSum}"; + + return "_1"; + } + + /// + /// Get unique duplicate suffix on name collision + /// + public static string GetDuplicateSuffix(this Rom? self) + { + if (self == null) + return string.Empty; + + string? crc = self.ReadString(Rom.CRCKey); + if (!string.IsNullOrWhiteSpace(crc)) + return $"_{crc}"; + + string? md5 = self.ReadString(Rom.MD5Key); + if (!string.IsNullOrWhiteSpace(md5)) + return $"_{md5}"; + + string? sha1 = self.ReadString(Rom.SHA1Key); + if (!string.IsNullOrWhiteSpace(sha1)) + return $"_{sha1}"; + + string? sha256 = self.ReadString(Rom.SHA256Key); + if (!string.IsNullOrWhiteSpace(sha256)) + return $"_{sha256}"; + + string? sha384 = self.ReadString(Rom.SHA384Key); + if (!string.IsNullOrWhiteSpace(sha384)) + return $"_{sha384}"; + + string? sha512 = self.ReadString(Rom.SHA512Key); + if (!string.IsNullOrWhiteSpace(sha512)) + return $"_{sha512}"; + + string? spamSum = self.ReadString(Rom.SpamSumKey); + if (!string.IsNullOrWhiteSpace(spamSum)) + return $"_{spamSum}"; + + return "_1"; + } + + #endregion } } \ No newline at end of file diff --git a/SabreTools.DatItems/Formats/Disk.cs b/SabreTools.DatItems/Formats/Disk.cs index 81f758aa..3016859d 100644 --- a/SabreTools.DatItems/Formats/Disk.cs +++ b/SabreTools.DatItems/Formats/Disk.cs @@ -192,7 +192,6 @@ namespace SabreTools.DatItems.Formats /// /// Create a Disk object from a BaseFile /// - /// public Disk(BaseFile baseFile) { Name = baseFile.Filename; @@ -213,7 +212,6 @@ namespace SabreTools.DatItems.Formats { return new Disk() { - Name = this.Name, ItemType = this.ItemType, DupeType = this.DupeType, @@ -283,21 +281,13 @@ namespace SabreTools.DatItems.Formats /// Fill any missing size and hash information from another Disk /// /// Disk to fill information from - public void FillMissingInformation(Disk other) => _disk?.FillMissingHashes(other?._disk); + public void FillMissingInformation(Disk other) => _disk.FillMissingHashes(other?._disk); /// /// Get unique duplicate suffix on name collision /// /// String representing the suffix - public string GetDuplicateSuffix() - { - if (!string.IsNullOrWhiteSpace(MD5)) - return $"_{MD5}"; - else if (!string.IsNullOrWhiteSpace(SHA1)) - return $"_{SHA1}"; - else - return "_1"; - } + public string GetDuplicateSuffix() => _disk.GetDuplicateSuffix(); #endregion diff --git a/SabreTools.DatItems/Formats/Media.cs b/SabreTools.DatItems/Formats/Media.cs index b31219fb..296d79d0 100644 --- a/SabreTools.DatItems/Formats/Media.cs +++ b/SabreTools.DatItems/Formats/Media.cs @@ -185,25 +185,13 @@ namespace SabreTools.DatItems.Formats /// Fill any missing size and hash information from another Media /// /// Media to fill information from - public void FillMissingInformation(Media other) => _media?.FillMissingHashes(other?._media); + public void FillMissingInformation(Media other) => _media.FillMissingHashes(other?._media); /// /// Get unique duplicate suffix on name collision /// /// String representing the suffix - public string GetDuplicateSuffix() - { - if (!string.IsNullOrWhiteSpace(MD5)) - return $"_{MD5}"; - else if (!string.IsNullOrWhiteSpace(SHA1)) - return $"_{SHA1}"; - else if (!string.IsNullOrWhiteSpace(SHA256)) - return $"_{SHA256}"; - else if (!string.IsNullOrWhiteSpace(SpamSum)) - return $"_{SpamSum}"; - else - return "_1"; - } + public string GetDuplicateSuffix() => _media.GetDuplicateSuffix(); #endregion diff --git a/SabreTools.DatItems/Formats/Rom.cs b/SabreTools.DatItems/Formats/Rom.cs index 3155286a..77fa405e 100644 --- a/SabreTools.DatItems/Formats/Rom.cs +++ b/SabreTools.DatItems/Formats/Rom.cs @@ -572,31 +572,13 @@ namespace SabreTools.DatItems.Formats /// Fill any missing size and hash information from another Rom /// /// Rom to fill information from - public void FillMissingInformation(Rom other) => _rom?.FillMissingHashes(other?._rom); + public void FillMissingInformation(Rom other) => _rom.FillMissingHashes(other?._rom); /// /// Get unique duplicate suffix on name collision /// /// String representing the suffix - public string GetDuplicateSuffix() - { - if (!string.IsNullOrWhiteSpace(CRC)) - return $"_{CRC}"; - else if (!string.IsNullOrWhiteSpace(MD5)) - return $"_{MD5}"; - else if (!string.IsNullOrWhiteSpace(SHA1)) - return $"_{SHA1}"; - else if (!string.IsNullOrWhiteSpace(SHA256)) - return $"_{SHA256}"; - else if (!string.IsNullOrWhiteSpace(SHA384)) - return $"_{SHA384}"; - else if (!string.IsNullOrWhiteSpace(SHA512)) - return $"_{SHA512}"; - else if (!string.IsNullOrWhiteSpace(SpamSum)) - return $"_{SpamSum}"; - else - return "_1"; - } + public string GetDuplicateSuffix() => _rom.GetDuplicateSuffix(); /// /// Returns if the Rom contains any hashes