From c8f962e2bbda1543f2fe507d914c5702de71204a Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Sun, 29 May 2016 13:36:02 -0700 Subject: [PATCH] [RomManipulation] Add cleaning to other DAT formats --- SabreHelper/RomManipulation.cs | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/SabreHelper/RomManipulation.cs b/SabreHelper/RomManipulation.cs index 2d74cbc7..c065016f 100644 --- a/SabreHelper/RomManipulation.cs +++ b/SabreHelper/RomManipulation.cs @@ -100,9 +100,9 @@ namespace SabreTools.Helper switch (GetOutputFormat(filename)) { case OutputFormat.ClrMamePro: - return ParseCMP(filename, sysid, srcid, datdata, logger, keep); + return ParseCMP(filename, sysid, srcid, datdata, logger, keep, clean); case OutputFormat.RomCenter: - return ParseRC(filename, sysid, srcid, datdata, logger); + return ParseRC(filename, sysid, srcid, datdata, logger, clean); case OutputFormat.SabreDat: case OutputFormat.Xml: return ParseXML(filename, sysid, srcid, datdata, logger, keep, clean); @@ -120,8 +120,9 @@ namespace SabreTools.Helper /// The DatData object representing found roms to this point /// Logger object for console and/or file output /// True if full pathnames are to be kept, false otherwise (default) + /// True if game names are sanitized, false otherwise (default) /// DatData object representing the read-in data - public static DatData ParseCMP(string filename, int sysid, int srcid, DatData datdata, Logger logger, bool keep = false) + public static DatData ParseCMP(string filename, int sysid, int srcid, DatData datdata, Logger logger, bool keep, bool clean) { // Read the input file, if possible logger.Log("Attempting to read file: \"" + filename + "\""); @@ -164,6 +165,15 @@ namespace SabreTools.Helper // If the line is a rom or disk and we're in a block else if ((line.Trim().StartsWith("rom (") || line.Trim().StartsWith("disk (")) && block) { + // If we're in cleaning mode, sanitize the game name + if (clean) + { + ///Run the name through the filters to make sure that it's correct + gamename = Style.NormalizeChars(gamename); + gamename = Style.RussianToLatin(gamename); + gamename = Style.SearchPattern(gamename); + } + RomData rom = new RomData { Game = gamename, @@ -380,8 +390,9 @@ namespace SabreTools.Helper /// Source ID for the DAT /// The DatData object representing found roms to this point /// Logger object for console and/or file output + /// True if game names are sanitized, false otherwise (default) /// DatData object representing the read-in data - public static DatData ParseRC(string filename, int sysid, int srcid, DatData datdata, Logger logger) + public static DatData ParseRC(string filename, int sysid, int srcid, DatData datdata, Logger logger, bool clean) { // Read the input file, if possible logger.Log("Attempting to read file: \"" + filename + "\""); @@ -492,6 +503,16 @@ namespace SabreTools.Helper 9 - merge name */ string[] rominfo = line.Split('¬'); + + // If we're in cleaning mode, sanitize the game name + if (clean) + { + ///Run the name through the filters to make sure that it's correct + rominfo[3] = Style.NormalizeChars(rominfo[3]); + rominfo[3] = Style.RussianToLatin(rominfo[3]); + rominfo[3] = Style.SearchPattern(rominfo[3]); + } + RomData rom = new RomData { Game = rominfo[3], @@ -532,7 +553,7 @@ namespace SabreTools.Helper /// True if full pathnames are to be kept, false otherwise (default) /// True if game names are sanitized, false otherwise (default) /// DatData object representing the read-in data - public static DatData ParseXML(string filename, int sysid, int srcid, DatData datdata, Logger logger, bool keep = false, bool clean = false) + public static DatData ParseXML(string filename, int sysid, int srcid, DatData datdata, Logger logger, bool keep, bool clean) { // Prepare all internal variables XmlReader subreader, headreader, flagreader;