Move suffix generation

This commit is contained in:
Matt Nadareski
2023-08-14 19:29:10 -04:00
parent 3b9ec1d62c
commit 242150d54c
4 changed files with 95 additions and 46 deletions

View File

@@ -603,5 +603,94 @@ namespace SabreTools.Core
} }
#endregion #endregion
#region Suffix Generation
/// <summary>
/// Get unique duplicate suffix on name collision
/// </summary>
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";
}
/// <summary>
/// Get unique duplicate suffix on name collision
/// </summary>
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";
}
/// <summary>
/// Get unique duplicate suffix on name collision
/// </summary>
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
} }
} }

View File

@@ -192,7 +192,6 @@ namespace SabreTools.DatItems.Formats
/// <summary> /// <summary>
/// Create a Disk object from a BaseFile /// Create a Disk object from a BaseFile
/// </summary> /// </summary>
/// <param name="baseFile"></param>
public Disk(BaseFile baseFile) public Disk(BaseFile baseFile)
{ {
Name = baseFile.Filename; Name = baseFile.Filename;
@@ -213,7 +212,6 @@ namespace SabreTools.DatItems.Formats
{ {
return new Disk() return new Disk()
{ {
Name = this.Name,
ItemType = this.ItemType, ItemType = this.ItemType,
DupeType = this.DupeType, DupeType = this.DupeType,
@@ -283,21 +281,13 @@ namespace SabreTools.DatItems.Formats
/// Fill any missing size and hash information from another Disk /// Fill any missing size and hash information from another Disk
/// </summary> /// </summary>
/// <param name="other">Disk to fill information from</param> /// <param name="other">Disk to fill information from</param>
public void FillMissingInformation(Disk other) => _disk?.FillMissingHashes(other?._disk); public void FillMissingInformation(Disk other) => _disk.FillMissingHashes(other?._disk);
/// <summary> /// <summary>
/// Get unique duplicate suffix on name collision /// Get unique duplicate suffix on name collision
/// </summary> /// </summary>
/// <returns>String representing the suffix</returns> /// <returns>String representing the suffix</returns>
public string GetDuplicateSuffix() public string GetDuplicateSuffix() => _disk.GetDuplicateSuffix();
{
if (!string.IsNullOrWhiteSpace(MD5))
return $"_{MD5}";
else if (!string.IsNullOrWhiteSpace(SHA1))
return $"_{SHA1}";
else
return "_1";
}
#endregion #endregion

View File

@@ -185,25 +185,13 @@ namespace SabreTools.DatItems.Formats
/// Fill any missing size and hash information from another Media /// Fill any missing size and hash information from another Media
/// </summary> /// </summary>
/// <param name="other">Media to fill information from</param> /// <param name="other">Media to fill information from</param>
public void FillMissingInformation(Media other) => _media?.FillMissingHashes(other?._media); public void FillMissingInformation(Media other) => _media.FillMissingHashes(other?._media);
/// <summary> /// <summary>
/// Get unique duplicate suffix on name collision /// Get unique duplicate suffix on name collision
/// </summary> /// </summary>
/// <returns>String representing the suffix</returns> /// <returns>String representing the suffix</returns>
public string GetDuplicateSuffix() public string GetDuplicateSuffix() => _media.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";
}
#endregion #endregion

View File

@@ -572,31 +572,13 @@ namespace SabreTools.DatItems.Formats
/// Fill any missing size and hash information from another Rom /// Fill any missing size and hash information from another Rom
/// </summary> /// </summary>
/// <param name="other">Rom to fill information from</param> /// <param name="other">Rom to fill information from</param>
public void FillMissingInformation(Rom other) => _rom?.FillMissingHashes(other?._rom); public void FillMissingInformation(Rom other) => _rom.FillMissingHashes(other?._rom);
/// <summary> /// <summary>
/// Get unique duplicate suffix on name collision /// Get unique duplicate suffix on name collision
/// </summary> /// </summary>
/// <returns>String representing the suffix</returns> /// <returns>String representing the suffix</returns>
public string GetDuplicateSuffix() public string GetDuplicateSuffix() => _rom.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";
}
/// <summary> /// <summary>
/// Returns if the Rom contains any hashes /// Returns if the Rom contains any hashes