mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Add convert to RomCenter functionality!
This commit is contained in:
@@ -97,6 +97,8 @@ Options:
|
||||
-q, --quotes Put double-quotes around each item
|
||||
-ae=, --add-ext= Add an extension to each item
|
||||
-re=, --rep-ext= Replace all extensions with specified
|
||||
-cr, --convert-rc Convert any DAT to RomCenter
|
||||
-out= Output directory
|
||||
-cx, --convert-xml Convert any DAT to XML
|
||||
-out= Output directory
|
||||
-es, --ext-split Split a DAT by two file extensions
|
||||
|
||||
@@ -304,7 +304,7 @@ namespace SabreTools.Helper
|
||||
"¬" + HttpUtility.HtmlEncode(rom.Game) +
|
||||
"¬" + HttpUtility.HtmlEncode(rom.Name) +
|
||||
"¬" + rom.CRC.ToLowerInvariant() +
|
||||
"¬" + (rom.Size != -1 ? rom.Size.ToString() : "") + "¬¬¬";
|
||||
"¬" + (rom.Size != -1 ? rom.Size.ToString() : "") + "¬¬¬\n";
|
||||
break;
|
||||
case OutputFormat.Xml:
|
||||
state += "\t\t<" + rom.Type + " name=\"" + HttpUtility.HtmlEncode(rom.Name) + "\"" +
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace SabreTools.Helper
|
||||
/// Return if the file is XML or not
|
||||
/// </summary>
|
||||
/// <param name="filename">Name of the file to be parsed</param>
|
||||
/// <returns>public static bool IsXmlDat(string filename)
|
||||
/// <returns>True if the DAT is probably XML, false otherwise</returns>
|
||||
public static bool IsXmlDat(string filename)
|
||||
{
|
||||
try
|
||||
@@ -36,6 +36,26 @@ namespace SabreTools.Helper
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return if the file is RomCenter or not
|
||||
/// </summary>
|
||||
/// <param name="filename">Name of the file to be parsed</param>
|
||||
/// <returns>True if the DAT is probably XML, false otherwise</returns>
|
||||
public static bool IsRCDat(string filename)
|
||||
{
|
||||
try
|
||||
{
|
||||
StreamReader sr = new StreamReader(File.OpenRead(filename));
|
||||
string first = sr.ReadLine();
|
||||
sr.Close();
|
||||
return first.Contains("[") && first.Contains("]");
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the XmlDocument associated with a file, if possible
|
||||
/// </summary>
|
||||
@@ -112,9 +132,18 @@ namespace SabreTools.Helper
|
||||
xtr.DtdProcessing = DtdProcessing.Ignore;
|
||||
return xtr;
|
||||
}
|
||||
else if (IsRCDat(filename))
|
||||
{
|
||||
logger.Log("RomCenter DAT detected");
|
||||
StringReader sr = new StringReader(Converters.RomCenterToXML(File.ReadAllLines(filename)).ToString());
|
||||
XmlTextReader xtr = new XmlTextReader(sr);
|
||||
xtr.WhitespaceHandling = WhitespaceHandling.None;
|
||||
xtr.DtdProcessing = DtdProcessing.Ignore;
|
||||
return xtr;
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.Log("Non-XML DAT detected");
|
||||
logger.Log("ClrMamePro DAT detected");
|
||||
StringReader sr = new StringReader(Converters.ClrMameProToXML(File.ReadAllLines(filename)).ToString());
|
||||
XmlTextReader xtr = new XmlTextReader(sr);
|
||||
xtr.WhitespaceHandling = WhitespaceHandling.None;
|
||||
|
||||
Reference in New Issue
Block a user