Take care of case of software tag ONLY having roms inside after the description.

This is rare and probably not seen too much in many softlists, but it is a possible issue, and must be addressed.
This commit is contained in:
Matt Nadareski
2016-05-22 17:24:19 -07:00
parent ccdb809a44
commit 96b8880bcb

View File

@@ -155,7 +155,7 @@ namespace SabreTools.Helper
int parentcount = parent.Count; int parentcount = parent.Count;
if (parentcount == 0) if (parentcount == 0)
{ {
Console.WriteLine("Empty parent: " + String.Join("\\", parent)); logger.Log("Empty parent: " + String.Join("\\", parent));
empty = true; empty = true;
} }
@@ -397,12 +397,17 @@ namespace SabreTools.Helper
// We want to process the entire subtree of the game // We want to process the entire subtree of the game
subreader = xtr.ReadSubtree(); subreader = xtr.ReadSubtree();
// Safeguard for interesting case of "software" without anything except roms
bool software = false;
// If we have a subtree, add what is possible
if (subreader != null) if (subreader != null)
{ {
if (temptype == "software" && subreader.ReadToFollowing("description")) if (temptype == "software" && subreader.ReadToFollowing("description"))
{ {
tempname = subreader.ReadElementContentAsString(); tempname = subreader.ReadElementContentAsString();
tempname = tempname.Replace('/', '_').Replace("\"", "''"); tempname = tempname.Replace('/', '_').Replace("\"", "''");
software = true;
} }
else else
{ {
@@ -410,7 +415,7 @@ namespace SabreTools.Helper
if (xtr.AttributeCount == 0) if (xtr.AttributeCount == 0)
{ {
logger.Error("No attributes were found"); logger.Error("No attributes were found");
subreader.Skip(); xtr.Skip();
continue; continue;
} }
tempname = xtr.GetAttribute("name"); tempname = xtr.GetAttribute("name");
@@ -430,8 +435,10 @@ namespace SabreTools.Helper
tempname = String.Join("\\", parent) + "\\" + tempname; tempname = String.Join("\\", parent) + "\\" + tempname;
} }
while (subreader.Read()) while (software || subreader.Read())
{ {
software = false;
// We only want elements // We only want elements
if (subreader.NodeType != XmlNodeType.Element) if (subreader.NodeType != XmlNodeType.Element)
{ {
@@ -539,8 +546,8 @@ namespace SabreTools.Helper
RomData value = new RomData RomData value = new RomData
{ {
Game = tempname, Game = tempname,
Name = xtr.GetAttribute("name"), Name = subreader.GetAttribute("name"),
Type = xtr.Name, Type = subreader.Name,
SystemID = sysid, SystemID = sysid,
SourceID = srcid, SourceID = srcid,
Size = size, Size = size,
@@ -563,6 +570,11 @@ namespace SabreTools.Helper
datdata.Roms.Add(key, newvalue); datdata.Roms.Add(key, newvalue);
} }
} }
// Otherwise, log that it wasn't added
else
{
logger.Log("Rom was not added: '" + xtr.GetAttribute("name") + "'");
}
break; break;
} }
} }
@@ -829,6 +841,13 @@ namespace SabreTools.Helper
// Then, deduplicate them by checking to see if data matches // Then, deduplicate them by checking to see if data matches
foreach (RomData rom in inroms) foreach (RomData rom in inroms)
{ {
// If it's a nodump, add and skip
if (rom.Nodump)
{
outroms.Add(rom);
continue;
}
// If it's the first rom in the list, don't touch it // If it's the first rom in the list, don't touch it
if (outroms.Count != 0) if (outroms.Count != 0)
{ {
@@ -840,6 +859,12 @@ namespace SabreTools.Helper
{ {
RomData lastrom = outroms[i]; RomData lastrom = outroms[i];
// If last is a nodump, skip it
if (lastrom.Nodump)
{
continue;
}
if (rom.Type == "rom" && lastrom.Type == "rom") if (rom.Type == "rom" && lastrom.Type == "rom")
{ {
dupefound = ((rom.Size == lastrom.Size) && dupefound = ((rom.Size == lastrom.Size) &&