Skip to content

Commit

Permalink
Merge pull request #28 from ryanpf/fix/rom-import-only-supported-file…
Browse files Browse the repository at this point in the history
…-types

Filter registered ROMs by emulator profile supported file types
  • Loading branch information
gantoine authored Nov 19, 2024
2 parents d5f0686 + 7581bcb commit 4e6a3ac
Showing 1 changed file with 38 additions and 4 deletions.
42 changes: 38 additions & 4 deletions Games/RomMInstallController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,8 @@ public override void Install(InstallActionArgs args)
ExtractNestedArchives(installDir);
}
// Add just the ROM files to the list
string[] actualRomFiles = Directory.GetFiles(installDir, "*", SearchOption.AllDirectories)
.Where(file => !file.EndsWith(".m3u", StringComparison.OrdinalIgnoreCase))
.ToArray();
List<string> supportedFileTypes = GetEmulatorSupportedFileTypes(info);
string[] actualRomFiles = GetRomFiles(installDir, supportedFileTypes);
foreach (var romFile in actualRomFiles) {
roms.Add(new GameRom(Game.Name, romFile));
Expand Down Expand Up @@ -129,6 +127,42 @@ public override void Install(InstallActionArgs args)
});
}

private static string[] GetRomFiles(string installDir, List<string> supportedFileTypes)
{
if (supportedFileTypes == null || supportedFileTypes.Count == 0)
{
return Directory.GetFiles(installDir, "*", SearchOption.AllDirectories)
.Where(file => !file.EndsWith(".m3u", StringComparison.OrdinalIgnoreCase))
.ToArray();
}
else
{
return supportedFileTypes.SelectMany(
fileType => Directory.GetFiles(installDir, "*." + fileType, SearchOption.AllDirectories)
).ToArray();
}
}

private static List<string> GetEmulatorSupportedFileTypes(RomMGameInfo info)
{
if (info.Mapping.EmulatorProfile is CustomEmulatorProfile)
{
var customProfile = info.Mapping.EmulatorProfile as CustomEmulatorProfile;
return customProfile.ImageExtensions;
}
else if (info.Mapping.EmulatorProfile is BuiltInEmulatorProfile)
{
var builtInProfile = (info.Mapping.EmulatorProfile as BuiltInEmulatorProfile);
return API.Instance.Emulation.Emulators
.FirstOrDefault(e => e.Id == info.Mapping.Emulator.BuiltInConfigId)?
.Profiles
.FirstOrDefault(p => p.Name == builtInProfile.Name)?
.ImageExtensions;
}

return null;
}

private static bool IsFileCompressed(string filePath)
{
try
Expand Down

0 comments on commit 4e6a3ac

Please sign in to comment.