Skip to content

Commit 739b913

Browse files
committed
Fixes: Issue #1 and Issue #2
1 parent 9983812 commit 739b913

File tree

4 files changed

+118
-75
lines changed

4 files changed

+118
-75
lines changed

RAWGMetadata/Model/GameOption.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using Playnite.SDK;
2+
using Rawg.Model;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace RAWGMetadata.Model
10+
{
11+
public class GameOption : GenericItemOption
12+
{
13+
public Game Game { get; private set; }
14+
15+
public GameOption(Game game)
16+
{
17+
this.Game = game;
18+
this.Description = game.Slug;
19+
this.Name = game.Name;
20+
}
21+
22+
23+
24+
}
25+
}

RAWGMetadata/RAWGMetadata.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<DebugSymbols>true</DebugSymbols>
1919
<DebugType>full</DebugType>
2020
<Optimize>false</Optimize>
21-
<OutputPath>..\..\..\..\..\AppData\Local\Playnite\Extensions\RAWGMetadata\</OutputPath>
21+
<OutputPath>..\..\..\..\AppData\Local\Playnite\Extensions\RawgMetadata\</OutputPath>
2222
<DefineConstants>DEBUG;TRACE</DefineConstants>
2323
<ErrorReport>prompt</ErrorReport>
2424
<WarningLevel>4</WarningLevel>
@@ -62,6 +62,7 @@
6262
<Generator>MSBuild:Compile</Generator>
6363
</Page>
6464
<Compile Include="Extensions\StringExtensions.cs" />
65+
<Compile Include="Model\GameOption.cs" />
6566
<Compile Include="RawgLazyMetadataProvider.cs" />
6667
<Compile Include="RawgMetadataPlugin.cs" />
6768
<Compile Include="RawgMetadataSettings.cs" />

RAWGMetadata/RawgLazyMetadataProvider.cs

Lines changed: 90 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
using Playnite.SDK.Metadata;
1+
using Playnite.SDK;
2+
using Playnite.SDK.Metadata;
23
using Playnite.SDK.Models;
34
using Playnite.SDK.Plugins;
45
using Rawg.Api;
56
using RAWGMetadata.Extensions;
7+
using RAWGMetadata.Model;
68
using System;
79
using System.Collections.Generic;
810
using System.IO;
@@ -32,22 +34,20 @@ public RawgLazyMetadataProvider(ulong gameId, RawgMetadataPlugin plugin)
3234
this.plugin = plugin;
3335
}
3436

35-
private Rawg.Model.GameSingle GetGameInfo()
37+
private void GetGameInfo()
3638
{
37-
var game = GetGame();
38-
39-
if (!(game is null) && _gameInfo is null)
40-
{
41-
_gameInfo = _gamesApi.GamesRead(game.Id.ToString());
42-
return _gameInfo;
43-
}
44-
else
39+
40+
if (_gameInfo is null)
4541
{
46-
return _gameInfo;
42+
GetGame();
43+
if (!(_game is null))
44+
{
45+
_gameInfo = _gamesApi.GamesRead(_game.Id.ToString());
46+
}
4747
}
4848
}
4949

50-
private Rawg.Model.Game GetGame()
50+
private void GetGame()
5151
{
5252
if (_game is null && !initialized)
5353
{
@@ -67,29 +67,42 @@ private Rawg.Model.Game GetGame()
6767

6868
var gameList = _gamesApi.GamesList(null, null, options.GameData.Name, null, platformId);
6969
_game = gameList.Results.FirstOrDefault(game => game.Name.Sanitize().Equals(options.GameData.Name.Sanitize()));
70-
/*
71-
if (_game == null)
70+
71+
if (_game == null && !options.IsBackgroundDownload)
7272
{
73-
_game = gameList.Results.FirstOrDefault();
73+
var selectedGame = plugin.PlayniteApi.Dialogs.ChooseItemWithSearch(new List<GenericItemOption>(gameList.Results.Select(_game => new GameOption(_game))), (a) =>
74+
{
75+
try
76+
{
77+
return new List<GenericItemOption>(_gamesApi.GamesList(null, null, a, null, platformId).Results.Select(_game => new GameOption(_game)));
78+
}
79+
catch (Exception e)
80+
{
81+
return new List<GenericItemOption>();
82+
}
83+
}, options.GameData.Name, string.Empty);
84+
85+
if (selectedGame == null)
86+
{
87+
_game = null;
88+
}
89+
else
90+
{
91+
_game = ((GameOption)selectedGame).Game;
92+
}
7493
}
75-
*/
76-
return _game;
77-
}
78-
else
79-
{
80-
return _game;
8194
}
8295
}
8396

