diff --git a/src/BizHawk.Client.Common/RomLoader.cs b/src/BizHawk.Client.Common/RomLoader.cs
index 8f3c991f29..e2b6c3c81c 100644
--- a/src/BizHawk.Client.Common/RomLoader.cs
+++ b/src/BizHawk.Client.Common/RomLoader.cs
@@ -194,17 +194,10 @@ namespace BizHawk.Client.Common
private bool HandleArchiveBinding(HawkFile file)
{
- var romExtensions = new[]
- {
- ".sms", ".smc", ".sfc", ".pce", ".sgx", ".gg", ".sg", ".bin", ".gen", ".md", ".smd", ".gb",
- ".nes", ".fds", ".rom", ".int", ".gbc", ".unf", ".a78", ".crt", ".col", ".xml", ".z64",
- ".v64", ".n64", ".ws", ".wsc", ".gba", ".32x", ".vec", ".o2"
- };
-
// try binding normal rom extensions first
if (!file.IsBound)
{
- file.BindSoleItemOf(romExtensions);
+ file.BindSoleItemOf(RomFileExtensions.AutoloadFromArchive);
}
// if we have an archive and need to bind something, then pop the dialog
@@ -765,38 +758,94 @@ namespace BizHawk.Client.Common
}
}
+ /// roms ONLY; when an archive is loaded with a single file whose extension is one of these, the user prompt is skipped
+ private static class RomFileExtensions
+ {
+ public static readonly IReadOnlyCollection A78 = new[] { "a78" };
+
+ public static readonly IReadOnlyCollection C64 = new[] { "crt" };
+
+ public static readonly IReadOnlyCollection Coleco = new[] { "col" };
+
+ public static readonly IReadOnlyCollection GB = new[] { "gb", "gbc" };
+
+ public static readonly IReadOnlyCollection GBA = new[] { "gba" };
+
+ public static readonly IReadOnlyCollection GEN = new[] { "gen", "md", "smd", "32x" };
+
+ public static readonly IReadOnlyCollection INTV = new[] { "int", "bin", "rom" };
+
+ public static readonly IReadOnlyCollection N64 = new[] { "z64", "v64", "n64" };
+
+ public static readonly IReadOnlyCollection NES = new[] { "nes", "fds", "unf" };
+
+ public static readonly IReadOnlyCollection O2 = new[] { "o2" };
+
+ public static readonly IReadOnlyCollection PCE = new[] { "pce", "sgx" };
+
+ public static readonly IReadOnlyCollection SMS = new[] { "sms", "gg", "sg" };
+
+ public static readonly IReadOnlyCollection SNES = new[] { "smc", "sfc", "xml" };
+
+ public static readonly IReadOnlyCollection TI83 = new[] { "rom" };
+
+ public static readonly IReadOnlyCollection VEC = new[] { "vec" };
+
+ public static readonly IReadOnlyCollection WSWAN = new[] { "ws", "wsc" };
+
+ public static readonly IReadOnlyCollection AutoloadFromArchive = new string[0]
+ .Concat(A78)
+ .Concat(C64)
+ .Concat(Coleco)
+ .Concat(GB)
+ .Concat(GBA)
+ .Concat(GEN)
+ .Concat(INTV)
+ .Concat(N64)
+ .Concat(NES)
+ .Concat(O2)
+ .Concat(PCE)
+ .Concat(SMS)
+ .Concat(SNES)
+ .Concat(TI83)
+ .Concat(VEC)
+ .Concat(WSWAN)
+ .Select(static s => $".{s}") // this is what's expected at call-site
+ .ToArray();
+ }
+
/// TODO add and handle (you can drag-and-drop scripts and there are already non-rom things in this list, so why not?)
private static readonly FilesystemFilterSet RomFSFilterSet = new FilesystemFilterSet(
new FilesystemFilter("Music Files", new string[0], devBuildExtraExts: new[] { "psf", "minipsf", "sid", "nsf" }),
new FilesystemFilter("Disc Images", new[] { "cue", "ccd", "mds", "m3u" }),
- new FilesystemFilter("NES", new[] { "nes", "fds", "unf", "nsf" }, addArchiveExts: true),
- new FilesystemFilter("Super NES", new[] { "smc", "sfc", "xml" }, addArchiveExts: true),
+ new FilesystemFilter("NES", RomFileExtensions.NES.Concat(new[] { "nsf" }).ToList(), addArchiveExts: true),
+ new FilesystemFilter("Super NES", RomFileExtensions.SNES, addArchiveExts: true),
new FilesystemFilter("PlayStation", new[] { "cue", "ccd", "mds", "m3u" }),
new FilesystemFilter("PSX Executables (experimental)", new string[0], devBuildExtraExts: new[] { "exe" }),
new FilesystemFilter("PSF Playstation Sound File", new[] { "psf", "minipsf" }),
- new FilesystemFilter("Nintendo 64", new[] { "z64", "v64", "n64" }),
- new FilesystemFilter("Gameboy", new[] { "gb", "gbc", "sgb" }, addArchiveExts: true),
- new FilesystemFilter("Gameboy Advance", new[] { "gba" }, addArchiveExts: true),
+ new FilesystemFilter("Nintendo 64", RomFileExtensions.N64),
+ new FilesystemFilter("Gameboy", RomFileExtensions.GB.Concat(new[] { "sgb" }).ToList(), addArchiveExts: true),
+ new FilesystemFilter("Gameboy Advance", RomFileExtensions.GBA, addArchiveExts: true),
new FilesystemFilter("Nintendo DS", new[] { "nds" }),
- new FilesystemFilter("Master System", new[] { "sms", "gg", "sg" }, addArchiveExts: true),
- new FilesystemFilter("PC Engine", new[] { "pce", "sgx", "cue", "ccd", "mds" }, addArchiveExts: true),
+ new FilesystemFilter("Master System", RomFileExtensions.SMS, addArchiveExts: true),
+ new FilesystemFilter("PC Engine", RomFileExtensions.PCE.Concat(new[] { "cue", "ccd", "mds" }).ToList(), addArchiveExts: true),
new FilesystemFilter("Atari 2600", new[] { "a26" }, devBuildExtraExts: new[] { "bin" }, addArchiveExts: true),
- new FilesystemFilter("Atari 7800", new[] { "a78" }, devBuildExtraExts: new[] { "bin" }, addArchiveExts: true),
+ new FilesystemFilter("Atari 7800", RomFileExtensions.A78, devBuildExtraExts: new[] { "bin" }, addArchiveExts: true),
new FilesystemFilter("Atari Lynx", new[] { "lnx" }, addArchiveExts: true),
- new FilesystemFilter("ColecoVision", new[] { "col" }, addArchiveExts: true),
- new FilesystemFilter("IntelliVision", new[] { "int", "bin", "rom" }, addArchiveExts: true),
- new FilesystemFilter("TI-83", new[] { "rom" }, addArchiveExts: true),
+ new FilesystemFilter("ColecoVision", RomFileExtensions.Coleco, addArchiveExts: true),
+ new FilesystemFilter("IntelliVision", RomFileExtensions.INTV, addArchiveExts: true),
+ new FilesystemFilter("TI-83", RomFileExtensions.TI83, addArchiveExts: true),
FilesystemFilter.Archives,
- new FilesystemFilter("Genesis", new[] { "gen", "md", "smd", "32x", "bin", "cue", "ccd" }, addArchiveExts: true),
+ new FilesystemFilter("Genesis", RomFileExtensions.GEN.Concat(new[] { "bin", "cue", "ccd" }).ToList(), addArchiveExts: true),
new FilesystemFilter("SID Commodore 64 Music File", new string[0], devBuildExtraExts: new[] { "sid" }, devBuildAddArchiveExts: true),
- new FilesystemFilter("WonderSwan", new[] { "ws", "wsc" }, addArchiveExts: true),
+ new FilesystemFilter("WonderSwan", RomFileExtensions.WSWAN, addArchiveExts: true),
new FilesystemFilter("Apple II", new[] { "dsk", "do", "po" }, addArchiveExts: true),
new FilesystemFilter("Virtual Boy", new[] { "vb" }, addArchiveExts: true),
new FilesystemFilter("Neo Geo Pocket", new[] { "ngp", "ngc" }, addArchiveExts: true),
- new FilesystemFilter("Commodore 64", new[] { "prg", "d64", "g64", "crt", "tap" }, addArchiveExts: true),
+ new FilesystemFilter("Commodore 64", new[] { "prg", "d64", "g64" }.Concat(RomFileExtensions.C64).Concat(new[] { "tap" }).ToList(), addArchiveExts: true),
new FilesystemFilter("Amstrad CPC", new string[0], devBuildExtraExts: new[] { "cdt", "dsk" }, devBuildAddArchiveExts: true),
new FilesystemFilter("Sinclair ZX Spectrum", new[] { "tzx", "tap", "dsk", "pzx", "csw", "wav" }, addArchiveExts: true),
- new FilesystemFilter("Odyssey 2", new[] { "o2" }),
+ new FilesystemFilter("Odyssey 2", RomFileExtensions.O2),
new FilesystemFilter("Uzebox", new[] { "uze" }),
FilesystemFilter.EmuHawkSaveStates
);
diff --git a/src/BizHawk.Common/HawkFile/HawkFile.cs b/src/BizHawk.Common/HawkFile/HawkFile.cs
index 56318dbdf8..60de7453f4 100644
--- a/src/BizHawk.Common/HawkFile/HawkFile.cs
+++ b/src/BizHawk.Common/HawkFile/HawkFile.cs
@@ -182,14 +182,14 @@ namespace BizHawk.Common
/// File extensions; include the leading period in each, and use lowercase.
/// stream already bound
- private HawkFile BindByExtensionCore(string[] extensions, bool onlyBindSingle = false)
+ private HawkFile BindByExtensionCore(IReadOnlyCollection extensions, bool onlyBindSingle = false)
{
if (!_rootExists) return this;
if (_boundStream != null) throw new InvalidOperationException("stream already bound!");
if (!(_archiveItems == null || _extractor == null))
{
- if (extensions.Length != 0)
+ if (extensions.Count != 0)
{
var candidates = _archiveItems.Where(item => extensions.Contains(Path.GetExtension(item.Name).ToLowerInvariant())).ToList();
if (onlyBindSingle ? candidates.Count == 1 : candidates.Count != 0) BindArchiveMember(candidates[0].Index);
@@ -207,7 +207,7 @@ namespace BizHawk.Common
}
// open uncompressed file
- if (extensions.Length == 0
+ if (extensions.Count == 0
|| extensions.Contains(Path.GetExtension(FullPathWithoutMember).ToLowerInvariant()))
{
BindRoot();
@@ -225,7 +225,7 @@ namespace BizHawk.Common
///
/// File extensions; include the leading period in each, and use lowercase.
/// You probably should use or the archive chooser instead.
- public HawkFile BindFirstOf(string[] extensions) => BindByExtensionCore(extensions);
+ public HawkFile BindFirstOf(IReadOnlyCollection extensions) => BindByExtensionCore(extensions);
///
/// Binds the first archive member whose file extension is if one exists,
@@ -242,9 +242,9 @@ namespace BizHawk.Common
Util.DebugWriteLine($"{nameof(HawkFile)} bound {CanonicalFullPath}");
}
- /// As , but doesn't bind anything if there are multiple archive members with a matching file extension.
+ /// As , but doesn't bind anything if there are multiple archive members with a matching file extension.
/// File extensions; include the leading period in each, and use lowercase.
- public HawkFile BindSoleItemOf(string[] extensions) => BindByExtensionCore(extensions, onlyBindSingle: true);
+ public HawkFile BindSoleItemOf(IReadOnlyCollection extensions) => BindByExtensionCore(extensions, onlyBindSingle: true);
public void Dispose()
{