Add convert to RomCenter functionality!

This commit is contained in:
Matt Nadareski
2016-05-16 15:38:33 -07:00
parent 40de13ac3d
commit 47e8f11f82
4 changed files with 141 additions and 24 deletions

View File

@@ -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;