8497
public override string GetName()
8598
{
86-
var game = GetGame();
99+
GetGame();
87100

88-
if (game != null)
101+
if (_game != null)
89102
{
90-
if (!string.IsNullOrWhiteSpace(game.Name))
103+
if (!string.IsNullOrWhiteSpace(_game.Name))
91104
{
92-
return game.Name;
105+
return _game.Name;
93106
}
94107
}
95108

@@ -98,13 +111,13 @@ public override string GetName()
98111

99112
public override List<string> GetGenres()
100113
{
101-
var gameInfo = GetGameInfo();
114+
GetGameInfo();
102115

103-
if (gameInfo != null)
116+
if (_gameInfo != null)
104117
{
105-
if (gameInfo.Genres != null)
118+
if (_gameInfo.Genres != null)
106119
{
107-
return gameInfo.Genres.Select(genre => genre.Name).ToList();
120+
return _gameInfo.Genres.Select(genre => genre.Name).ToList();
108121
}
109122
}
110123

@@ -114,13 +127,13 @@ public override List<string> GetGenres()
114127

115128
public override DateTime? GetReleaseDate()
116129
{
117-
var game = GetGame();
130+
GetGame();
118131

119-
if (game != null)
132+
if (_game != null)
120133
{
121-
if (game.Released != null)
134+
if (_game.Released != null)
122135
{
123-
return game.Released;
136+
return _game.Released;
124137
}
125138
}
126139

@@ -129,13 +142,13 @@ public override List<string> GetGenres()
129142

130143
public override List<string> GetDevelopers()
131144
{
132-
var gameInfo = GetGameInfo();
145+
GetGameInfo();
133146

134-
if (gameInfo != null)
147+
if (_gameInfo != null)
135148
{
136-
if (gameInfo.Developers != null)
149+
if (_gameInfo.Developers != null)
137150
{
138-
return gameInfo.Developers.Select(developer => developer.Name).ToList();
151+
return _gameInfo.Developers.Select(developer => developer.Name).ToList();
139152
}
140153
}
141154

@@ -144,13 +157,13 @@ public override List<string> GetDevelopers()
144157

145158
public override List<string> GetPublishers()
146159
{
147-
var gameInfo = GetGameInfo();
160+
GetGameInfo();
148161

149-
if (gameInfo != null)
162+
if (_gameInfo != null)
150163
{
151-
if (gameInfo.Publishers != null)
164+
if (_gameInfo.Publishers != null)
152165
{
153-
return gameInfo.Publishers.Select(publisher => publisher.Name).ToList();
166+
return _gameInfo.Publishers.Select(publisher => publisher.Name).ToList();
154167
}
155168
}
156169

@@ -160,13 +173,13 @@ public override List<string> GetPublishers()
160173

161174
public override string GetDescription()
162175
{
163-
var gameInfo = GetGameInfo();
176+
GetGameInfo();
164177

165-
if (gameInfo != null)
178+
if (_gameInfo != null)
166179
{
167-
if (!string.IsNullOrWhiteSpace(gameInfo.Description))
180+
if (!string.IsNullOrWhiteSpace(_gameInfo.Description))
168181
{
169-
return gameInfo.Description;
182+
return _gameInfo.Description;
170183
}
171184
}
172185

@@ -175,13 +188,13 @@ public override string GetDescription()
175188

176189
public override int? GetCommunityScore()
177190
{
178-
var game = GetGame();
191+
GetGame();
179192

180-
if (game != null)
193+
if (_game != null)
181194
{
182-
if (game.Rating != null)
195+
if (_game.Rating != null)
183196
{
184-
return (int)(game.Rating*20);
197+
return (int)(_game.Rating*20);
185198
}
186199
}
187200

@@ -191,13 +204,13 @@ public override string GetDescription()
191204
public override MetadataFile GetCoverImage()
192205
{
193206
/*
194-
var game = GetGame();
207+
GetGame();
195208
196-
if (game != null)
209+
if (_game != null)
197210
{
198-
if (!string.IsNullOrWhiteSpace(game.BackgroundImage))
211+
if (!string.IsNullOrWhiteSpace(_game.BackgroundImage))
199212
{
200-
return new MetadataFile(game.BackgroundImage);
213+
return new MetadataFile(_game.BackgroundImage);
201214
}
202215
}
203216
*/
@@ -206,13 +219,13 @@ public override MetadataFile GetCoverImage()
206219

207220
public override MetadataFile GetBackgroundImage()
208221
{
209-
var game = GetGame();
222+
GetGame();
210223

211-
if (game != null)
224+
if (_game != null)
212225
{
213-
if (!string.IsNullOrWhiteSpace(game.BackgroundImage))
226+
if (!string.IsNullOrWhiteSpace(_game.BackgroundImage))
214227
{
215-
return new MetadataFile(game.BackgroundImage);
228+
return new MetadataFile(_game.BackgroundImage);
216229
}
217230
}
218231

@@ -221,25 +234,25 @@ public override MetadataFile GetBackgroundImage()
221234

222235
public override List<Link> GetLinks()
223236
{
224-
var gameInfo = GetGameInfo();
237+
GetGameInfo();
225238

226-
if (gameInfo != null)
239+
if (_gameInfo != null)
227240
{
228241
var links = new List<Link>();
229242

230-
if (!string.IsNullOrWhiteSpace(gameInfo.Website))
243+
if (!string.IsNullOrWhiteSpace(_gameInfo.Website))
231244
{
232-
links.Add(new Link("Website", gameInfo.Website));
245+
links.Add(new Link("Website", _gameInfo.Website));
233246
}
234247

235-
if (!string.IsNullOrWhiteSpace(gameInfo.MetacriticUrl))
248+
if (!string.IsNullOrWhiteSpace(_gameInfo.MetacriticUrl))
236249
{
237-
links.Add(new Link("Metacritic", gameInfo.MetacriticUrl));
250+
links.Add(new Link("Metacritic", _gameInfo.MetacriticUrl));
238251
}
239252

240-
if (!string.IsNullOrWhiteSpace(gameInfo.RedditUrl))
253+
if (!string.IsNullOrWhiteSpace(_gameInfo.RedditUrl))
241254
{
242-
links.Add(new Link("Reddit", gameInfo.RedditUrl));
255+
links.Add(new Link("Reddit", _gameInfo.RedditUrl));
243256
}
244257

245258
if (links.Count > 0)
@@ -253,22 +266,26 @@ public override List<Link> GetLinks()
253266

254267
public override MetadataFile GetIcon()
255268
{
269+
/*
256270
using (MemoryStream ms = new MemoryStream())
257271
{
258272
RAWGMetadata.Properties.Resources.rawg.Save(ms);
259273
return new MetadataFile("RAWG", ms.ToArray());
260274
}
275+
*/
276+
277+
return base.GetIcon();
261278
}
262279

263280
public override int? GetCriticScore()
264281
{
265-
var game = GetGame();
282+
GetGame();
266283

267-
if (game != null)
284+
if (_game != null)
268285
{
269-
if (game.Metacritic != null)
286+
if (_game.Metacritic != null)
270287
{
271-
return game.Metacritic;
288+
return _game.Metacritic;
272289
}
273290
}
274291

@@ -277,13 +294,13 @@ public override MetadataFile GetIcon()
277294

278295
public override List<string> GetTags()
279296
{
280-
var gameInfo = GetGameInfo();
297+
GetGameInfo();
281298

282-
if (gameInfo != null)
299+
if (_gameInfo != null)
283300
{
284-
if (gameInfo.Tags != null)
301+
if (_gameInfo.Tags != null)
285302
{
286-
return gameInfo.Tags.Select(tag => tag.Name).ToList();
303+
return _gameInfo.Tags.Select(tag => tag.Name).ToList();
287304
}
288305
}
289306

RAWGMetadata/RawgMetadataPlugin.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public override OnDemandMetadataProvider GetMetadataProvider(MetadataRequestOpti
151151
MetadataField.Links,
152152
MetadataField.CriticScore,
153153
MetadataField.CommunityScore,
154-
MetadataField.Icon,
154+
//MetadataField.Icon,
155155
//MetadataField.CoverImage,
156156
MetadataField.BackgroundImage
157157

0 commit comments

Comments
 (0)