Skip to content

Commit

Permalink
do not publish games that cannot be grouped by name
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-codes committed Dec 9, 2024
1 parent e100330 commit c34ea09
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
21 changes: 14 additions & 7 deletions apps/PlayniteWebPlugin/src/Models/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
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 @@ -22,6 +21,7 @@ public class Game : IIdentifiable
private readonly IEnumerable<Platform> defaultPlatforms;
private readonly GameSource defaultSource;
private readonly ILogger logger = LogManager.GetLogger();
private readonly IEnumerable<Playnite.SDK.Models.Game> playniteGames;

[DontSerialize]
public IEnumerable<Release> Releases => releases;
Expand All @@ -41,7 +41,15 @@ public Game(IEnumerable<Playnite.SDK.Models.Game> playniteGames, IEnumerable<Pla
xboxPlatformNames = new List<string> { ".*Xbox.*" };
nintendoPlatformNames = new List<string> { ".*Nintendo.*", ".*Switch.*", ".*Wii.*", ".*Game ?Cube.*" };

releases = playniteGames.GroupBy(game => game.Source).SelectMany(GetReleases).ToList();

var gameBySource = playniteGames.GroupBy(game => game.Source);
if (gameBySource.Any(grouped => grouped.Key == null))
{
logger.Warn($"Game {playniteGames.First().Name} has no source. These will be published with the source Emulator.");
}

releases = gameBySource
.SelectMany(GetReleases).ToList();

using (MD5 md5 = MD5.Create())
{
Expand All @@ -62,10 +70,8 @@ private IEnumerable<Release> GetReleases(IGrouping<GameSource, Playnite.SDK.Mode
{
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}");
}
catch
{ }

if (game == null)
{
Expand All @@ -84,7 +90,8 @@ private IEnumerable<Release> GetReleases(IGrouping<GameSource, Playnite.SDK.Mode
{
platform = groupedBySource.ElementAt(i).Platforms.Where(p => IsMatchingPlatform(groupedBySource.Key, p)).Where(p => !publishedPlatforms.Any(pp => p.Id == pp.Id)).OrderBy(p => p, platformSorter).First();
}
catch {
catch
{
}
if (platform == null)
{
Expand Down
9 changes: 8 additions & 1 deletion apps/PlayniteWebPlugin/src/PlayniteWeb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,14 @@ private IEnumerable<Task> SyncLibrary()

var batchMessage = new BatchMessage();

var games = PlayniteApi.Database.Games.GroupBy(game => game.Name).Select(groupedByName => new Models.Game(groupedByName, pcPlatforms, emulatorSource)).Where(g => !g.Id.Equals(Guid.Empty)).ToList();
var groupedGames = PlayniteApi.Database.Games.GroupBy(game => game.Name);
var invalidGames = groupedGames.Where(groupedByName => groupedByName.Key == null).ToList();
if (invalidGames.Any())
{
logger.Warn($"Found {invalidGames.Count} games with no name. These games will not be published.");
}

var games = groupedGames.Where(groupedByName => groupedByName.Key != null).Select(groupedByName => new Models.Game(groupedByName, pcPlatforms, emulatorSource)).Where(g => !g.Id.Equals(Guid.Empty)).ToList();
games.ForEach(game =>
{
batchMessage.Messages.Add(new Message() { Topic = topicManager.GetPublishTopic(PublishTopics.Game(game.Id)), Payload = serializer.Serialize(game) });
Expand Down

0 comments on commit c34ea09

Please sign in to comment.