Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

do not publish games that cannot be grouped by name #667

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading