Cleanup usage of Config.PreferredPlatformsForExtensions
This commit is contained in:
parent
4103a8bab2
commit
cc7e440fba
|
@ -191,16 +191,6 @@ namespace BizHawk.Client.Common
|
||||||
OnLoadError?.Invoke(this, new RomErrorArgs(message, systemId, path, det, type));
|
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; }
|
public IOpenAdvanced OpenAdvanced { get; set; }
|
||||||
|
|
||||||
private bool HandleArchiveBinding(HawkFile file)
|
private bool HandleArchiveBinding(HawkFile file)
|
||||||
|
@ -290,9 +280,7 @@ namespace BizHawk.Client.Common
|
||||||
case DiscType.AudioDisc:
|
case DiscType.AudioDisc:
|
||||||
case DiscType.UnknownCDFS:
|
case DiscType.UnknownCDFS:
|
||||||
case DiscType.UnknownFormat:
|
case DiscType.UnknownFormat:
|
||||||
game.System = PreferredPlatformIsDefined(ext)
|
game.System = _config.TryGetChosenSystemForFileExt(ext, out var sysID) ? sysID : "NULL";
|
||||||
? _config.PreferredPlatformsForExtensions[ext]
|
|
||||||
: "NULL";
|
|
||||||
break;
|
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]
|
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))
|
if (string.IsNullOrEmpty(rom.GameInfo.System))
|
||||||
{
|
{
|
||||||
// Has the user picked a preference for this extension?
|
// 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)
|
else if (ChoosePlatform != null)
|
||||||
{
|
{
|
||||||
|
|
|
@ -38,14 +38,18 @@ namespace BizHawk.Client.Common
|
||||||
PathEntries.RefreshTempPath();
|
PathEntries.RefreshTempPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Core preference for generic file extension, key: file extension, value: a systemID or empty if no preference
|
/// <summary>
|
||||||
|
/// 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 <see cref="string.Empty"/> for unset (though <see langword="null"/> should also work, omitting will remove from UI).
|
||||||
|
/// </summary>
|
||||||
public Dictionary<string, string> PreferredPlatformsForExtensions { get; set; } = new Dictionary<string, string>
|
public Dictionary<string, string> PreferredPlatformsForExtensions { get; set; } = new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
[".bin"] = "",
|
[".bin"] = "",
|
||||||
[".rom"] = "",
|
[".cue"] = "",
|
||||||
[".iso"] = "",
|
|
||||||
[".img"] = "",
|
[".img"] = "",
|
||||||
[".cue"] = ""
|
[".iso"] = "",
|
||||||
|
[".rom"] = "",
|
||||||
};
|
};
|
||||||
|
|
||||||
public PathEntryCollection PathEntries { get; set; } = new PathEntryCollection();
|
public PathEntryCollection PathEntries { get; set; } = new PathEntryCollection();
|
||||||
|
|
|
@ -135,5 +135,19 @@ namespace BizHawk.Client.Common
|
||||||
{
|
{
|
||||||
config.PutCoreSyncSettings(o, typeof(TCore));
|
config.PutCoreSyncSettings(o, typeof(TCore));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <param name="fileExt">file extension, including the leading period and in lowercase</param>
|
||||||
|
/// <remarks><paramref name="systemID"/> will be <see langword="null"/> if returned value is <see langword="false"/></remarks>
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue