From fa40bb39cf3915fb0b1e4c597c20eaedbef72769 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Sun, 29 May 2016 21:15:05 -0700 Subject: [PATCH] [RomManipulation] Make game cleaning more standardized --- SabreHelper/RomManipulation.cs | 81 ++++++++++++++++------------------ 1 file changed, 39 insertions(+), 42 deletions(-) diff --git a/SabreHelper/RomManipulation.cs b/SabreHelper/RomManipulation.cs index 95cb0bda..fa9d6f1d 100644 --- a/SabreHelper/RomManipulation.cs +++ b/SabreHelper/RomManipulation.cs @@ -168,14 +168,7 @@ namespace SabreTools.Helper // 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); - gamename = gamename.TrimStart().TrimEnd(); - - gamename = new Regex(@"(([[(].*[\)\]] )?([^([]+))").Match(gamename).Groups[1].Value; - gamename = gamename.TrimStart().TrimEnd(); + gamename = CleanGameName(gamename); } RomData rom = new RomData @@ -511,13 +504,7 @@ namespace SabreTools.Helper // 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]); - - rominfo[3] = new Regex(@"(([[(].*[\)\]] )?([^([]+))").Match(rominfo[3]).Groups[1].Value; - rominfo[3] = rominfo[3].TrimStart().TrimEnd(); + rominfo[3] = CleanGameName(rominfo[3]); } RomData rom = new RomData @@ -583,13 +570,10 @@ namespace SabreTools.Helper { string tempgame = String.Join("\\", parent); - // WoD gets rid of anything past the first "(" or "[" as the name, we will do the same if in clean mode + // If we're in cleaning mode, sanitize the game name if (clean) { - string[] splitgame = tempgame.Split(Path.DirectorySeparatorChar); - splitgame[splitgame.Length - 1] = new Regex(@"(([[(].*[\)\]] )?([^([]+))").Match(splitgame[splitgame.Length - 1]).Groups[1].Value; - tempgame = String.Join(Path.DirectorySeparatorChar.ToString(), splitgame); - tempgame = tempgame.TrimStart().TrimEnd(); + tempgame = CleanGameName(tempgame.Split(Path.DirectorySeparatorChar)); } RomData rom = new RomData @@ -1009,18 +993,7 @@ namespace SabreTools.Helper // If we're in clean mode, sanitize the game name if (clean) { - string[] splitgame = tempname.Split(Path.DirectorySeparatorChar); - string intname = splitgame[splitgame.Length - 1]; - - ///Run the name through the filters to make sure that it's correct - intname = Style.NormalizeChars(intname); - intname = Style.RussianToLatin(intname); - intname = Style.SearchPattern(intname); - - // WoD gets rid of anything past the first "(" or "[" as the name, we will do the same if in clean mode - splitgame[splitgame.Length - 1] = new Regex(@"(([[(].*[\)\]] )?([^([]+))").Match(intname).Groups[1].Value; - tempname = String.Join(Path.DirectorySeparatorChar.ToString(), splitgame); - tempname = tempname.TrimStart().TrimEnd(); + tempname = CleanGameName(tempname.Split(Path.DirectorySeparatorChar)); } // Only add the rom if there's useful information in it @@ -1077,13 +1050,10 @@ namespace SabreTools.Helper { tempname = (parent.Count > 0 ? String.Join("\\", parent) + Path.DirectorySeparatorChar : "") + tempname; - // WoD gets rid of anything past the first "(" or "[" as the name, we will do the same if in clean mode + // If we're in cleaning mode, sanitize the game name if (clean) { - string[] splitgame = tempname.Split(Path.DirectorySeparatorChar); - splitgame[splitgame.Length - 1] = new Regex(@"(([[(].*[\)\]] )?([^([]+))").Match(splitgame[splitgame.Length - 1]).Groups[1].Value; - tempname = String.Join(Path.DirectorySeparatorChar.ToString(), splitgame); - tempname = tempname.TrimStart().TrimEnd(); + tempname = CleanGameName(tempname.Split(Path.DirectorySeparatorChar)); } RomData rom = new RomData @@ -1245,13 +1215,10 @@ namespace SabreTools.Helper } } - // WoD gets rid of anything past the first "(" or "[" as the name, we will do the same if in clean mode + // If we're in cleaning mode, sanitize the game name if (clean) { - string[] splitgame = tempname.Split(Path.DirectorySeparatorChar); - splitgame[splitgame.Length - 1] = new Regex(@"(([[(].*[\)\]] )?([^([]+))").Match(splitgame[splitgame.Length - 1]).Groups[1].Value; - tempname = String.Join(Path.DirectorySeparatorChar.ToString(), splitgame); - tempname = tempname.TrimStart().TrimEnd(); + tempname = CleanGameName(tempname.Split(Path.DirectorySeparatorChar)); } // Only add the rom if there's useful information in it @@ -1524,5 +1491,35 @@ namespace SabreTools.Helper logger.User("A total of " + count + " file hashes will be written out to file"); return sortable; } + + /// + /// Clean a game (or rom) name to the WoD standard + /// + /// Name of the game to be cleaned + /// The cleaned name + public static string CleanGameName(string game) + { + ///Run the name through the filters to make sure that it's correct + game = Style.NormalizeChars(game); + game = Style.RussianToLatin(game); + game = Style.SearchPattern(game); + + game = new Regex(@"(([[(].*[\)\]] )?([^([]+))").Match(game).Groups[1].Value; + game = game.TrimStart().TrimEnd(); + return game; + } + + /// + /// Clean a game (or rom) name to the WoD standard + /// + /// Array representing the path to be cleaned + /// The cleaned name + public static string CleanGameName(string[] game) + { + game[game.Length - 1] = CleanGameName(game[game.Length - 1]); + string outgame = String.Join(Path.DirectorySeparatorChar.ToString(), game); + outgame = outgame.TrimStart().TrimEnd(); + return outgame; + } } }