Move around some error messages

See #2561.  From the point of view of romloader, this is all pretty simple:  It asks for a particular settings type.  It should either get null back (indicating there was nothing, use defaults), or an object of that type.  Providing a completely unrelated type is baloney.  So this check here is a stupid defensive check that shouldn't be needed.  MainForm cannot be trusted.
This commit is contained in:
nattthebear 2021-01-12 09:32:58 -05:00
parent 733862b070
commit 39c0011d09
1 changed files with 10 additions and 2 deletions

View File

@ -84,14 +84,22 @@ namespace BizHawk.Client.Common
private object GetCoreSettings(Type t, Type settingsType)
{
var e = new SettingsLoadArgs(t, settingsType);
OnLoadSettings?.Invoke(this, e);
if (OnLoadSettings == null)
throw new InvalidOperationException("Frontend failed to provide a settings getter");
OnLoadSettings(this, e);
if (e.Settings != null && e.Settings.GetType() != settingsType)
throw new InvalidOperationException($"Frontend did not provide the requested settings type: Expected {settingsType}, got {e.Settings.GetType()}");
return e.Settings;
}
private object GetCoreSyncSettings(Type t, Type syncSettingsType)
{
var e = new SettingsLoadArgs(t, syncSettingsType);
OnLoadSyncSettings?.Invoke(this, e);
if (OnLoadSyncSettings == null)
throw new InvalidOperationException("Frontend failed to provide a sync settings getter");
OnLoadSyncSettings(this, e);
if (e.Settings != null && e.Settings.GetType() != syncSettingsType)
throw new InvalidOperationException($"Frontend did not provide the requested sync settings type: Expected {syncSettingsType}, got {e.Settings.GetType()}");
return e.Settings;
}