diff --git a/DATabase/DATabase.cs b/DATabase/DATabase.cs index f4bf9fcb..450615ea 100644 --- a/DATabase/DATabase.cs +++ b/DATabase/DATabase.cs @@ -56,6 +56,7 @@ namespace SabreTools convertMiss = false, convertCMP = false, convertRC = false, + convertSD = false, convertXml = false, dedup = false, diff = false, @@ -127,6 +128,10 @@ namespace SabreTools case "--convert-rc": convertRC = true; break; + case "-cs": + case "--convert-sd": + convertSD = true; + break; case "-cx": case "--convert-xml": convertXml = true; @@ -310,7 +315,7 @@ namespace SabreTools } // If more than one switch is enabled or help is set, show the help screen - if (help || !(add ^ convertMiss ^ convertCMP ^ convertRC ^ convertXml ^ extsplit ^ generate ^ genall ^ + if (help || !(add ^ convertMiss ^ convertCMP ^ convertRC ^ convertSD ^ convertXml ^ extsplit ^ generate ^ genall ^ import ^ listsrc ^ listsys ^ (merge || diff) ^ rem ^ trim)) { Build.Help(); @@ -319,7 +324,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 || convertRC || convertXml || extsplit || import || (merge || diff) || trim)) + if (inputs.Count == 0 && (convertMiss || convertCMP || convertRC || convertSD || convertXml || extsplit || import || (merge || diff) || trim)) { Build.Help(); logger.Close(); @@ -388,6 +393,15 @@ namespace SabreTools } } + // Convert any DAT to SabreDAT + else if (convertSD) + { + foreach (string input in inputs) + { + InitConvert(input, OutputFormat.SabreDat, outdir); + } + } + // Convert any DAT to XML DAT else if (convertXml) { @@ -652,10 +666,10 @@ Make a selection: Make a selection: 1) Convert or clean DAT or folder of DATs - 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 + 2) Convert DAT to missfile + 3) Trim all entries in DAT and merge into a single game + 4) Merge, diff, and/or dedup 2 or more DAT files + 5) Split DAT using 2 extensions B) Go back to the previous menu "); Console.Write("Enter selection: "); @@ -725,6 +739,7 @@ Make a selection: 1) Xml 2) ClrMamePro 3) RomCenter + 4) SabreDAT "); Console.Write("Please enter your selection: "); subsel = Console.ReadLine(); @@ -740,6 +755,9 @@ Make a selection: case "3": outputFormat = OutputFormat.RomCenter; break; + case "4": + outputFormat = OutputFormat.SabreDat; + break; default: subsel = ""; break; @@ -751,6 +769,8 @@ Make a selection: InitConvert(input, outputFormat, outdir); Console.Write("\nPress any key to continue..."); Console.ReadKey(); + input = ""; outdir = ""; + outputFormat = OutputFormat.Xml; break; } } @@ -1326,7 +1346,7 @@ Make a selection: Roms = new Dictionary>(), MergeRoms = false, }; - datdata = RomManipulation.Parse(filename, 0, 0, datdata, logger); + datdata = RomManipulation.Parse(filename, 0, 0, datdata, logger, true); // Sometimes the description doesn't match the filename, change this if (datdata.Description != Path.GetFileNameWithoutExtension(filename)) @@ -1335,7 +1355,8 @@ Make a selection: } // If the extension matches, append ".new" to the filename - if (outdir == "" && Path.GetExtension(filename) == (datdata.OutputFormat == OutputFormat.Xml ? ".xml" : ".dat")) + string extension = (datdata.OutputFormat == OutputFormat.Xml || datdata.OutputFormat == OutputFormat.SabreDat ? ".xml" : ".dat"); + if (outdir == "" && Path.GetExtension(filename) == extension) { datdata.Description += ".new"; } @@ -1365,7 +1386,7 @@ Make a selection: Roms = new Dictionary>(), MergeRoms = false, }; - datdata = RomManipulation.Parse(file, 0, 0, datdata, logger); + datdata = RomManipulation.Parse(file, 0, 0, datdata, logger, true); // Sometimes the description doesn't match the filename, change this if (datdata.Description != Path.GetFileNameWithoutExtension(file)) @@ -1374,7 +1395,8 @@ Make a selection: } // If the extension matches, append ".new" to the filename - if (outdir == "" && Path.GetExtension(file) == (datdata.OutputFormat == OutputFormat.Xml ? ".xml" : ".dat")) + string extension = (datdata.OutputFormat == OutputFormat.Xml || datdata.OutputFormat == OutputFormat.SabreDat ? ".xml" : ".dat"); + if (outdir == "" && Path.GetExtension(file) == extension) { datdata.Description += ".new"; } diff --git a/SabreHelper/Build.cs b/SabreHelper/Build.cs index a568424c..7940a50b 100644 --- a/SabreHelper/Build.cs +++ b/SabreHelper/Build.cs @@ -98,6 +98,8 @@ Options: -ae=, --add-ext= Add an extension to each item -re=, --rep-ext= Replace all extensions with specified -ro, --romba Output roms in Romba format (requires SHA-1) + -cs, --convert-sd Convert any DAT to SabreDAT + -out= Output directory -cr, --convert-rc Convert any DAT to RomCenter -out= Output directory -cx, --convert-xml Convert any DAT to XML diff --git a/SabreHelper/Enums.cs b/SabreHelper/Enums.cs index 0822dad3..282b64b1 100644 --- a/SabreHelper/Enums.cs +++ b/SabreHelper/Enums.cs @@ -104,5 +104,6 @@ namespace SabreTools.Helper RomCenter, DOSCenter, MissFile, + SabreDat, } } diff --git a/SabreHelper/Output.cs b/SabreHelper/Output.cs index 4ff5d079..42b24539 100644 --- a/SabreHelper/Output.cs +++ b/SabreHelper/Output.cs @@ -72,11 +72,12 @@ namespace SabreTools.Helper Directory.CreateDirectory(outDir); // (currently uses current time, change to "last updated time") - logger.User("Opening file for writing: " + outDir + datdata.Description + (datdata.OutputFormat == OutputFormat.Xml ? ".xml" : ".dat")); + string extension = (datdata.OutputFormat == OutputFormat.Xml || datdata.OutputFormat == OutputFormat.SabreDat ? ".xml" : ".dat"); + logger.User("Opening file for writing: " + outDir + datdata.Description + extension); try { - FileStream fs = File.Create(outDir + datdata.Description + (datdata.OutputFormat == OutputFormat.Xml ? ".xml" : ".dat")); + FileStream fs = File.Create(outDir + datdata.Description + extension); StreamWriter sw = new StreamWriter(fs, Encoding.UTF8); string header = ""; @@ -108,6 +109,26 @@ namespace SabreTools.Helper "version=" + HttpUtility.HtmlEncode(datdata.Description) + "\n" + "[GAMES]\n"; break; + case OutputFormat.SabreDat: + header = "\n" + + "\n\n" + + "\n" + + "\t
\n" + + "\t\t" + HttpUtility.HtmlEncode(datdata.Name) + "\n" + + "\t\t" + HttpUtility.HtmlEncode(datdata.Description) + "\n" + + "\t\t" + HttpUtility.HtmlEncode(datdata.Category) + "\n" + + "\t\t" + HttpUtility.HtmlEncode(datdata.Version) + "\n" + + "\t\t" + HttpUtility.HtmlEncode(datdata.Date) + "\n" + + "\t\t" + HttpUtility.HtmlEncode(datdata.Author) + "\n" + + "\t\t" + HttpUtility.HtmlEncode(datdata.Comment) + "\n" + + (datdata.Type != null && datdata.Type != "" && datdata.ForcePacking != ForcePacking.Unzip ? + "\t\t\n" + + (datdata.Type != null && datdata.Type != "" ? "\t\t\t\n" : "") + + (datdata.ForcePacking == ForcePacking.Unzip ? "\t\t\t\n" : "") + + "\t\t\n" : "") + + "\t
\n" + + "\t\n"; + break; case OutputFormat.Xml: header = "\n" + "\n\n" + @@ -130,12 +151,17 @@ namespace SabreTools.Helper sw.Write(header); // Write out each of the machines and roms + int depth = 2, last = -1; string lastgame = null; + List splitpath = new List(); foreach (List roms in sortable.Values) { foreach (RomData rom in roms) { string state = ""; + List newsplit = rom.Game.Split('\\').ToList(); + + // If we have a different game and we're not at the start of the list, output the end of last item if (lastgame != null && lastgame.ToLowerInvariant() != rom.Game.ToLowerInvariant()) { switch (datdata.OutputFormat) @@ -143,12 +169,43 @@ namespace SabreTools.Helper case OutputFormat.ClrMamePro: state += ")\n"; break; + case OutputFormat.SabreDat: + if (splitpath != null) + { + for (int i = 0; i < newsplit.Count && i < splitpath.Count; i++) + { + // Always keep track of the last seen item + last = i; + + // If we find a difference, break + if (newsplit[i] != splitpath[i]) + { + break; + } + } + + // Now that we have the last known position, take down all open folders + for (int i = depth - 1; i > last + 1; i--) + { + // Print out the number of tabs and the end folder + for (int j = 0; j < i; j++) + { + state += "\t"; + } + state += "\n"; + } + + // Reset the current depth + depth = 2 + last; + } + break; case OutputFormat.Xml: state += "\t\n"; break; } } + // If we have a new game, output the beginning of the new item if (lastgame == null || lastgame.ToLowerInvariant() != rom.Game.ToLowerInvariant()) { switch (datdata.OutputFormat) @@ -157,6 +214,18 @@ namespace SabreTools.Helper state += "game (\n\tname \"" + rom.Game + "\"\n" + "\tdescription \"" + rom.Game + "\"\n"; break; + case OutputFormat.SabreDat: + for (int i = (last == -1 ? 0 : last); i < newsplit.Count; i++) + { + for (int j = 0; j < depth - last + i - (lastgame == null ? 1 : 0); j++) + { + state += "\t"; + } + state += "\n"; + } + depth = depth - (last == -1 ? 0 : last) + newsplit.Count; + break; case OutputFormat.Xml: state += "\t\n" + "\t\t" + HttpUtility.HtmlEncode(rom.Game) + "\n"; @@ -229,6 +298,19 @@ namespace SabreTools.Helper "¬" + rom.CRC.ToLowerInvariant() + "¬" + (rom.Size != -1 ? rom.Size.ToString() : "") + "¬¬¬\n"; break; + case OutputFormat.SabreDat: + for (int i = 0; i < depth; i++) + { + state += "\t"; + } + state += "\n"; + break; case OutputFormat.Xml: state += "\t\t<" + rom.Type + " name=\"" + HttpUtility.HtmlEncode(rom.Name) + "\"" + (rom.Size != -1 ? " size=\"" + rom.Size + "\"" : "") + @@ -240,6 +322,7 @@ namespace SabreTools.Helper break; } + splitpath = newsplit; lastgame = rom.Game; sw.Write(state); @@ -252,6 +335,18 @@ namespace SabreTools.Helper case OutputFormat.ClrMamePro: footer = ")"; break; + case OutputFormat.SabreDat: + for (int i = depth; i >= 2; i--) + { + // Print out the number of tabs and the end folder + for (int j = 0; j < i; j++) + { + footer += "\t"; + } + footer += "\n"; + } + footer += "\t\n
"; + break; case OutputFormat.Xml: footer = "\t\n"; break; diff --git a/SabreHelper/RomManipulation.cs b/SabreHelper/RomManipulation.cs index 4be02e11..a9a06b26 100644 --- a/SabreHelper/RomManipulation.cs +++ b/SabreHelper/RomManipulation.cs @@ -98,7 +98,7 @@ namespace SabreTools.Helper /// The DatData object representing found roms to this point /// Logger object for console and/or file output /// DatData object representing the read-in data - public static DatData Parse(string filename, int sysid, int srcid, DatData datdata, Logger logger) + public static DatData Parse(string filename, int sysid, int srcid, DatData datdata, Logger logger, bool keep = false) { XmlTextReader xtr = GetXmlTextReader(filename, logger); bool superdat = false, shouldbreak = false; @@ -270,7 +270,7 @@ namespace SabreTools.Helper tempname = xtr.GetAttribute("name"); } - if (superdat) + if (superdat && !keep) { tempname = Regex.Match(tempname, @".*?\\(.*)").Groups[1].Value; }