Skip to content

Commit

Permalink
better error handling for games w/o a source
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-codes committed Dec 9, 2024
1 parent b302092 commit 79d26c3
Show file tree
Hide file tree
Showing 3 changed files with 546 additions and 529 deletions.
16 changes: 14 additions & 2 deletions apps/PlayniteWebPlugin/src/Models/Game.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using Playnite.SDK;
using Playnite.SDK.Data;
using Playnite.SDK.Models;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
Expand All @@ -19,6 +21,7 @@ public class Game : IIdentifiable
private readonly Guid id;
private readonly IEnumerable<Platform> defaultPlatforms;
private readonly GameSource defaultSource;
private readonly ILogger logger = LogManager.GetLogger();

[DontSerialize]
public IEnumerable<Release> Releases => releases;
Expand Down Expand Up @@ -54,10 +57,19 @@ private IEnumerable<Release> GetReleases(IGrouping<GameSource, Playnite.SDK.Mode
{
foreach (var platform in defaultPlatforms)
{
var game = groupedBySource.FirstOrDefault(g => g.Roms.Any(r => r.Path.EndsWith("m3u")));
Playnite.SDK.Models.Game game = null;
try
{
game = groupedBySource.FirstOrDefault(g => g.Roms.Any(r => r.Path.EndsWith("m3u"))) ?? groupedBySource.First();
}
catch(Exception error)
{
logger.Error(error, $"Failed to get game from source for game named ${this.Name}");
}

if (game == null)
{
game = groupedBySource.First();
yield break;
}
yield return new Release(game, platform, defaultSource);
}
Expand Down
Loading

0 comments on commit 79d26c3

Please sign in to comment.