mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Add DAT name prefixing
This commit is contained in:
@@ -89,6 +89,7 @@ Options:
|
||||
url= URL (source only)
|
||||
-cm, --convert-miss
|
||||
-r, --roms Output roms to miss instead of sets
|
||||
-dp, --dat-prefix Add dat name as a prefix to each item
|
||||
-pre=, --prefix= Set prefix to be printed in front of all lines
|
||||
-post=, --postfix= Set postfix to be printed behind all lines
|
||||
-q, --quotes Put double-quotes around each item
|
||||
|
||||
@@ -139,9 +139,10 @@ namespace SabreTools.Helper
|
||||
/// <param name="quotes">True if quotes should be put around the item, false otherwise (default)</param>
|
||||
/// <param name="addext">Arbitrary extension added to the end of each item</param>
|
||||
/// <param name="repext">Arbitrary extension to replace all extensions in the item</param>
|
||||
/// <param name="datname">The internal name of the DAT to prefix</param>
|
||||
/// <returns>True if the file was written, false otherwise</returns>
|
||||
public static bool WriteToText(string textfile, string outdir, List<RomData> roms, Logger logger, bool useGame = true, string prefix = "",
|
||||
string postfix = "", string addext = "", string repext = "", bool quotes = false)
|
||||
string postfix = "", string addext = "", string repext = "", bool quotes = false, string datname = "")
|
||||
{
|
||||
// Normalize the output directory
|
||||
if (outdir == "")
|
||||
@@ -153,6 +154,12 @@ namespace SabreTools.Helper
|
||||
outdir += Path.DirectorySeparatorChar;
|
||||
}
|
||||
|
||||
// Get the DAT name, if applicable
|
||||
if (datname != "" && !datname.EndsWith(Path.DirectorySeparatorChar.ToString()))
|
||||
{
|
||||
datname = datname + Path.DirectorySeparatorChar;
|
||||
}
|
||||
|
||||
// Make the output directory if it doesn't exist
|
||||
if (!Directory.Exists(outdir))
|
||||
{
|
||||
@@ -175,7 +182,7 @@ namespace SabreTools.Helper
|
||||
{
|
||||
string pre = prefix + (quotes ? "\"" : "");
|
||||
string post = (quotes ? "\"" : "") + postfix;
|
||||
string name = (useGame ? rom.Game : rom.Name);
|
||||
string name = datname + (useGame ? rom.Game : rom.Name);
|
||||
if (repext != "")
|
||||
{
|
||||
string dir = Path.GetDirectoryName(name);
|
||||
|
||||
@@ -28,6 +28,65 @@ namespace SabreTools.Helper
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the name of the DAT for external use
|
||||
/// </summary>
|
||||
/// <param name="filename">Name of the file to be parsed</param>
|
||||
/// <param name="logger">Logger object for console and file output</param>
|
||||
/// <returns>The internal name of the DAT on success, empty string otherwise</returns>
|
||||
public static string GetDatName(string filename, Logger logger)
|
||||
{
|
||||
string name = "";
|
||||
|
||||
XmlDocument doc = new XmlDocument();
|
||||
try
|
||||
{
|
||||
doc.LoadXml(File.ReadAllText(filename));
|
||||
}
|
||||
catch (XmlException)
|
||||
{
|
||||
try
|
||||
{
|
||||
doc.LoadXml(Converters.RomVaultToXML(File.ReadAllLines(filename)).ToString());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error(ex.ToString());
|
||||
return name;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error(ex.ToString());
|
||||
return name;
|
||||
}
|
||||
|
||||
// Experimental looping using only XML parsing
|
||||
XmlNode node = doc.FirstChild;
|
||||
if (node != null && node.Name == "xml")
|
||||
{
|
||||
// Skip over everything that's not an element
|
||||
while (node.NodeType != XmlNodeType.Element)
|
||||
{
|
||||
node = node.NextSibling;
|
||||
}
|
||||
}
|
||||
|
||||
// Once we find the main body, enter it
|
||||
if (node != null && (node.Name == "datafile" || node.Name == "softwarelist"))
|
||||
{
|
||||
node = node.FirstChild;
|
||||
}
|
||||
|
||||
// Get the name from the header
|
||||
if (node != null && node.Name == "header")
|
||||
{
|
||||
name = node.SelectSingleNode("name").InnerText;
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a DAT and return all found games and roms within
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user