Skip to content

Commit

Permalink
Fix failing to obtain metadata of Steam game demos
Browse files Browse the repository at this point in the history
  • Loading branch information
darklinkpower committed Oct 2, 2024
1 parent 61722a0 commit 732acc7
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions SGDBMetadata/SGDBMetadataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class SGDBMetadataProvider : OnDemandMetadataProvider
private string gamePlatformEnum;
private List<MetadataField> availableFields;
private string iconAssetSelection;
private const string demoSuffix = " Demo";
public override List<MetadataField> AvailableFields
{
get
Expand Down Expand Up @@ -55,7 +56,11 @@ public void convertPlayniteGamePluginIdToSGDBPlatformEnum(Guid pluginId, string
//Steam mods seem to use a randomly generated ID that surpass
//that value, so they shouldn't be used for matching.
//Mods should be matched by game name
if (int.TryParse(gameId, out int result))

// Demo entries are also ignored to fallback to normal search since
// they won't be matched using ID on SGDB
if (int.TryParse(gameId, out int _) &&
!options.GameData.Name.EndsWith(demoSuffix, StringComparison.OrdinalIgnoreCase))
{
gamePlatformEnum = "steam";
}
Expand Down Expand Up @@ -200,14 +205,13 @@ private void GetGame(List<GenericItemOption> gameList, string caption)
try
{
return new List<GenericItemOption>(services.getGameListSGDB(a).Select(game => new GenericItemOption(game.name, game.id.ToString())));
}
catch
{
var sgdbException = new Exception("Service failure.");
throw sgdbException;
}
}, options.GameData.Name, caption);
}, CleanupGameName(options.GameData.Name), caption);
searchSelection = item;
}

Expand All @@ -233,20 +237,31 @@ private void GetSgdbMetadata()
logger.Info("GetSgdbMetadata");

convertPlayniteGamePluginIdToSGDBPlatformEnum(options.GameData.PluginId, options.GameData.GameId);
var cleanedUpGameName = CleanupGameName(options.GameData.Name);
if (!options.IsBackgroundDownload)
{
if (string.IsNullOrEmpty(gamePlatformEnum))
{
var gameList = new List<GenericItemOption>(services.getGameListSGDB(options.GameData.Name).Select(game => new GenericItemOption(game.name, game.id.ToString())));
var gameList = new List<GenericItemOption>(services.getGameListSGDB(cleanedUpGameName).Select(game => new GenericItemOption(game.name, game.id.ToString())));
GetGame(gameList, ResourceProvider.GetString("LOCSteamGridDBMetadata_WindowTitleChooseGame"));
}
}
else if (string.IsNullOrEmpty(gamePlatformEnum))
{
gameSearchItem = services.getGameSGDBFuzzySearch(options.GameData.Name);
gameSearchItem = services.getGameSGDBFuzzySearch(cleanedUpGameName);
}
}

private string CleanupGameName(string gameName)
{
if (gameName.EndsWith(demoSuffix, StringComparison.OrdinalIgnoreCase))
{
gameName = gameName.Substring(0, gameName.Length - demoSuffix.Length);
}

return gameName;
}

private ImageFileOption GetCoverManually(List<GridModel> possibleCovers)
{
var selection = new List<ImageFileOption>();
Expand Down

0 comments on commit 732acc7

Please sign in to comment.