mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[DatFiles/] Abstract out prefix/postfix logic
This commit is contained in:
@@ -5894,6 +5894,77 @@ namespace SabreTools.Library.DatFiles
|
||||
return outfile;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a prefix or postfix from inputs
|
||||
/// </summary>
|
||||
/// <param name="item">DatItem to create a prefix/postfix for</param>
|
||||
/// <param name="prefix">True for prefix, false for postfix</param>
|
||||
/// <returns>Sanitized string representing the postfix or prefix</returns>
|
||||
protected string CreatePrefixPostfix(DatItem item, bool prefix)
|
||||
{
|
||||
// Initialize strings
|
||||
string fix = "",
|
||||
game = item.MachineName,
|
||||
name = item.Name,
|
||||
manufacturer = item.Manufacturer,
|
||||
publisher = item.Publisher,
|
||||
crc = string.Empty,
|
||||
md5 = string.Empty,
|
||||
sha1 = string.Empty,
|
||||
sha256 = string.Empty,
|
||||
sha384 = string.Empty,
|
||||
sha512 = string.Empty,
|
||||
size = string.Empty;
|
||||
|
||||
// If we have a prefix
|
||||
if (prefix)
|
||||
{
|
||||
fix = Prefix + (Quotes ? "\"" : "");
|
||||
}
|
||||
// If we have a postfix
|
||||
else
|
||||
{
|
||||
fix = (Quotes ? "\"" : "") + Postfix;
|
||||
}
|
||||
|
||||
// Ensure we have the proper values for replacement
|
||||
if (item.Type == ItemType.Rom)
|
||||
{
|
||||
crc = ((Rom)item).CRC;
|
||||
md5 = ((Rom)item).MD5;
|
||||
sha1 = ((Rom)item).SHA1;
|
||||
sha256 = ((Rom)item).SHA256;
|
||||
sha384 = ((Rom)item).SHA384;
|
||||
sha512 = ((Rom)item).SHA512;
|
||||
size = ((Rom)item).Size.ToString();
|
||||
}
|
||||
else if (item.Type == ItemType.Disk)
|
||||
{
|
||||
md5 = ((Disk)item).MD5;
|
||||
sha1 = ((Disk)item).SHA1;
|
||||
sha256 = ((Disk)item).SHA256;
|
||||
sha384 = ((Disk)item).SHA384;
|
||||
sha512 = ((Disk)item).SHA512;
|
||||
}
|
||||
|
||||
// Now do bulk replacement where possible
|
||||
fix = fix
|
||||
.Replace("%game%", game)
|
||||
.Replace("%machine%", game)
|
||||
.Replace("%name%", name)
|
||||
.Replace("%manufacturer%", manufacturer)
|
||||
.Replace("%publisher%", publisher)
|
||||
.Replace("%crc%", crc)
|
||||
.Replace("%md5%", md5)
|
||||
.Replace("%sha1%", sha1)
|
||||
.Replace("%sha256%", sha256)
|
||||
.Replace("%sha384%", sha384)
|
||||
.Replace("%sha512%", sha512)
|
||||
.Replace("%size%", size);
|
||||
|
||||
return fix;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion // Instance Methods
|
||||
|
||||
@@ -155,81 +155,8 @@ namespace SabreTools.Library.DatFiles
|
||||
try
|
||||
{
|
||||
string state = "", name = "", pre = "", post = "";
|
||||
pre = Prefix + (Quotes ? "\"" : "");
|
||||
post = (Quotes ? "\"" : "") + Postfix;
|
||||
|
||||
if (rom.Type == ItemType.Rom)
|
||||
{
|
||||
// Check for special strings in prefix and postfix
|
||||
pre = pre
|
||||
.Replace("%game%", rom.MachineName)
|
||||
.Replace("%name%", rom.Name)
|
||||
.Replace("%crc%", ((Rom)rom).CRC)
|
||||
.Replace("%md5%", ((Rom)rom).MD5)
|
||||
.Replace("%sha1%", ((Rom)rom).SHA1)
|
||||
.Replace("%sha256%", ((Rom)rom).SHA256)
|
||||
.Replace("%sha384%", ((Rom)rom).SHA384)
|
||||
.Replace("%sha512%", ((Rom)rom).SHA512)
|
||||
.Replace("%size%", ((Rom)rom).Size.ToString());
|
||||
post = post
|
||||
.Replace("%game%", rom.MachineName)
|
||||
.Replace("%name%", rom.Name)
|
||||
.Replace("%crc%", ((Rom)rom).CRC)
|
||||
.Replace("%md5%", ((Rom)rom).MD5)
|
||||
.Replace("%sha1%", ((Rom)rom).SHA1)
|
||||
.Replace("%sha256%", ((Rom)rom).SHA256)
|
||||
.Replace("%sha384%", ((Rom)rom).SHA384)
|
||||
.Replace("%sha512%", ((Rom)rom).SHA512)
|
||||
.Replace("%size%", ((Rom)rom).Size.ToString());
|
||||
}
|
||||
else if (rom.Type == ItemType.Disk)
|
||||
{
|
||||
// Check for special strings in prefix and postfix
|
||||
pre = pre
|
||||
.Replace("%game%", rom.MachineName)
|
||||
.Replace("%name%", rom.Name)
|
||||
.Replace("%crc%", string.Empty)
|
||||
.Replace("%md5%", ((Disk)rom).MD5)
|
||||
.Replace("%sha1%", ((Disk)rom).SHA1)
|
||||
.Replace("%sha256%", ((Disk)rom).SHA256)
|
||||
.Replace("%sha384%", ((Disk)rom).SHA384)
|
||||
.Replace("%sha512%", ((Disk)rom).SHA512)
|
||||
.Replace("%size%", string.Empty);
|
||||
post = post
|
||||
.Replace("%game%", rom.MachineName)
|
||||
.Replace("%name%", rom.Name)
|
||||
.Replace("%crc%", string.Empty)
|
||||
.Replace("%md5%", ((Disk)rom).MD5)
|
||||
.Replace("%sha1%", ((Disk)rom).SHA1)
|
||||
.Replace("%sha256%", ((Disk)rom).SHA256)
|
||||
.Replace("%sha384%", ((Disk)rom).SHA384)
|
||||
.Replace("%sha512%", ((Disk)rom).SHA512)
|
||||
.Replace("%size%", string.Empty);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Check for special strings in prefix and postfix
|
||||
pre = pre
|
||||
.Replace("%game%", rom.MachineName)
|
||||
.Replace("%name%", rom.Name)
|
||||
.Replace("%crc%", string.Empty)
|
||||
.Replace("%md5%", string.Empty)
|
||||
.Replace("%sha1%", string.Empty)
|
||||
.Replace("%sha256%", string.Empty)
|
||||
.Replace("%sha384%", string.Empty)
|
||||
.Replace("%sha512%", string.Empty)
|
||||
.Replace("%size%", string.Empty);
|
||||
post = post
|
||||
.Replace("%game%", rom.MachineName)
|
||||
.Replace("%name%", rom.Name)
|
||||
.Replace("%crc%", string.Empty)
|
||||
.Replace("%md5%", string.Empty)
|
||||
.Replace("%sha1%", string.Empty)
|
||||
.Replace("%sha256%", string.Empty)
|
||||
.Replace("%sha384%", string.Empty)
|
||||
.Replace("%sha512%", string.Empty)
|
||||
.Replace("%size%", string.Empty);
|
||||
}
|
||||
pre = CreatePrefixPostfix(rom, true);
|
||||
post = CreatePrefixPostfix(rom, false);
|
||||
|
||||
// If we're in Romba mode, the state is consistent
|
||||
if (Romba)
|
||||
|
||||
@@ -458,75 +458,8 @@ namespace SabreTools.Library.DatFiles
|
||||
return true;
|
||||
}
|
||||
|
||||
pre = Prefix + (Quotes ? "\"" : "");
|
||||
post = (Quotes ? "\"" : "") + Postfix;
|
||||
|
||||
if (rom.Type == ItemType.Rom)
|
||||
{
|
||||
// Check for special strings in prefix and postfix
|
||||
pre = pre
|
||||
.Replace("%game%", rom.MachineName)
|
||||
.Replace("%name%", rom.Name)
|
||||
.Replace("%crc%", ((Rom)rom).CRC)
|
||||
.Replace("%md5%", ((Rom)rom).MD5)
|
||||
.Replace("%sha1%", ((Rom)rom).SHA1)
|
||||
.Replace("%sha256%", ((Rom)rom).SHA256)
|
||||
.Replace("%sha384%", ((Rom)rom).SHA384)
|
||||
.Replace("%sha512%", ((Rom)rom).SHA512)
|
||||
.Replace("%size%", ((Rom)rom).Size.ToString());
|
||||
post = post
|
||||
.Replace("%game%", rom.MachineName)
|
||||
.Replace("%name%", rom.Name)
|
||||
.Replace("%crc%", ((Rom)rom).CRC)
|
||||
.Replace("%md5%", ((Rom)rom).MD5)
|
||||
.Replace("%sha1%", ((Rom)rom).SHA1)
|
||||
.Replace("%sha256%", ((Rom)rom).SHA256)
|
||||
.Replace("%sha384%", ((Rom)rom).SHA384)
|
||||
.Replace("%sha512%", ((Rom)rom).SHA512)
|
||||
.Replace("%size%", ((Rom)rom).Size.ToString());
|
||||
}
|
||||
else if (rom.Type == ItemType.Disk)
|
||||
{
|
||||
// Check for special strings in prefix and postfix
|
||||
pre = pre
|
||||
.Replace("%game%", rom.MachineName)
|
||||
.Replace("%name%", rom.Name)
|
||||
.Replace("%crc%", string.Empty)
|
||||
.Replace("%md5%", ((Disk)rom).MD5)
|
||||
.Replace("%sha1%", ((Disk)rom).SHA1)
|
||||
.Replace("%sha256%", ((Disk)rom).SHA256)
|
||||
.Replace("%sha384%", ((Disk)rom).SHA384)
|
||||
.Replace("%sha512%", ((Disk)rom).SHA512)
|
||||
.Replace("%size%", string.Empty); ;
|
||||
post = post
|
||||
.Replace("%game%", rom.MachineName)
|
||||
.Replace("%name%", rom.Name)
|
||||
.Replace("%crc%", string.Empty)
|
||||
.Replace("%md5%", ((Disk)rom).MD5)
|
||||
.Replace("%sha1%", ((Disk)rom).SHA1)
|
||||
.Replace("%sha256%", ((Disk)rom).SHA256)
|
||||
.Replace("%sha384%", ((Disk)rom).SHA384)
|
||||
.Replace("%sha512%", ((Disk)rom).SHA512)
|
||||
.Replace("%size%", string.Empty); ;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Check for special strings in prefix and postfix
|
||||
pre = pre
|
||||
.Replace("%game%", rom.MachineName)
|
||||
.Replace("%name%", rom.Name)
|
||||
.Replace("%crc%", string.Empty)
|
||||
.Replace("%md5%", string.Empty)
|
||||
.Replace("%sha1%", string.Empty)
|
||||
.Replace("%size%", string.Empty);
|
||||
post = post
|
||||
.Replace("%game%", rom.MachineName)
|
||||
.Replace("%name%", rom.Name)
|
||||
.Replace("%crc%", string.Empty)
|
||||
.Replace("%md5%", string.Empty)
|
||||
.Replace("%sha1%", string.Empty)
|
||||
.Replace("%size%", string.Empty);
|
||||
}
|
||||
pre = CreatePrefixPostfix(rom, true);
|
||||
post = CreatePrefixPostfix(rom, false);
|
||||
|
||||
if (rom.Type == ItemType.Rom)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user