Fix icon loading on initial game sync
This commit is contained in:
		
							parent
							
								
									6b5824e920
								
							
						
					
					
						commit
						f63c2ddf2d
					
				
					 3 changed files with 25 additions and 17 deletions
				
			
		|  | @ -90,8 +90,6 @@ namespace LANCommander.PlaynitePlugin | |||
|                         continue; | ||||
|                     } | ||||
| 
 | ||||
|                     var iconUri = new Uri(new Uri(Settings.ServerAddress), $"Games/GetIcon/{game.Id}"); | ||||
| 
 | ||||
|                     var metadata = new GameMetadata() | ||||
|                     { | ||||
|                         IsInstalled = false, | ||||
|  | @ -101,7 +99,7 @@ namespace LANCommander.PlaynitePlugin | |||
|                         GameId = game.Id.ToString(), | ||||
|                         ReleaseDate = new ReleaseDate(manifest.ReleasedOn), | ||||
|                         //Version = game.Archives.OrderByDescending(a => a.CreatedOn).FirstOrDefault().Version, | ||||
|                         Icon = new MetadataFile(iconUri.ToString()), | ||||
|                         Icon = new MetadataFile($"{Settings.ServerAddress}{manifest.Icon}"), | ||||
|                         GameActions = game.Actions.OrderBy(a => a.SortOrder).Select(a => new PN.SDK.Models.GameAction() | ||||
|                         { | ||||
|                             Name = a.Name, | ||||
|  | @ -112,14 +110,6 @@ namespace LANCommander.PlaynitePlugin | |||
|                         }).ToList() | ||||
|                     }; | ||||
| 
 | ||||
|                     if (existingGame != null) | ||||
|                     { | ||||
|                         metadata.IsInstalled = true; | ||||
|                         metadata.Version = existingGame.Version; | ||||
|                         metadata.InstallDirectory = existingGame.InstallDirectory; | ||||
|                         metadata.InstallSize = existingGame.InstallSize; | ||||
|                     } | ||||
| 
 | ||||
|                     if (manifest.Genre != null && manifest.Genre.Count() > 0) | ||||
|                         metadata.Genres = new HashSet<MetadataProperty>(manifest.Genre.Select(g => new MetadataNameProperty(g))); | ||||
| 
 | ||||
|  | @ -285,11 +275,16 @@ namespace LANCommander.PlaynitePlugin | |||
|         { | ||||
|             var game = PlayniteApi.Database.Games.First(g => g.GameId == gameId.ToString()); | ||||
| 
 | ||||
|             if (game == null) | ||||
|                 return; | ||||
| 
 | ||||
|             if (game.GameActions == null) | ||||
|                 game.GameActions = new ObservableCollection<PN.SDK.Models.GameAction>(); | ||||
|             else | ||||
|                 game.GameActions.Clear(); | ||||
| 
 | ||||
|             game.Icon = $"{Settings.ServerAddress}{manifest.Icon}"; | ||||
| 
 | ||||
|             foreach (var action in manifest.Actions.OrderBy(a => a.SortOrder)) | ||||
|             { | ||||
|                 bool isFirstAction = !manifest.Actions.Any(a => a.IsPrimaryAction) && manifest.Actions.First().Name == action.Name; | ||||
|  |  | |||
|  | @ -41,6 +41,8 @@ namespace LANCommander.Controllers.Api | |||
|         { | ||||
|             var manifest = await GameService.GetManifest(id); | ||||
| 
 | ||||
|             manifest.Icon = Url.Action(nameof(GetIcon), new { id = id }); | ||||
| 
 | ||||
|             return manifest; | ||||
|         } | ||||
| 
 | ||||
|  | @ -64,5 +66,21 @@ namespace LANCommander.Controllers.Api | |||
| 
 | ||||
|             return File(new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read), "application/octet-stream", $"{game.Title.SanitizeFilename()}.zip"); | ||||
|         } | ||||
| 
 | ||||
|         [AllowAnonymous] | ||||
|         [HttpGet("{id}/Icon.png")] | ||||
|         public async Task<IActionResult> GetIcon(Guid id) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 var game = await GameService.Get(id); | ||||
| 
 | ||||
|                 return File(GameService.GetIcon(game), "image/png"); | ||||
|             } | ||||
|             catch (FileNotFoundException ex) | ||||
|             { | ||||
|                 return NotFound(); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -40,6 +40,7 @@ namespace LANCommander.Services | |||
|                 Description = game.Description, | ||||
|                 ReleasedOn = game.ReleasedOn.GetValueOrDefault(), | ||||
|                 Singleplayer = game.Singleplayer, | ||||
|                 Icon = game.Icon | ||||
|             }; | ||||
| 
 | ||||
|             if (game.Genres != null && game.Genres.Count > 0) | ||||
|  | @ -57,12 +58,6 @@ namespace LANCommander.Services | |||
|             if (game.Archives != null && game.Archives.Count > 0) | ||||
|                 manifest.Version = game.Archives.OrderByDescending(a => a.CreatedOn).First().Version; | ||||
| 
 | ||||
|             try | ||||
|             { | ||||
|                 manifest.Icon = Convert.ToBase64String(GetIcon(game)); | ||||
|             } | ||||
|             catch { } | ||||
| 
 | ||||
|             if (game.Actions != null && game.Actions.Count > 0) | ||||
|             { | ||||
|                 manifest.Actions = game.Actions.Select(a => new GameAction() | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 Pat Hartl
						Pat Hartl