Skip to content
Closed
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: 19 additions & 2 deletions RomM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,14 +237,19 @@ public override IEnumerable<GameMetadata> GetGames(LibraryGetGamesArgs args)
continue;
}

if (mapping.Platform == null)
if (mapping.Platform == null && mapping.PlatformFsSlug == null)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

This change allows mapping.Platform to be null if mapping.PlatformFsSlug is provided. However, this introduces NullReferenceExceptions in several places later in the code that still assume mapping.Platform is not null.

For example:

  • Line 256: mapping.Platform.Name
  • Line 378: mapping.Platform.Name
  • Line 409: mapping.Platform.Name

The potential NullReferenceException on line 247 is addressed in a separate comment, but these other instances also need to be fixed. You should either make all usages of mapping.Platform within this loop null-safe (e.g., using the null-conditional operator ?.) or reconsider this condition to avoid breaking existing logic.

{
Logger.Warn($"Platform {mapping.PlatformId} not found, skipping.");
continue;
}

string url = $"{Settings.RomMHost}/api/roms";
RomMPlatform apiPlatform = apiPlatforms.FirstOrDefault(p => p.IgdbId == mapping.Platform.IgdbId);
RomMPlatform apiPlatform = apiPlatform = apiPlatforms.FirstOrDefault(p => p.IgdbId == mapping.Platform.IgdbId);

if (mapping.PlatformFsSlug != null)
{
apiPlatform = apiPlatforms.FirstOrDefault(p => p.FsSlug == mapping.PlatformFsSlug);
}
Comment on lines +247 to +252

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

There are a few issues with the logic for finding the apiPlatform:

  1. Typo: There's a redundant assignment apiPlatform = apiPlatform = ... on line 247.
  2. Crash Risk: If mapping.Platform is null (which is now possible due to the change on line 240), accessing mapping.Platform.IgdbId on line 247 will cause a NullReferenceException.
  3. Flawed Logic: The code first attempts to find the platform by IgdbId and then overwrites it if PlatformFsSlug is available. The logic should prioritize PlatformFsSlug and only fall back to IgdbId if the slug is not present.

Here is a suggested replacement that fixes these issues and is safer and clearer:

                RomMPlatform apiPlatform = null;
                if (mapping.PlatformFsSlug != null)
                {
                    apiPlatform = apiPlatforms.FirstOrDefault(p => p.FsSlug == mapping.PlatformFsSlug);
                }
                else if (mapping.Platform != null)
                {
                    apiPlatform = apiPlatforms.FirstOrDefault(p => p.IgdbId == mapping.Platform.IgdbId);
                }


if (apiPlatform == null)
{
Expand Down Expand Up @@ -274,6 +279,18 @@ public override IEnumerable<GameMetadata> GetGames(LibraryGetGamesArgs args)
{ "order_dir", "asc" },
};

if (mapping.PlatformFsSlug != null)
{
queryParams = new NameValueCollection
{
{ "limit", pageSize.ToString() },
{ "offset", offset.ToString() },
{ "platform_fs_slug", apiPlatform.FsSlug.ToString() },
{ "order_by", "name" },
{ "order_dir", "asc" },
};
}

try
{
// Make the request and get the response
Expand Down
3 changes: 3 additions & 0 deletions Settings/EmulatorMapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ public IEnumerable<EmulatedPlatform> AvailablePlatforms
}
}

[JsonIgnore]
public string PlatformFsSlug { get; set; }

[JsonIgnore]
[XmlIgnore]
public string DestinationPathResolved
Expand Down