From 739b913b6e47e9b72f10be54a76411fd64de93a9 Mon Sep 17 00:00:00 2001 From: Brett Sanderson Date: Sun, 23 Feb 2020 01:53:57 -0500 Subject: [PATCH] Fixes: Issue #1 and Issue #2 --- RAWGMetadata/Model/GameOption.cs | 25 ++++ RAWGMetadata/RAWGMetadata.csproj | 3 +- RAWGMetadata/RawgLazyMetadataProvider.cs | 163 +++++++++++++---------- RAWGMetadata/RawgMetadataPlugin.cs | 2 +- 4 files changed, 118 insertions(+), 75 deletions(-) create mode 100644 RAWGMetadata/Model/GameOption.cs diff --git a/RAWGMetadata/Model/GameOption.cs b/RAWGMetadata/Model/GameOption.cs new file mode 100644 index 0000000..6c54abd --- /dev/null +++ b/RAWGMetadata/Model/GameOption.cs @@ -0,0 +1,25 @@ +using Playnite.SDK; +using Rawg.Model; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RAWGMetadata.Model +{ + public class GameOption : GenericItemOption + { + public Game Game { get; private set; } + + public GameOption(Game game) + { + this.Game = game; + this.Description = game.Slug; + this.Name = game.Name; + } + + + + } +} diff --git a/RAWGMetadata/RAWGMetadata.csproj b/RAWGMetadata/RAWGMetadata.csproj index a24c703..5969df5 100644 --- a/RAWGMetadata/RAWGMetadata.csproj +++ b/RAWGMetadata/RAWGMetadata.csproj @@ -18,7 +18,7 @@ true full false - ..\..\..\..\..\AppData\Local\Playnite\Extensions\RAWGMetadata\ + ..\..\..\..\AppData\Local\Playnite\Extensions\RawgMetadata\ DEBUG;TRACE prompt 4 @@ -62,6 +62,7 @@ MSBuild:Compile + diff --git a/RAWGMetadata/RawgLazyMetadataProvider.cs b/RAWGMetadata/RawgLazyMetadataProvider.cs index 7462794..dbd6f37 100644 --- a/RAWGMetadata/RawgLazyMetadataProvider.cs +++ b/RAWGMetadata/RawgLazyMetadataProvider.cs @@ -1,8 +1,10 @@ -using Playnite.SDK.Metadata; +using Playnite.SDK; +using Playnite.SDK.Metadata; using Playnite.SDK.Models; using Playnite.SDK.Plugins; using Rawg.Api; using RAWGMetadata.Extensions; +using RAWGMetadata.Model; using System; using System.Collections.Generic; using System.IO; @@ -32,22 +34,20 @@ public RawgLazyMetadataProvider(ulong gameId, RawgMetadataPlugin plugin) this.plugin = plugin; } - private Rawg.Model.GameSingle GetGameInfo() + private void GetGameInfo() { - var game = GetGame(); - - if (!(game is null) && _gameInfo is null) - { - _gameInfo = _gamesApi.GamesRead(game.Id.ToString()); - return _gameInfo; - } - else + + if (_gameInfo is null) { - return _gameInfo; + GetGame(); + if (!(_game is null)) + { + _gameInfo = _gamesApi.GamesRead(_game.Id.ToString()); + } } } - private Rawg.Model.Game GetGame() + private void GetGame() { if (_game is null && !initialized) { @@ -67,29 +67,42 @@ private Rawg.Model.Game GetGame() var gameList = _gamesApi.GamesList(null, null, options.GameData.Name, null, platformId); _game = gameList.Results.FirstOrDefault(game => game.Name.Sanitize().Equals(options.GameData.Name.Sanitize())); - /* - if (_game == null) + + if (_game == null && !options.IsBackgroundDownload) { - _game = gameList.Results.FirstOrDefault(); + var selectedGame = plugin.PlayniteApi.Dialogs.ChooseItemWithSearch(new List(gameList.Results.Select(_game => new GameOption(_game))), (a) => + { + try + { + return new List(_gamesApi.GamesList(null, null, a, null, platformId).Results.Select(_game => new GameOption(_game))); + } + catch (Exception e) + { + return new List(); + } + }, options.GameData.Name, string.Empty); + + if (selectedGame == null) + { + _game = null; + } + else + { + _game = ((GameOption)selectedGame).Game; + } } - */ - return _game; - } - else - { - return _game; } } public override string GetName() { - var game = GetGame(); + GetGame(); - if (game != null) + if (_game != null) { - if (!string.IsNullOrWhiteSpace(game.Name)) + if (!string.IsNullOrWhiteSpace(_game.Name)) { - return game.Name; + return _game.Name; } } @@ -98,13 +111,13 @@ public override string GetName() public override List GetGenres() { - var gameInfo = GetGameInfo(); + GetGameInfo(); - if (gameInfo != null) + if (_gameInfo != null) { - if (gameInfo.Genres != null) + if (_gameInfo.Genres != null) { - return gameInfo.Genres.Select(genre => genre.Name).ToList(); + return _gameInfo.Genres.Select(genre => genre.Name).ToList(); } } @@ -114,13 +127,13 @@ public override List GetGenres() public override DateTime? GetReleaseDate() { - var game = GetGame(); + GetGame(); - if (game != null) + if (_game != null) { - if (game.Released != null) + if (_game.Released != null) { - return game.Released; + return _game.Released; } } @@ -129,13 +142,13 @@ public override List GetGenres() public override List GetDevelopers() { - var gameInfo = GetGameInfo(); + GetGameInfo(); - if (gameInfo != null) + if (_gameInfo != null) { - if (gameInfo.Developers != null) + if (_gameInfo.Developers != null) { - return gameInfo.Developers.Select(developer => developer.Name).ToList(); + return _gameInfo.Developers.Select(developer => developer.Name).ToList(); } } @@ -144,13 +157,13 @@ public override List GetDevelopers() public override List GetPublishers() { - var gameInfo = GetGameInfo(); + GetGameInfo(); - if (gameInfo != null) + if (_gameInfo != null) { - if (gameInfo.Publishers != null) + if (_gameInfo.Publishers != null) { - return gameInfo.Publishers.Select(publisher => publisher.Name).ToList(); + return _gameInfo.Publishers.Select(publisher => publisher.Name).ToList(); } } @@ -160,13 +173,13 @@ public override List GetPublishers() public override string GetDescription() { - var gameInfo = GetGameInfo(); + GetGameInfo(); - if (gameInfo != null) + if (_gameInfo != null) { - if (!string.IsNullOrWhiteSpace(gameInfo.Description)) + if (!string.IsNullOrWhiteSpace(_gameInfo.Description)) { - return gameInfo.Description; + return _gameInfo.Description; } } @@ -175,13 +188,13 @@ public override string GetDescription() public override int? GetCommunityScore() { - var game = GetGame(); + GetGame(); - if (game != null) + if (_game != null) { - if (game.Rating != null) + if (_game.Rating != null) { - return (int)(game.Rating*20); + return (int)(_game.Rating*20); } } @@ -191,13 +204,13 @@ public override string GetDescription() public override MetadataFile GetCoverImage() { /* - var game = GetGame(); + GetGame(); - if (game != null) + if (_game != null) { - if (!string.IsNullOrWhiteSpace(game.BackgroundImage)) + if (!string.IsNullOrWhiteSpace(_game.BackgroundImage)) { - return new MetadataFile(game.BackgroundImage); + return new MetadataFile(_game.BackgroundImage); } } */ @@ -206,13 +219,13 @@ public override MetadataFile GetCoverImage() public override MetadataFile GetBackgroundImage() { - var game = GetGame(); + GetGame(); - if (game != null) + if (_game != null) { - if (!string.IsNullOrWhiteSpace(game.BackgroundImage)) + if (!string.IsNullOrWhiteSpace(_game.BackgroundImage)) { - return new MetadataFile(game.BackgroundImage); + return new MetadataFile(_game.BackgroundImage); } } @@ -221,25 +234,25 @@ public override MetadataFile GetBackgroundImage() public override List GetLinks() { - var gameInfo = GetGameInfo(); + GetGameInfo(); - if (gameInfo != null) + if (_gameInfo != null) { var links = new List(); - if (!string.IsNullOrWhiteSpace(gameInfo.Website)) + if (!string.IsNullOrWhiteSpace(_gameInfo.Website)) { - links.Add(new Link("Website", gameInfo.Website)); + links.Add(new Link("Website", _gameInfo.Website)); } - if (!string.IsNullOrWhiteSpace(gameInfo.MetacriticUrl)) + if (!string.IsNullOrWhiteSpace(_gameInfo.MetacriticUrl)) { - links.Add(new Link("Metacritic", gameInfo.MetacriticUrl)); + links.Add(new Link("Metacritic", _gameInfo.MetacriticUrl)); } - if (!string.IsNullOrWhiteSpace(gameInfo.RedditUrl)) + if (!string.IsNullOrWhiteSpace(_gameInfo.RedditUrl)) { - links.Add(new Link("Reddit", gameInfo.RedditUrl)); + links.Add(new Link("Reddit", _gameInfo.RedditUrl)); } if (links.Count > 0) @@ -253,22 +266,26 @@ public override List GetLinks() public override MetadataFile GetIcon() { + /* using (MemoryStream ms = new MemoryStream()) { RAWGMetadata.Properties.Resources.rawg.Save(ms); return new MetadataFile("RAWG", ms.ToArray()); } + */ + + return base.GetIcon(); } public override int? GetCriticScore() { - var game = GetGame(); + GetGame(); - if (game != null) + if (_game != null) { - if (game.Metacritic != null) + if (_game.Metacritic != null) { - return game.Metacritic; + return _game.Metacritic; } } @@ -277,13 +294,13 @@ public override MetadataFile GetIcon() public override List GetTags() { - var gameInfo = GetGameInfo(); + GetGameInfo(); - if (gameInfo != null) + if (_gameInfo != null) { - if (gameInfo.Tags != null) + if (_gameInfo.Tags != null) { - return gameInfo.Tags.Select(tag => tag.Name).ToList(); + return _gameInfo.Tags.Select(tag => tag.Name).ToList(); } } diff --git a/RAWGMetadata/RawgMetadataPlugin.cs b/RAWGMetadata/RawgMetadataPlugin.cs index 00b465d..0951ff3 100644 --- a/RAWGMetadata/RawgMetadataPlugin.cs +++ b/RAWGMetadata/RawgMetadataPlugin.cs @@ -151,7 +151,7 @@ public override OnDemandMetadataProvider GetMetadataProvider(MetadataRequestOpti MetadataField.Links, MetadataField.CriticScore, MetadataField.CommunityScore, - MetadataField.Icon, + //MetadataField.Icon, //MetadataField.CoverImage, MetadataField.BackgroundImage