Adding Date to official specification, fix SabreDAT output

Secondary fix: how on Earth did reading from a game/rom formatted XML DAT not explode? It was using "xtr" instead of "subreader" for everything...
This commit is contained in:
Matt Nadareski
2016-05-20 10:21:24 -07:00
parent daa41d1923
commit de9f3d6ac8
3 changed files with 38 additions and 16 deletions

View File

@@ -275,6 +275,7 @@ namespace SabreTools.Helper
(rom.CRC != "" ? " crc " + rom.CRC.ToLowerInvariant() : "") + (rom.CRC != "" ? " crc " + rom.CRC.ToLowerInvariant() : "") +
(rom.MD5 != "" ? " md5 " + rom.MD5.ToLowerInvariant() : "") + (rom.MD5 != "" ? " md5 " + rom.MD5.ToLowerInvariant() : "") +
(rom.SHA1 != "" ? " sha1 " + rom.SHA1.ToLowerInvariant() : "") + (rom.SHA1 != "" ? " sha1 " + rom.SHA1.ToLowerInvariant() : "") +
(rom.Date != "" ? " date \"" + rom.Date + "\"" : "") +
(rom.Nodump ? " flags nodump" : "") + (rom.Nodump ? " flags nodump" : "") +
" )\n"; " )\n";
break; break;
@@ -332,17 +333,20 @@ namespace SabreTools.Helper
"¬" + (rom.Size != -1 ? rom.Size.ToString() : "") + "¬¬¬\n"; "¬" + (rom.Size != -1 ? rom.Size.ToString() : "") + "¬¬¬\n";
break; break;
case OutputFormat.SabreDat: case OutputFormat.SabreDat:
string prefix = "";
for (int i = 0; i < depth; i++) for (int i = 0; i < depth; i++)
{ {
state += "\t"; prefix += "\t";
} }
state += prefix;
state += "<file type=\"" + rom.Type + "\" name=\"" + HttpUtility.HtmlEncode(rom.Name) + "\"" + state += "<file type=\"" + rom.Type + "\" name=\"" + HttpUtility.HtmlEncode(rom.Name) + "\"" +
(rom.Size != -1 ? " size=\"" + rom.Size + "\"" : "") + (rom.Size != -1 ? " size=\"" + rom.Size + "\"" : "") +
(rom.CRC != "" ? " crc=\"" + rom.CRC.ToLowerInvariant() + "\"" : "") + (rom.CRC != "" ? " crc=\"" + rom.CRC.ToLowerInvariant() + "\"" : "") +
(rom.MD5 != "" ? " md5=\"" + rom.MD5.ToLowerInvariant() + "\"" : "") + (rom.MD5 != "" ? " md5=\"" + rom.MD5.ToLowerInvariant() + "\"" : "") +
(rom.SHA1 != "" ? " sha1=\"" + rom.SHA1.ToLowerInvariant() + "\"" : "") + (rom.SHA1 != "" ? " sha1=\"" + rom.SHA1.ToLowerInvariant() + "\"" : "") +
(rom.Nodump ? " status=\"nodump\"" : "") + (rom.Date != "" ? " date=\"" + rom.Date + "\"" : "") +
"/>\n"; (rom.Nodump ? prefix + "/>\n\t<flags>\n" + prefix + "\t\t<flag name=\"status\" value=\"nodump\"/>\n" + prefix + "\t</flags>\n" + prefix + "</file>" : "/>\n");
break; break;
case OutputFormat.Xml: case OutputFormat.Xml:
state += "\t\t<" + rom.Type + " name=\"" + HttpUtility.HtmlEncode(rom.Name) + "\"" + state += "\t\t<" + rom.Type + " name=\"" + HttpUtility.HtmlEncode(rom.Name) + "\"" +
@@ -350,6 +354,7 @@ namespace SabreTools.Helper
(rom.CRC != "" ? " crc=\"" + rom.CRC.ToLowerInvariant() + "\"" : "") + (rom.CRC != "" ? " crc=\"" + rom.CRC.ToLowerInvariant() + "\"" : "") +
(rom.MD5 != "" ? " md5=\"" + rom.MD5.ToLowerInvariant() + "\"" : "") + (rom.MD5 != "" ? " md5=\"" + rom.MD5.ToLowerInvariant() + "\"" : "") +
(rom.SHA1 != "" ? " sha1=\"" + rom.SHA1.ToLowerInvariant() + "\"" : "") + (rom.SHA1 != "" ? " sha1=\"" + rom.SHA1.ToLowerInvariant() + "\"" : "") +
(rom.Date != "" ? " date=\"" + rom.Date + "\"" : "") +
(rom.Nodump ? " status=\"nodump\"" : "") + (rom.Nodump ? " status=\"nodump\"" : "") +
"/>\n"; "/>\n";
break; break;

