mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Fix handling of native XML files
This commit is contained in:
@@ -252,79 +252,85 @@ namespace DATabase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attempt to open the given file
|
// Attempt to load the current file as XML
|
||||||
|
XmlDocument doc = new XmlDocument();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
FileStream fs = File.OpenRead(_filepath);
|
doc.LoadXml(File.ReadAllText(_filepath));
|
||||||
StreamReader sr = new StreamReader(fs);
|
}
|
||||||
|
catch (XmlException ex)
|
||||||
|
{
|
||||||
|
doc.LoadXml(Converters.RomVaultToXML(File.ReadAllLines(_filepath)).ToString());
|
||||||
|
}
|
||||||
|
|
||||||
XmlDocument doc = new XmlDocument();
|
// Experimental looping using only XML parsing
|
||||||
try
|
XmlNode node = doc.FirstChild;
|
||||||
{
|
if (node != null && node.Name == "xml")
|
||||||
doc.LoadXml(sr.ReadToEnd());
|
{
|
||||||
}
|
node = node.NextSibling;
|
||||||
catch (XmlException ex)
|
}
|
||||||
{
|
if (node != null && node.Name == "softwarelist")
|
||||||
doc.LoadXml(Converters.RomVaultToXML(File.ReadAllLines(_filepath)).ToString());
|
{
|
||||||
}
|
node = node.NextSibling;
|
||||||
|
}
|
||||||
|
if (node != null && (node.Name == "datafile" || node.Name == "softwarelist"))
|
||||||
|
{
|
||||||
|
node = node.FirstChild;
|
||||||
|
}
|
||||||
|
if (node != null && node.Name == "header")
|
||||||
|
{
|
||||||
|
node = node.NextSibling;
|
||||||
|
}
|
||||||
|
|
||||||
// Experimental looping using only XML parsing
|
while (node != null)
|
||||||
XmlNode node = doc.FirstChild.FirstChild;
|
{
|
||||||
if (node.Name == "header")
|
if (node.Name == "machine" || node.Name == "game" || node.Name == "software")
|
||||||
{
|
{
|
||||||
node = node.NextSibling;
|
long gameid = AddGame(sysid, node.Attributes["name"].Value, srcid);
|
||||||
}
|
|
||||||
|
|
||||||
while (node != null)
|
// Get the roms from the machine
|
||||||
{
|
if (node.HasChildNodes)
|
||||||
if (node.Name == "machine" || node.Name == "game" || node.Name == "software")
|
|
||||||
{
|
{
|
||||||
long gameid = AddGame(sysid, node.Attributes["name"].Value, srcid);
|
// If this node has children, traverse the children
|
||||||
|
foreach (XmlNode child in node.ChildNodes)
|
||||||
// Get the roms from the machine
|
|
||||||
if (node.HasChildNodes)
|
|
||||||
{
|
{
|
||||||
// If this node has children, traverse the children
|
// If we find a rom or disk, add it
|
||||||
foreach (XmlNode child in node.ChildNodes)
|
if (child.Name == "rom" || child.Name == "disk")
|
||||||
{
|
{
|
||||||
// If we find a rom or disk, add it
|
AddRomHelper(
|
||||||
if (child.Name == "rom" || child.Name == "disk")
|
child.Name,
|
||||||
|
gameid,
|
||||||
|
child.Attributes["name"].Value,
|
||||||
|
date,
|
||||||
|
(child.Attributes["size"].Value != "" ? Int32.Parse(child.Attributes["size"].Value) : -1),
|
||||||
|
(child.Attributes["crc"].Value != "" ? child.Attributes["crc"].Value : ""),
|
||||||
|
(child.Attributes["md5"].Value != "" ? child.Attributes["md5"].Value : ""),
|
||||||
|
(child.Attributes["sha1"].Value != "" ? child.Attributes["sha1"].Value : "")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
// If we find the signs of a software list, traverse the children
|
||||||
|
else if (child.Name == "part" && child.HasChildNodes)
|
||||||
|
{
|
||||||
|
foreach (XmlNode part in child.ChildNodes)
|
||||||
{
|
{
|
||||||
AddRomHelper(
|
// If we find a dataarea, traverse the children
|
||||||
child.Name,
|
if (part.Name == "dataarea")
|
||||||
gameid,
|
|
||||||
child.Attributes["name"].Value,
|
|
||||||
date,
|
|
||||||
(child.Attributes["size"].Value != "" ? Int32.Parse(child.Attributes["size"].Value) : -1),
|
|
||||||
(child.Attributes["crc"].Value != "" ? child.Attributes["crc"].Value : ""),
|
|
||||||
(child.Attributes["md5"].Value != "" ? child.Attributes["md5"].Value : ""),
|
|
||||||
(child.Attributes["sha1"].Value != "" ? child.Attributes["sha1"].Value : "")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
// If we find the signs of a software list, traverse the children
|
|
||||||
else if (child.Name == "part" && child.HasChildNodes)
|
|
||||||
{
|
|
||||||
foreach (XmlNode part in child.ChildNodes)
|
|
||||||
{
|
{
|
||||||
// If we find a dataarea, traverse the children
|
foreach (XmlNode data in part.ChildNodes)
|
||||||
if (part.Name == "dataarea")
|
|
||||||
{
|
{
|
||||||
foreach (XmlNode data in part.ChildNodes)
|
// If we find a rom or disk, add it
|
||||||
|
if (data.Name == "rom" || data.Name == "disk")
|
||||||
{
|
{
|
||||||
// If we find a rom or disk, add it
|
AddRomHelper(
|
||||||
if (data.Name == "rom" || data.Name == "disk")
|
data.Name,
|
||||||
{
|
gameid,
|
||||||
AddRomHelper(
|
data.Attributes["name"].Value,
|
||||||
data.Name,
|
date,
|
||||||
gameid,
|
(data.Attributes["size"] != null ? Int32.Parse(data.Attributes["size"].Value) : -1),
|
||||||
data.Attributes["name"].Value,
|
(data.Attributes["crc"] != null ? data.Attributes["crc"].Value : ""),
|
||||||
date,
|
(data.Attributes["md5"] != null ? data.Attributes["md5"].Value : ""),
|
||||||
(data.Attributes["size"].Value != "" ? Int32.Parse(data.Attributes["size"].Value) : -1),
|
(data.Attributes["sha1"] != null ? data.Attributes["sha1"].Value : "")
|
||||||
(data.Attributes["crc"].Value != "" ? data.Attributes["crc"].Value : ""),
|
);
|
||||||
(data.Attributes["md5"].Value != "" ? data.Attributes["md5"].Value : ""),
|
|
||||||
(data.Attributes["sha1"].Value != "" ? data.Attributes["sha1"].Value : "")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -332,16 +338,8 @@ namespace DATabase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
node = node.NextSibling;
|
|
||||||
}
|
}
|
||||||
|
node = node.NextSibling;
|
||||||
sr.Close();
|
|
||||||
fs.Close();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Console.WriteLine(ex);
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user