fix: improved title matching

This commit is contained in:
Michael Green
2023-05-16 19:14:54 +10:00
parent 42d5f9f6f2
commit 5ffc33472d
2 changed files with 46 additions and 8 deletions

View File

@@ -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,6 +181,12 @@ 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)

View File

@@ -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;
}
}
}
}