Skip to content

Commit 4e6a3ac

Browse files
authored
Merge pull request #28 from ryanpf/fix/rom-import-only-supported-file-types
Filter registered ROMs by emulator profile supported file types
2 parents d5f0686 + 7581bcb commit 4e6a3ac

File tree

1 file changed

+38
-4
lines changed

1 file changed

+38
-4
lines changed

Games/RomMInstallController.cs

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,8 @@ public override void Install(InstallActionArgs args)
9696
ExtractNestedArchives(installDir);
9797
}
9898

99-
// Add just the ROM files to the list
100-
string[] actualRomFiles = Directory.GetFiles(installDir, "*", SearchOption.AllDirectories)
101-
.Where(file => !file.EndsWith(".m3u", StringComparison.OrdinalIgnoreCase))
102-
.ToArray();
99+
List<string> supportedFileTypes = GetEmulatorSupportedFileTypes(info);
100+
string[] actualRomFiles = GetRomFiles(installDir, supportedFileTypes);
103101

104102
foreach (var romFile in actualRomFiles) {
105103
roms.Add(new GameRom(Game.Name, romFile));
@@ -129,6 +127,42 @@ public override void Install(InstallActionArgs args)
129127
});
130128
}
131129

130+
private static string[] GetRomFiles(string installDir, List<string> supportedFileTypes)
131+
{
132+
if (supportedFileTypes == null || supportedFileTypes.Count == 0)
133+
{
134+
return Directory.GetFiles(installDir, "*", SearchOption.AllDirectories)
135+
.Where(file => !file.EndsWith(".m3u", StringComparison.OrdinalIgnoreCase))
136+
.ToArray();
137+
}
138+
else
139+
{
140+
return supportedFileTypes.SelectMany(
141+
fileType => Directory.GetFiles(installDir, "*." + fileType, SearchOption.AllDirectories)
142+
).ToArray();
143+
}
144+
}
145+
146+
private static List<string> GetEmulatorSupportedFileTypes(RomMGameInfo info)
147+
{
148+
if (info.Mapping.EmulatorProfile is CustomEmulatorProfile)
149+
{
150+
var customProfile = info.Mapping.EmulatorProfile as CustomEmulatorProfile;
151+
return customProfile.ImageExtensions;
152+
}
153+
else if (info.Mapping.EmulatorProfile is BuiltInEmulatorProfile)
154+
{
155+
var builtInProfile = (info.Mapping.EmulatorProfile as BuiltInEmulatorProfile);
156+
return API.Instance.Emulation.Emulators
157+
.FirstOrDefault(e => e.Id == info.Mapping.Emulator.BuiltInConfigId)?
158+
.Profiles
159+
.FirstOrDefault(p => p.Name == builtInProfile.Name)?
160+
.ImageExtensions;
161+
}
162+
163+
return null;
164+
}
165+
132166
private static bool IsFileCompressed(string filePath)
133167
{
134168
try

0 commit comments

Comments
 (0)