Fix RomVault-style dir2dat

The previous version was skipping over all secondary directories because of poor previous programming. This fixes the issues found with those DATs.
This commit is contained in:
Matt Nadareski
2016-05-19 10:56:36 -07:00
parent 41063921f2
commit 2aabeefc5b

View File

@@ -111,8 +111,10 @@ namespace SabreTools.Helper
if (xtr != null) if (xtr != null)
{ {
xtr.MoveToContent(); xtr.MoveToContent();
while (xtr.NodeType != XmlNodeType.None) while (!xtr.EOF) //xtr.NodeType != XmlNodeType.None
{ {
Console.WriteLine(xtr.Name + " " + xtr.NodeType);
// If we're ending a folder or game, take care of possibly empty games and removing from the parent // If we're ending a folder or game, take care of possibly empty games and removing from the parent
if (xtr.NodeType == XmlNodeType.EndElement && (xtr.Name == "directory" || xtr.Name == "dir")) if (xtr.NodeType == XmlNodeType.EndElement && (xtr.Name == "directory" || xtr.Name == "dir"))
{ {
@@ -143,7 +145,11 @@ namespace SabreTools.Helper
} }
// Regardless, end the current folder // Regardless, end the current folder
empty = true; if (parent.Count == 0)
{
Console.WriteLine("Empty parent: " + String.Join("\\", parent));
empty = true;
}
// If we have an end folder element, remove one item from the parent, if possible // If we have an end folder element, remove one item from the parent, if possible
if (parent.Count > 0) if (parent.Count > 0)
@@ -156,15 +162,11 @@ namespace SabreTools.Helper
} }
} }
// We only want elements // We only want elements
if (xtr.NodeType != XmlNodeType.Element) if (xtr.NodeType != XmlNodeType.Element)
{ {
if (xtr.Read()) xtr.Read();
{ continue;
continue;
}
break;
} }
switch (xtr.Name) switch (xtr.Name)
@@ -412,7 +414,7 @@ namespace SabreTools.Helper
// Get the name of the game from the parent // Get the name of the game from the parent
else if (superdat && keep && parent.Count > 0) else if (superdat && keep && parent.Count > 0)
{ {
tempname = String.Join("\\", parent) + "\\" + tempname; tempname = String.Join("\\", parent) + "\\" + tempname;
} }
@@ -563,13 +565,19 @@ namespace SabreTools.Helper
} }
// Regardless, end the current folder // Regardless, end the current folder
empty = true; if (parent.Count == 0)
{
empty = true;
}
xtr.Skip();
// Read to next game /*
if (!xtr.ReadToNextSibling(temptype)) // Read to next game, folder, or dir
if (!xtr.ReadToFollowing(temptype))
{ {
shouldbreak = true; shouldbreak = true;
} }
*/
break; break;
case "dir": case "dir":
case "directory": case "directory":
@@ -585,6 +593,7 @@ namespace SabreTools.Helper
{ {
parent.Add(foldername); parent.Add(foldername);
} }
xtr.Read(); xtr.Read();
break; break;
case "file": case "file":