mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Update SingleGame to full functionality
This commit is contained in:
@@ -8,13 +8,15 @@ namespace SabreTools
|
|||||||
{
|
{
|
||||||
public class SingleGame
|
public class SingleGame
|
||||||
{
|
{
|
||||||
private static string _filename;
|
private static string _filename = "";
|
||||||
|
private static string _path = "";
|
||||||
|
private static bool _rename = true;
|
||||||
|
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
Console.Title = "SingleGame " + Build.Version;
|
Console.Title = "SingleGame " + Build.Version;
|
||||||
|
|
||||||
if (args.Length != 1)
|
if (args.Length == 0)
|
||||||
{
|
{
|
||||||
Help();
|
Help();
|
||||||
return;
|
return;
|
||||||
@@ -22,6 +24,17 @@ namespace SabreTools
|
|||||||
|
|
||||||
_filename = args[0];
|
_filename = args[0];
|
||||||
|
|
||||||
|
if (args.Length > 1)
|
||||||
|
{
|
||||||
|
for (int i = 1; i < args.Length; i++)
|
||||||
|
{
|
||||||
|
_path = (args[i].StartsWith("-r") ? args[i].Split('=')[1] : _path);
|
||||||
|
_rename = (args[i] == "-n" ? false : _rename);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_path = (_path == "" ? Environment.CurrentDirectory : _path);
|
||||||
|
|
||||||
// Take the filename, and load it as an XML document
|
// Take the filename, and load it as an XML document
|
||||||
XmlDocument doc = new XmlDocument();
|
XmlDocument doc = new XmlDocument();
|
||||||
try
|
try
|
||||||
@@ -58,7 +71,7 @@ namespace SabreTools
|
|||||||
while (node != null)
|
while (node != null)
|
||||||
{
|
{
|
||||||
// If we're at a game node, add the parent node but not all the internals
|
// If we're at a game node, add the parent node but not all the internals
|
||||||
if (node.NodeType == XmlNodeType.Element && (node.Name == "machine" || node.Name == "game"))
|
if (_rename && node.NodeType == XmlNodeType.Element && (node.Name == "machine" || node.Name == "game"))
|
||||||
{
|
{
|
||||||
if (!inGame)
|
if (!inGame)
|
||||||
{
|
{
|
||||||
@@ -91,12 +104,14 @@ namespace SabreTools
|
|||||||
|
|
||||||
XmlElement tempNode = (XmlElement)tempDoc.ImportNode(child, true);
|
XmlElement tempNode = (XmlElement)tempDoc.ImportNode(child, true);
|
||||||
|
|
||||||
// Windows max name length is 260. Taking into account the game name of "!", we can use 259 characters
|
// Windows max name length is 260
|
||||||
string tempname = "(" + node.Attributes["name"].Value + ")" + child.Attributes["name"].Value;
|
string tempname = child.Attributes["name"].Value;
|
||||||
if (tempname.Length > 259)
|
int usableLength = 259 - _path.Length;
|
||||||
|
|
||||||
|
if (tempname.Length > usableLength)
|
||||||
{
|
{
|
||||||
string ext = Path.GetExtension(tempname);
|
string ext = Path.GetExtension(tempname);
|
||||||
tempname = tempname.Substring(0, 259 - ext.Length);
|
tempname = tempname.Substring(0, usableLength - ext.Length);
|
||||||
tempname += ext;
|
tempname += ext;
|
||||||
}
|
}
|
||||||
tempNode.SetAttribute("name", tempname);
|
tempNode.SetAttribute("name", tempname);
|
||||||
@@ -108,10 +123,29 @@ namespace SabreTools
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
XmlNode tempNode = tempDoc.ImportNode(node, true);
|
XmlNode tempNode = tempDoc.ImportNode(node, true);
|
||||||
|
|
||||||
|
if (tempNode.Name == "header")
|
||||||
|
{
|
||||||
|
if (tempNode.SelectSingleNode("clrmamepro") == null)
|
||||||
|
{
|
||||||
|
XmlElement tempChild = tempDoc.CreateElement("clrmamepro");
|
||||||
|
tempChild.SetAttribute("forcepacking", "unzip");
|
||||||
|
tempNode.AppendChild(tempChild);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
(tempNode.SelectSingleNode("clrmamepro") as XmlElement).SetAttribute("forcepacking", "unzip");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
outNode.AppendChild(tempNode);
|
outNode.AppendChild(tempNode);
|
||||||
}
|
}
|
||||||
node = node.NextSibling;
|
node = node.NextSibling;
|
||||||
}
|
}
|
||||||
|
if (inGame)
|
||||||
|
{
|
||||||
|
outNode = outNode.ParentNode;
|
||||||
|
}
|
||||||
|
|
||||||
tempDoc.AppendChild(tempDoc.CreateDocumentType("datafile", "-//Logiqx//DTD ROM Management Datafile//EN", "http://www.logiqx.com/Dats/datafile.dtd", null));
|
tempDoc.AppendChild(tempDoc.CreateDocumentType("datafile", "-//Logiqx//DTD ROM Management Datafile//EN", "http://www.logiqx.com/Dats/datafile.dtd", null));
|
||||||
tempDoc.AppendChild(outNode);
|
tempDoc.AppendChild(outNode);
|
||||||
@@ -121,7 +155,10 @@ namespace SabreTools
|
|||||||
|
|
||||||
private static void Help()
|
private static void Help()
|
||||||
{
|
{
|
||||||
Console.WriteLine("SingleGame.exe <filename>");
|
Console.WriteLine(@"SingleGame.exe <filename> [-r=rootdir|-n]
|
||||||
|
-r=rootdir Set the directory name for path size
|
||||||
|
-n Disable single-game mode
|
||||||
|
");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user