From cc7e440fbaf65d6e2d4834ba232cc4500fa7fea8 Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Tue, 23 Feb 2021 05:35:05 +1000 Subject: [PATCH] Cleanup usage of Config.PreferredPlatformsForExtensions --- src/BizHawk.Client.Common/RomLoader.cs | 18 +++--------------- src/BizHawk.Client.Common/config/Config.cs | 14 +++++++++----- .../config/ConfigExtensions.cs | 14 ++++++++++++++ 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/src/BizHawk.Client.Common/RomLoader.cs b/src/BizHawk.Client.Common/RomLoader.cs index cbb22c7a62..fdb5e6d251 100644 --- a/src/BizHawk.Client.Common/RomLoader.cs +++ b/src/BizHawk.Client.Common/RomLoader.cs @@ -191,16 +191,6 @@ namespace BizHawk.Client.Common OnLoadError?.Invoke(this, new RomErrorArgs(message, systemId, path, det, type)); } - private bool PreferredPlatformIsDefined(string extension) - { - if (_config.PreferredPlatformsForExtensions.ContainsKey(extension)) - { - return !string.IsNullOrEmpty(_config.PreferredPlatformsForExtensions[extension]); - } - - return false; - } - public IOpenAdvanced OpenAdvanced { get; set; } private bool HandleArchiveBinding(HawkFile file) @@ -290,9 +280,7 @@ namespace BizHawk.Client.Common case DiscType.AudioDisc: case DiscType.UnknownCDFS: case DiscType.UnknownFormat: - game.System = PreferredPlatformIsDefined(ext) - ? _config.PreferredPlatformsForExtensions[ext] - : "NULL"; + game.System = _config.TryGetChosenSystemForFileExt(ext, out var sysID) ? sysID : "NULL"; break; default: //"for an unknown disc, default to psx instead of pce-cd, since that is far more likely to be what they are attempting to open" [5e07ab3ec3b8b8de9eae71b489b55d23a3909f55, year 2015] @@ -439,9 +427,9 @@ namespace BizHawk.Client.Common if (string.IsNullOrEmpty(rom.GameInfo.System)) { // Has the user picked a preference for this extension? - if (PreferredPlatformIsDefined(rom.Extension.ToLowerInvariant())) + if (_config.TryGetChosenSystemForFileExt(rom.Extension.ToLowerInvariant(), out var systemID)) { - rom.GameInfo.System = _config.PreferredPlatformsForExtensions[rom.Extension.ToLowerInvariant()]; + rom.GameInfo.System = systemID; } else if (ChoosePlatform != null) { diff --git a/src/BizHawk.Client.Common/config/Config.cs b/src/BizHawk.Client.Common/config/Config.cs index 3b84bf5d79..473558f870 100644 --- a/src/BizHawk.Client.Common/config/Config.cs +++ b/src/BizHawk.Client.Common/config/Config.cs @@ -38,14 +38,18 @@ namespace BizHawk.Client.Common PathEntries.RefreshTempPath(); } - // Core preference for generic file extension, key: file extension, value: a systemID or empty if no preference + /// + /// Used to determine the system a rom is classified as (and thus which core to use) for the times when our romloading autodetect magic can't determine a system. + /// Keys are file extensions, include the leading period in each, and use lowercase; + /// values are system IDs, use for unset (though should also work, omitting will remove from UI). + /// public Dictionary PreferredPlatformsForExtensions { get; set; } = new Dictionary { - [".bin"] = "", - [".rom"] = "", - [".iso"] = "", + [".bin"] = "", + [".cue"] = "", [".img"] = "", - [".cue"] = "" + [".iso"] = "", + [".rom"] = "", }; public PathEntryCollection PathEntries { get; set; } = new PathEntryCollection(); diff --git a/src/BizHawk.Client.Common/config/ConfigExtensions.cs b/src/BizHawk.Client.Common/config/ConfigExtensions.cs index 53c7b14bed..5041dc497e 100644 --- a/src/BizHawk.Client.Common/config/ConfigExtensions.cs +++ b/src/BizHawk.Client.Common/config/ConfigExtensions.cs @@ -135,5 +135,19 @@ namespace BizHawk.Client.Common { config.PutCoreSyncSettings(o, typeof(TCore)); } + + /// file extension, including the leading period and in lowercase + /// will be if returned value is + public static bool TryGetChosenSystemForFileExt(this Config config, string fileExt, out string systemID) + { + var b = config.PreferredPlatformsForExtensions.TryGetValue(fileExt, out var v); + if (b && !string.IsNullOrEmpty(v)) + { + systemID = v; + return true; + } + systemID = null; + return false; + } } }