diff --git a/DATabase/DATabase.cs b/DATabase/DATabase.cs
index 24aaa226..70302322 100644
--- a/DATabase/DATabase.cs
+++ b/DATabase/DATabase.cs
@@ -55,6 +55,7 @@ namespace SabreTools
bare = false,
convertMiss = false,
convertCMP = false,
+ convertRC = false,
convertXml = false,
dedup = false,
diff = false,
@@ -120,6 +121,10 @@ namespace SabreTools
case "--convert-miss":
convertMiss = true;
break;
+ case "-cr":
+ case "--convert-rc":
+ convertRC = true;
+ break;
case "-cx":
case "--convert-xml":
convertXml = true;
@@ -295,7 +300,8 @@ namespace SabreTools
}
// If more than one switch is enabled or help is set, show the help screen
- if (help || !(add ^ convertMiss ^ convertCMP ^ convertXml ^ extsplit ^ generate ^ genall ^ import ^ listsrc ^ listsys ^ (merge || diff) ^ rem ^ trim))
+ if (help || !(add ^ convertMiss ^ convertCMP ^ convertRC ^ convertXml ^ extsplit ^ generate ^ genall ^
+ import ^ listsrc ^ listsys ^ (merge || diff) ^ rem ^ trim))
{
Build.Help();
logger.Close();
@@ -303,7 +309,7 @@ namespace SabreTools
}
// If a switch that requires a filename is set and no file is, show the help screen
- if (inputs.Count == 0 && (convertMiss || convertCMP || convertXml || extsplit || import || (merge || diff) || trim))
+ if (inputs.Count == 0 && (convertMiss || convertCMP || convertRC || convertXml || extsplit || import || (merge || diff) || trim))
{
Build.Help();
logger.Close();
@@ -354,7 +360,7 @@ namespace SabreTools
}
}
- // Convert XML DAT to CMP DAT
+ // Convert any DAT to CMP DAT
else if (convertCMP)
{
foreach (string input in inputs)
@@ -363,7 +369,16 @@ namespace SabreTools
}
}
- // Convert CMP DAT to XML DAT
+ // Convert any DAT to RC DAT
+ else if (convertRC)
+ {
+ foreach (string input in inputs)
+ {
+ InitConvertRC(input);
+ }
+ }
+
+ // Convert any DAT to XML DAT
else if (convertXml)
{
foreach (string input in inputs)
@@ -626,12 +641,13 @@ Make a selection:
===========================
Make a selection:
- 1) Convert XML DAT to CMP
- 2) Convert CMP DAT to XML
- 3) Convert DAT to missfile
- 4) Trim all entries in DAT and merge into a single game
- 5) Merge, diff, and/or dedup 2 or more DAT files
- 6) Split DAT using 2 extensions
+ 1) Convert DAT to ClrMamePro
+ 2) Convert DAT to RomCenter
+ 3) Convert DAT to XML
+ 4) Convert DAT to missfile
+ 5) Trim all entries in DAT and merge into a single game
+ 6) Merge, diff, and/or dedup 2 or more DAT files
+ 7) Split DAT using 2 extensions
B) Go back to the previous menu
");
Console.Write("Enter selection: ");
@@ -642,18 +658,21 @@ Make a selection:
ConvertCMPMenu();
break;
case "2":
- ConvertXMLMenu();
+ ConvertRCMenu();
break;
case "3":
- ConvertMissMenu();
+ ConvertXMLMenu();
break;
case "4":
- TrimMergeMenu();
+ ConvertMissMenu();
break;
case "5":
- MergeDiffMenu();
+ TrimMergeMenu();
break;
case "6":
+ MergeDiffMenu();
+ break;
+ case "7":
ExtSplitMenu();
break;
}
@@ -661,7 +680,7 @@ Make a selection:
}
///
- /// Show the text-based XML to CMP conversion menu
+ /// Show the text-based any to CMP conversion menu
///
private static void ConvertCMPMenu()
{
@@ -670,9 +689,9 @@ Make a selection:
{
Console.Clear();
Build.Start("DATabase");
- Console.WriteLine(@"XML -> CMP CONVERT MENU
+ Console.WriteLine(@"ANY -> CMP CONVERT MENU
===========================
-Enter the name of a DAT file to convert from XML to CMP
+Enter the name of a DAT file to convert to CMP
or 'b' to go back to the previous menu:
");
selection = Console.ReadLine();
@@ -687,6 +706,33 @@ or 'b' to go back to the previous menu:
return;
}
+ ///
+ /// Show the text-based any to RomCenter conversion menu
+ ///
+ private static void ConvertRCMenu()
+ {
+ string selection = "";
+ while (selection.ToLowerInvariant() != "b")
+ {
+ Console.Clear();
+ Build.Start("DATabase");
+ Console.WriteLine(@"ANY -> RC CONVERT MENU
+===========================
+Enter the name of a DAT file to convert to RomCenter
+or 'b' to go back to the previous menu:
+");
+ selection = Console.ReadLine();
+ if (selection.ToLowerInvariant() != "b")
+ {
+ Console.Clear();
+ InitConvertRC(selection);
+ Console.Write("\nPress any key to continue...");
+ Console.ReadKey();
+ }
+ }
+ return;
+ }
+
///
/// Show the text-based CMP to XML conversion menu
///
@@ -697,9 +743,9 @@ or 'b' to go back to the previous menu:
{
Console.Clear();
Build.Start("DATabase");
- Console.WriteLine(@"CMP -> XML CONVERT MENU
+ Console.WriteLine(@"ANY -> XML CONVERT MENU
===========================
-Enter the name of a DAT file to convert from CMP to XML
+Enter the name of a DAT file to convert to XML
or 'b' to go back to the previous menu:
");
selection = Console.ReadLine();
@@ -1243,7 +1289,7 @@ Make a selection:
}
///
- /// Wrap converting DAT file from XML to ClrMamePro
+ /// Wrap converting DAT file from any format to ClrMamePro
///
///
private static void InitConvertCMP(string filename)
@@ -1283,7 +1329,47 @@ Make a selection:
}
///
- /// Wrap converting DAT file from ClrMamePro to XML
+ /// Wrap converting DAT file from any format to RomCenter
+ ///
+ ///
+ private static void InitConvertRC(string filename)
+ {
+ if (File.Exists(filename))
+ {
+ logger.User("Converting " + filename);
+ DatData datdata = new DatData
+ {
+ Name = "",
+ Description = "",
+ Category = "",
+ Version = "",
+ Date = "",
+ Author = "",
+ Email = "",
+ Homepage = "",
+ Url = "",
+ Comment = "",
+ OutputFormat = OutputFormat.RomCenter,
+ Roms = new Dictionary>(),
+ MergeRoms = false,
+ };
+
+ datdata = RomManipulation.ParseDict(filename, 0, 0, datdata, logger);
+
+ logger.User("datdata.Description: " + datdata.Description);
+
+ datdata.Description += ".new";
+ Output.WriteToDatFromDict(datdata, Path.GetDirectoryName(filename), logger);
+ }
+ else
+ {
+ logger.Error("I'm sorry but " + filename + " doesn't exist!");
+ }
+ return;
+ }
+
+ ///
+ /// Wrap converting DAT file from any format to XML
///
///
private static void InitConvertXML(string filename)
diff --git a/SabreHelper/Build.cs b/SabreHelper/Build.cs
index 9a9f9ee8..1b2e1f02 100644
--- a/SabreHelper/Build.cs
+++ b/SabreHelper/Build.cs
@@ -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
diff --git a/SabreHelper/Output.cs b/SabreHelper/Output.cs
index 5e1c550a..0086b812 100644
--- a/SabreHelper/Output.cs
+++ b/SabreHelper/Output.cs
@@ -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) + "\"" +
diff --git a/SabreHelper/RomManipulation.cs b/SabreHelper/RomManipulation.cs
index 6f9ad4d6..22710bf7 100644
--- a/SabreHelper/RomManipulation.cs
+++ b/SabreHelper/RomManipulation.cs
@@ -20,7 +20,7 @@ namespace SabreTools.Helper
/// Return if the file is XML or not
///
/// Name of the file to be parsed
- /// public static bool IsXmlDat(string filename)
+ /// True if the DAT is probably XML, false otherwise
public static bool IsXmlDat(string filename)
{
try
@@ -36,6 +36,26 @@ namespace SabreTools.Helper
}
}
+ ///
+ /// Return if the file is RomCenter or not
+ ///
+ /// Name of the file to be parsed
+ /// True if the DAT is probably XML, false otherwise
+ 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;
+ }
+ }
+
///
/// Get the XmlDocument associated with a file, if possible
///
@@ -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;