More 0-byte file shennanigans

This commit is contained in:
Matt Nadareski
2016-05-06 12:56:02 -07:00
parent ced41c5cde
commit a7f97cc419
2 changed files with 23 additions and 1 deletions

View File

@@ -95,7 +95,7 @@ namespace SabreTools.Helper
if (old)
{
state += "\t" + rom.Type + " ( name \"" + rom.Name + "\"" +
(rom.Size != 0 ? " size " + rom.Size : "") +
(rom.Size != -1 ? " size " + rom.Size : "") +
(rom.CRC != "" ? " crc " + rom.CRC.ToLowerInvariant() : "") +
(rom.MD5 != "" ? " md5 " + rom.MD5.ToLowerInvariant() : "") +
(rom.SHA1 != "" ? " sha1 " + rom.SHA1.ToLowerInvariant() : "") +

View File

@@ -10,6 +10,12 @@ namespace SabreTools.Helper
{
public class RomManipulation
{
// 0-byte file constants
private static long sizezero = 0;
private static string crczero = "00000000";
private static string md5zero = "d41d8cd98f00b204e9800998ecf8427e";
private static string sha1zero = "da39a3ee5e6b4b0d3255bfef95601890afd80709";
/// <summary>
/// Return if the file is XML or not
/// </summary>
@@ -450,6 +456,7 @@ namespace SabreTools.Helper
// If the rom is nodump, skip it
if (xtr.GetAttribute("flags") == "nodump" || xtr.GetAttribute("status") == "nodump")
{
logger.Log("Nodump detected");
break;
}
@@ -475,6 +482,21 @@ namespace SabreTools.Helper
sha1 = (sha1.StartsWith("0x") ? sha1.Remove(0, 2) : sha1);
sha1 = (sha1 == "-" ? "" : sha1);
// If we have a rom and it's missing size AND the hashes match a 0-byte file, fill in the rest of the info
if (subreader.Name == "rom" && size == 0 && (crc == crczero || md5 == md5zero || sha1 == sha1zero))
{
size = 0;
crc = crczero;
md5 = md5zero;
sha1 = sha1zero;
}
// If the file has no size and it's not the above case, skip and log
else if (subreader.Name == "rom" && size == 0)
{
logger.Warning("Potentially incomplete entry found for " + xtr.GetAttribute("name"));
break;
}
// Only add the rom if there's useful information in it
if (!(crc == "" && md5 == "" && sha1 == ""))
{