mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Handle blank folders in DATFromDir and output alike
This commit is contained in:
@@ -249,10 +249,67 @@ namespace SabreTools
|
|||||||
_basePath = Path.GetFullPath(_basePath);
|
_basePath = Path.GetFullPath(_basePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool items = false;
|
||||||
foreach (string subitem in Directory.EnumerateFiles(item, "*", SearchOption.AllDirectories))
|
foreach (string subitem in Directory.EnumerateFiles(item, "*", SearchOption.AllDirectories))
|
||||||
{
|
{
|
||||||
|
items = true;
|
||||||
ProcessFile(subitem);
|
ProcessFile(subitem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If there were no subitems, add a "blank" game to to the set
|
||||||
|
if (!items)
|
||||||
|
{
|
||||||
|
RomData rom = new RomData
|
||||||
|
{
|
||||||
|
Name = "null",
|
||||||
|
Game = item.Remove(0, basePathBackup.Length),
|
||||||
|
Size = -1,
|
||||||
|
CRC = "null",
|
||||||
|
MD5 = "null",
|
||||||
|
SHA1 = "null",
|
||||||
|
};
|
||||||
|
|
||||||
|
string key = rom.Size + "-" + rom.CRC;
|
||||||
|
if (_dict.ContainsKey(key))
|
||||||
|
{
|
||||||
|
_dict[key].Add(rom);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
List<RomData> temp = new List<RomData>();
|
||||||
|
temp.Add(rom);
|
||||||
|
_dict.Add(key, temp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now scour subdirectories for empties and add those as well
|
||||||
|
foreach (string subdir in Directory.EnumerateDirectories(item, "*", SearchOption.AllDirectories))
|
||||||
|
{
|
||||||
|
if (Directory.EnumerateFiles(subdir, "*", SearchOption.AllDirectories).Count() == 0)
|
||||||
|
{
|
||||||
|
RomData rom = new RomData
|
||||||
|
{
|
||||||
|
Name = "null",
|
||||||
|
Game = subdir.Remove(0, basePathBackup.Length),
|
||||||
|
Size = -1,
|
||||||
|
CRC = "null",
|
||||||
|
MD5 = "null",
|
||||||
|
SHA1 = "null",
|
||||||
|
};
|
||||||
|
|
||||||
|
string key = rom.Size + "-" + rom.CRC;
|
||||||
|
if (_dict.ContainsKey(key))
|
||||||
|
{
|
||||||
|
_dict[key].Add(rom);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
List<RomData> temp = new List<RomData>();
|
||||||
|
temp.Add(rom);
|
||||||
|
_dict.Add(key, temp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_basePath = basePathBackup;
|
_basePath = basePathBackup;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ namespace SabreTools.Helper
|
|||||||
{
|
{
|
||||||
XElement elem = new XElement("datafile");
|
XElement elem = new XElement("datafile");
|
||||||
|
|
||||||
bool block = false;
|
bool block = false, romfound = false;
|
||||||
for (int k = 0; k < filecontents.Length; k++)
|
for (int k = 0; k < filecontents.Length; k++)
|
||||||
{
|
{
|
||||||
string line = filecontents[k];
|
string line = filecontents[k];
|
||||||
@@ -61,6 +61,7 @@ namespace SabreTools.Helper
|
|||||||
// If the line is a rom or disk and we're in a block
|
// If the line is a rom or disk and we're in a block
|
||||||
else if ((line.Trim().StartsWith("rom (") || line.Trim().StartsWith("disk (")) && block)
|
else if ((line.Trim().StartsWith("rom (") || line.Trim().StartsWith("disk (")) && block)
|
||||||
{
|
{
|
||||||
|
romfound = true;
|
||||||
string[] gc = line.Trim().Split(' ');
|
string[] gc = line.Trim().Split(' ');
|
||||||
|
|
||||||
XElement temp = new XElement(gc[0]);
|
XElement temp = new XElement(gc[0]);
|
||||||
@@ -151,6 +152,7 @@ namespace SabreTools.Helper
|
|||||||
// If we find an end bracket that's not associated with anything else, the block is done
|
// If we find an end bracket that's not associated with anything else, the block is done
|
||||||
else if (Regex.IsMatch(line, _endPatternCMP) && block)
|
else if (Regex.IsMatch(line, _endPatternCMP) && block)
|
||||||
{
|
{
|
||||||
|
romfound = false;
|
||||||
block = false;
|
block = false;
|
||||||
elem = elem.Parent;
|
elem = elem.Parent;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -233,7 +233,14 @@ namespace SabreTools.Helper
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now output the rom data
|
// If we have a "null" game (created by DATFromDir or something similar), skip trying to add a rom
|
||||||
|
if (rom.Name == "null" && rom.Size == -1 && rom.CRC == "null" && rom.MD5 == "null" && rom.SHA1 == "null")
|
||||||
|
{
|
||||||
|
logger.Log("Empty folder found: " + rom.Game);
|
||||||
|
}
|
||||||
|
// Otherwise, output the rom data
|
||||||
|
else
|
||||||
|
{
|
||||||
switch (datdata.OutputFormat)
|
switch (datdata.OutputFormat)
|
||||||
{
|
{
|
||||||
case OutputFormat.ClrMamePro:
|
case OutputFormat.ClrMamePro:
|
||||||
@@ -321,6 +328,7 @@ namespace SabreTools.Helper
|
|||||||
"/>\n";
|
"/>\n";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
splitpath = newsplit;
|
splitpath = newsplit;
|
||||||
lastgame = rom.Game;
|
lastgame = rom.Game;
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ namespace SabreTools.Helper
|
|||||||
{
|
{
|
||||||
// Prepare all internal variables
|
// Prepare all internal variables
|
||||||
XmlReader subreader, headreader, flagreader;
|
XmlReader subreader, headreader, flagreader;
|
||||||
bool superdat = false, shouldbreak = false, nodump = false;
|
bool superdat = false, shouldbreak = false, nodump = false, empty = true;
|
||||||
string key = "", crc = "", md5 = "", sha1 = "";
|
string key = "", crc = "", md5 = "", sha1 = "";
|
||||||
long size = -1;
|
long size = -1;
|
||||||
List<string> parent = new List<string>();
|
List<string> parent = new List<string>();
|
||||||
@@ -113,8 +113,40 @@ namespace SabreTools.Helper
|
|||||||
xtr.MoveToContent();
|
xtr.MoveToContent();
|
||||||
while (xtr.NodeType != XmlNodeType.None)
|
while (xtr.NodeType != XmlNodeType.None)
|
||||||
{
|
{
|
||||||
|
// 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 we didn't find any items in the folder, make sure to add the blank rom
|
||||||
|
if (empty)
|
||||||
|
{
|
||||||
|
RomData rom = new RomData
|
||||||
|
{
|
||||||
|
Name = "null",
|
||||||
|
Game = String.Join("\\", parent),
|
||||||
|
Size = -1,
|
||||||
|
CRC = "null",
|
||||||
|
MD5 = "null",
|
||||||
|
SHA1 = "null",
|
||||||
|
};
|
||||||
|
|
||||||
|
key = rom.Size + "-" + rom.CRC;
|
||||||
|
if (datdata.Roms.ContainsKey(key))
|
||||||
|
{
|
||||||
|
datdata.Roms[key].Add(rom);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
List<RomData> temp = new List<RomData>();
|
||||||
|
temp.Add(rom);
|
||||||
|
datdata.Roms.Add(key, temp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Regardless, end the current folder
|
||||||
|
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 (xtr.NodeType == XmlNodeType.EndElement && (xtr.Name == "directory" || xtr.Name == "dir") && parent.Count > 0)
|
if (parent.Count > 0)
|
||||||
{
|
{
|
||||||
parent.RemoveAt(parent.Count - 1);
|
parent.RemoveAt(parent.Count - 1);
|
||||||
if (keep)
|
if (keep)
|
||||||
@@ -122,6 +154,8 @@ namespace SabreTools.Helper
|
|||||||
datdata.Type = (String.IsNullOrEmpty(datdata.Type) ? "SuperDAT" : datdata.Type);
|
datdata.Type = (String.IsNullOrEmpty(datdata.Type) ? "SuperDAT" : datdata.Type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// We only want elements
|
// We only want elements
|
||||||
if (xtr.NodeType != XmlNodeType.Element)
|
if (xtr.NodeType != XmlNodeType.Element)
|
||||||
@@ -395,6 +429,8 @@ namespace SabreTools.Helper
|
|||||||
{
|
{
|
||||||
case "rom":
|
case "rom":
|
||||||
case "disk":
|
case "disk":
|
||||||
|
empty = false;
|
||||||
|
|
||||||
// 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 (xtr.GetAttribute("flags") == "nodump" || xtr.GetAttribute("status") == "nodump")
|
||||||
@@ -498,6 +534,37 @@ namespace SabreTools.Helper
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If we didn't find any items in the folder, make sure to add the blank rom
|
||||||
|
if (empty)
|
||||||
|
{
|
||||||
|
tempname = (parent.Count > 0 ? String.Join("\\", parent) + Path.DirectorySeparatorChar : "") + tempname;
|
||||||
|
|
||||||
|
RomData rom = new RomData
|
||||||
|
{
|
||||||
|
Name = "null",
|
||||||
|
Game = tempname,
|
||||||
|
Size = -1,
|
||||||
|
CRC = "null",
|
||||||
|
MD5 = "null",
|
||||||
|
SHA1 = "null",
|
||||||
|
};
|
||||||
|
|
||||||
|
key = rom.Size + "-" + rom.CRC;
|
||||||
|
if (datdata.Roms.ContainsKey(key))
|
||||||
|
{
|
||||||
|
datdata.Roms[key].Add(rom);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
List<RomData> temp = new List<RomData>();
|
||||||
|
temp.Add(rom);
|
||||||
|
datdata.Roms.Add(key, temp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Regardless, end the current folder
|
||||||
|
empty = true;
|
||||||
|
|
||||||
// Read to next game
|
// Read to next game
|
||||||
if (!xtr.ReadToNextSibling(temptype))
|
if (!xtr.ReadToNextSibling(temptype))
|
||||||
{
|
{
|
||||||
@@ -521,6 +588,8 @@ namespace SabreTools.Helper
|
|||||||
xtr.Read();
|
xtr.Read();
|
||||||
break;
|
break;
|
||||||
case "file":
|
case "file":
|
||||||
|
empty = false;
|
||||||
|
|
||||||
// If the rom is nodump, flag it
|
// If the rom is nodump, flag it
|
||||||
nodump = false;
|
nodump = false;
|
||||||
flagreader = xtr.ReadSubtree();
|
flagreader = xtr.ReadSubtree();
|
||||||
|
|||||||
Reference in New Issue
Block a user