View File

@@ -103,7 +103,7 @@ namespace SabreTools.Helper
// Prepare all internal variables // Prepare all internal variables
XmlReader subreader, headreader, flagreader; XmlReader subreader, headreader, flagreader;
bool superdat = false, nodump = false, empty = true; bool superdat = false, nodump = false, empty = true;
string key = "", crc = "", md5 = "", sha1 = ""; string key = "", crc = "", md5 = "", sha1 = "", date = "";
long size = -1; long size = -1;
List<string> parent = new List<string>(); List<string> parent = new List<string>();
@@ -400,7 +400,7 @@ namespace SabreTools.Helper
if (xtr.AttributeCount == 0) if (xtr.AttributeCount == 0)
{ {
logger.Error("No attributes were found"); logger.Error("No attributes were found");
xtr.ReadToNextSibling(xtr.Name); subreader.Skip();
continue; continue;
} }
tempname = xtr.GetAttribute("name"); tempname = xtr.GetAttribute("name");
@@ -437,26 +437,33 @@ namespace SabreTools.Helper
// If the rom is nodump, flag it // If the rom is nodump, flag it
nodump = false; nodump = false;
if (xtr.GetAttribute("flags") == "nodump" || xtr.GetAttribute("status") == "nodump") if (subreader.GetAttribute("flags") == "nodump" || subreader.GetAttribute("status") == "nodump")
{ {
logger.Log("Nodump detected: " + logger.Log("Nodump detected: " +
(xtr.GetAttribute("name") != null && xtr.GetAttribute("name") != "" ? "\"" + xtr.GetAttribute("name") + "\"" : "ROM NAME NOT FOUND")); (subreader.GetAttribute("name") != null && subreader.GetAttribute("name") != "" ? "\"" + xtr.GetAttribute("name") + "\"" : "ROM NAME NOT FOUND"));
nodump = true; nodump = true;
} }
// If the rom has a Date attached, read it in and then sanitize it
date = "";
if (subreader.GetAttribute("date") != null)
{
date = DateTime.Parse(subreader.GetAttribute("date")).ToString();
}
// Take care of hex-sized files // Take care of hex-sized files
size = -1; size = -1;
if (xtr.GetAttribute("size") != null && xtr.GetAttribute("size").Contains("0x")) if (subreader.GetAttribute("size") != null && subreader.GetAttribute("size").Contains("0x"))
{ {
size = Convert.ToInt64(xtr.GetAttribute("size"), 16); size = Convert.ToInt64(subreader.GetAttribute("size"), 16);
} }
else if (xtr.GetAttribute("size") != null) else if (subreader.GetAttribute("size") != null)
{ {
Int64.TryParse(xtr.GetAttribute("size"), out size); Int64.TryParse(subreader.GetAttribute("size"), out size);
} }
// If the rom is continue or ignore, add the size to the previous rom // If the rom is continue or ignore, add the size to the previous rom
if (xtr.GetAttribute("loadflag") == "continue" || xtr.GetAttribute("loadflag") == "ignore") if (subreader.GetAttribute("loadflag") == "continue" || subreader.GetAttribute("loadflag") == "ignore")
{ {
int index = datdata.Roms[key].Count() - 1; int index = datdata.Roms[key].Count() - 1;
RomData lastrom = datdata.Roms[key][index]; RomData lastrom = datdata.Roms[key][index];
@@ -467,15 +474,15 @@ namespace SabreTools.Helper
} }
// Sanitize the hashes from null, hex sizes, and "true blank" strings // Sanitize the hashes from null, hex sizes, and "true blank" strings
crc = (xtr.GetAttribute("crc") != null ? xtr.GetAttribute("crc").ToLowerInvariant().Trim() : ""); crc = (subreader.GetAttribute("crc") != null ? subreader.GetAttribute("crc").ToLowerInvariant().Trim() : "");
crc = (crc.StartsWith("0x") ? crc.Remove(0, 2) : crc); crc = (crc.StartsWith("0x") ? crc.Remove(0, 2) : crc);
crc = (crc == "-" ? "" : crc); crc = (crc == "-" ? "" : crc);
crc = (crc == "" ? "" : crc.PadLeft(8, '0')); crc = (crc == "" ? "" : crc.PadLeft(8, '0'));
md5 = (xtr.GetAttribute("md5") != null ? xtr.GetAttribute("md5").ToLowerInvariant().Trim() : ""); md5 = (subreader.GetAttribute("md5") != null ? subreader.GetAttribute("md5").ToLowerInvariant().Trim() : "");
md5 = (md5.StartsWith("0x") ? md5.Remove(0, 2) : md5); md5 = (md5.StartsWith("0x") ? md5.Remove(0, 2) : md5);
md5 = (md5 == "-" ? "" : md5); md5 = (md5 == "-" ? "" : md5);
md5 = (md5 == "" ? "" : md5.PadLeft(32, '0')); md5 = (md5 == "" ? "" : md5.PadLeft(32, '0'));
sha1 = (xtr.GetAttribute("sha1") != null ? xtr.GetAttribute("sha1").ToLowerInvariant().Trim() : ""); sha1 = (subreader.GetAttribute("sha1") != null ? subreader.GetAttribute("sha1").ToLowerInvariant().Trim() : "");
sha1 = (sha1.StartsWith("0x") ? sha1.Remove(0, 2) : sha1); sha1 = (sha1.StartsWith("0x") ? sha1.Remove(0, 2) : sha1);
sha1 = (sha1 == "-" ? "" : sha1); sha1 = (sha1 == "-" ? "" : sha1);
sha1 = (sha1 == "" ? "" : sha1.PadLeft(40, '0')); sha1 = (sha1 == "" ? "" : sha1.PadLeft(40, '0'));
@@ -491,7 +498,7 @@ namespace SabreTools.Helper
// If the file has no size and it's not the above case, skip and log // If the file has no size and it's not the above case, skip and log
else if (subreader.Name == "rom" && (size == 0 || size == -1)) else if (subreader.Name == "rom" && (size == 0 || size == -1))
{ {
logger.Warning("Incomplete entry for \"" + xtr.GetAttribute("name") + "\" will be output as nodump"); logger.Warning("Incomplete entry for \"" + subreader.GetAttribute("name") + "\" will be output as nodump");
nodump = true; nodump = true;
} }
@@ -520,6 +527,7 @@ namespace SabreTools.Helper
SHA1 = sha1, SHA1 = sha1,
System = filename, System = filename,
Nodump = nodump, Nodump = nodump,
Date = date,
}; };
if (datdata.Roms.ContainsKey(key)) if (datdata.Roms.ContainsKey(key))
@@ -630,6 +638,13 @@ namespace SabreTools.Helper
} }
} }
// If the rom has a Date attached, read it in and then sanitize it
date = "";
if (xtr.GetAttribute("date") != null)
{
date = DateTime.Parse(xtr.GetAttribute("date")).ToString();
}
// Take care of hex-sized files // Take care of hex-sized files
size = -1; size = -1;
if (xtr.GetAttribute("size") != null && xtr.GetAttribute("size").Contains("0x")) if (xtr.GetAttribute("size") != null && xtr.GetAttribute("size").Contains("0x"))
@@ -719,6 +734,7 @@ namespace SabreTools.Helper
SHA1 = sha1, SHA1 = sha1,
System = filename, System = filename,
Nodump = nodump, Nodump = nodump,
Date = date,
}; };
if (datdata.Roms.ContainsKey(key)) if (datdata.Roms.ContainsKey(key))

View File

@@ -22,6 +22,7 @@ namespace SabreTools.Helper
public string SHA1; public string SHA1;
public DupeType Dupe; public DupeType Dupe;
public bool Nodump; public bool Nodump;
public string Date;
} }
/// <summary> /// <summary>