mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Move suffix generation
This commit is contained in:
@@ -603,5 +603,94 @@ namespace SabreTools.Core
|
||||
}
|
||||
|
||||
#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
|
||||
}
|
||||
}
|
||||
@@ -192,7 +192,6 @@ namespace SabreTools.DatItems.Formats
|
||||
/// <summary>
|
||||
/// Create a Disk object from a BaseFile
|
||||
/// </summary>
|
||||
/// <param name="baseFile"></param>
|
||||
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
|
||||
/// </summary>
|
||||
/// <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>
|
||||
/// Get unique duplicate suffix on name collision
|
||||
/// </summary>
|
||||
/// <returns>String representing the suffix</returns>
|
||||
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
|
||||
|
||||
|
||||
@@ -185,25 +185,13 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Fill any missing size and hash information from another Media
|
||||
/// </summary>
|
||||
/// <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>
|
||||
/// Get unique duplicate suffix on name collision
|
||||
/// </summary>
|
||||
/// <returns>String representing the suffix</returns>
|
||||
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
|
||||
|
||||
|
||||
@@ -572,31 +572,13 @@ namespace SabreTools.DatItems.Formats
|
||||
/// Fill any missing size and hash information from another Rom
|
||||
/// </summary>
|
||||
/// <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>
|
||||
/// Get unique duplicate suffix on name collision
|
||||
/// </summary>
|
||||
/// <returns>String representing the suffix</returns>
|
||||
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();
|
||||
|
||||
/// <summary>
|
||||
/// Returns if the Rom contains any hashes
|
||||
|
||||
Reference in New Issue
Block a user