From 5ffc33472de994f357977d493fda087a4d26c891 Mon Sep 17 00:00:00 2001 From: Michael Green <84688932+michael-j-green@users.noreply.github.com> Date: Tue, 16 May 2023 19:14:54 +1000 Subject: [PATCH] fix: improved title matching --- gaseous-server/Classes/ImportGames.cs | 31 ++++++++++++++++++------ gaseous-server/Models/PlatformMapping.cs | 23 ++++++++++++++++++ 2 files changed, 46 insertions(+), 8 deletions(-) diff --git a/gaseous-server/Classes/ImportGames.cs b/gaseous-server/Classes/ImportGames.cs index 5e69368..d05d39c 100644 --- a/gaseous-server/Classes/ImportGames.cs +++ b/gaseous-server/Classes/ImportGames.cs @@ -1,5 +1,6 @@ using System; using System.Data; +using System.Text.RegularExpressions; using System.Threading.Tasks; using gaseous_tools; using Org.BouncyCastle.Utilities.IO.Pem; @@ -133,6 +134,15 @@ namespace gaseous_server.Classes // game title is the file name without the extension or path gi.Name = Path.GetFileNameWithoutExtension(GameFileImportPath); + // remove everything after brackets - leaving (hopefully) only the name + if (gi.Name.Contains("(")) + { + gi.Name = gi.Name.Substring(0, gi.Name.IndexOf("(")); + } + + // remove special characters like dashes + gi.Name = gi.Name.Replace("-", ""); + // guess platform gaseous_server.Models.PlatformMapping.GetIGDBPlatformMapping(ref discoveredSignature, fi, true); @@ -152,16 +162,15 @@ namespace gaseous_server.Classes determinedPlatform = new IGDB.Models.Platform(); } - // remove string ending ", The" if present - if (discoveredSignature.Game.Name.Contains(", The")) - { - Logging.Log(Logging.LogType.Information, "Import Game", " Removing ', The' from end of game title for search"); - discoveredSignature.Game.Name.Replace(", The", ""); - } - // search discovered game - case insensitive exact match first IGDB.Models.Game determinedGame = new IGDB.Models.Game(); + // remove version numbers from name + discoveredSignature.Game.Name = Regex.Replace(discoveredSignature.Game.Name, @"v(\d+\.)?(\d+\.)?(\*|\d+)$", "").Trim(); + discoveredSignature.Game.Name = Regex.Replace(discoveredSignature.Game.Name, @"Rev (\d+\.)?(\d+\.)?(\*|\d+)$", "").Trim(); + + Logging.Log(Logging.LogType.Information, "Import Game", " Searching for title: " + discoveredSignature.Game.Name); + foreach (Metadata.Games.SearchType searchType in Enum.GetValues(typeof(Metadata.Games.SearchType))) { Logging.Log(Logging.LogType.Information, "Import Game", " Search type: " + searchType.ToString()); @@ -172,7 +181,13 @@ namespace gaseous_server.Classes determinedGame = Metadata.Games.GetGame((long)games[0].Id, false, false); Logging.Log(Logging.LogType.Information, "Import Game", " IGDB game: " + determinedGame.Name); break; - } + } else if (games.Length > 0) + { + Logging.Log(Logging.LogType.Information, "Import Game", " " + games.Length + " search results found"); + } else + { + Logging.Log(Logging.LogType.Information, "Import Game", " No search results found"); + } } if (determinedGame == null) { diff --git a/gaseous-server/Models/PlatformMapping.cs b/gaseous-server/Models/PlatformMapping.cs index a8c0798..f97dd7b 100644 --- a/gaseous-server/Models/PlatformMapping.cs +++ b/gaseous-server/Models/PlatformMapping.cs @@ -35,6 +35,7 @@ namespace gaseous_server.Models public static void GetIGDBPlatformMapping(ref Models.Signatures_Games Signature, FileInfo RomFileInfo, bool SetSystemName) { + bool PlatformFound = false; foreach (Models.PlatformMapping.PlatformMapItem PlatformMapping in Models.PlatformMapping.PlatformMap) { if (PlatformMapping.KnownFileExtensions.Contains(RomFileInfo.Extension, StringComparer.OrdinalIgnoreCase)) @@ -45,6 +46,28 @@ namespace gaseous_server.Models } Signature.Flags.IGDBPlatformId = PlatformMapping.IGDBId; Signature.Flags.IGDBPlatformName = PlatformMapping.IGDBName; + + PlatformFound = true; + break; + } + } + + if (PlatformFound == false) + { + foreach (Models.PlatformMapping.PlatformMapItem PlatformMapping in Models.PlatformMapping.PlatformMap) + { + if (PlatformMapping.AlternateNames.Contains(Signature.Game.System, StringComparer.OrdinalIgnoreCase)) + { + if (SetSystemName == true) + { + if (Signature.Game != null) { Signature.Game.System = PlatformMapping.IGDBName; } + } + Signature.Flags.IGDBPlatformId = PlatformMapping.IGDBId; + Signature.Flags.IGDBPlatformName = PlatformMapping.IGDBName; + + PlatformFound = true; + break; + } } } }