Create a MissingFirmwareException in Emulation.Common, and catch this in the Rom loading logic, on the client side, respond to this type of error with a nice message and an option to configure their firmware. Have NesHawk throw this exception when there is a missing FDS Bios. Other cores will need to be implemented this way too at some point

This commit is contained in:
adelikat 2014-07-31 21:15:07 +00:00
parent 0fd5ddd0cf
commit ad5b60f137
6 changed files with 51 additions and 13 deletions

View File

@ -29,6 +29,8 @@ namespace BizHawk.Client.Common
{ {
public class RomLoader public class RomLoader
{ {
public enum LoadErrorType { Unknown, MissingFirmware, XML }
// helper methods for the settings events // helper methods for the settings events
private object GetCoreSettings<T>() private object GetCoreSettings<T>()
where T : IEmulator where T : IEmulator
@ -70,14 +72,16 @@ namespace BizHawk.Client.Common
public class RomErrorArgs : EventArgs public class RomErrorArgs : EventArgs
{ {
// TODO: think about naming here, what to pass, a lot of potential good information about what went wrong could go here! // TODO: think about naming here, what to pass, a lot of potential good information about what went wrong could go here!
public RomErrorArgs(string message, string systemId) public RomErrorArgs(string message, string systemId, LoadErrorType type)
{ {
Message = message; Message = message;
AttemptedCoreLoad = systemId; AttemptedCoreLoad = systemId;
Type = type;
} }
public string Message { get; private set; } public string Message { get; private set; }
public string AttemptedCoreLoad { get; private set; } public string AttemptedCoreLoad { get; private set; }
public LoadErrorType Type { get; private set; }
} }
public class SettingsLoadArgs : EventArgs public class SettingsLoadArgs : EventArgs
@ -112,11 +116,11 @@ namespace BizHawk.Client.Common
return null; return null;
} }
private void ThrowLoadError(string message, string systemId) private void DoLoadErrorCallback(string message, string systemId, LoadErrorType type = LoadErrorType.Unknown)
{ {
if (OnLoadError != null) if (OnLoadError != null)
{ {
OnLoadError(this, new RomErrorArgs(message, systemId)); OnLoadError(this, new RomErrorArgs(message, systemId, type));
} }
} }
@ -270,7 +274,7 @@ namespace BizHawk.Client.Common
} }
catch (Exception ex) catch (Exception ex)
{ {
ThrowLoadError(ex.ToString(), "XMLGame Load Error"); // TODO: don't pass in XMLGame Load Error as a system ID DoLoadErrorCallback(ex.ToString(), "DGB", LoadErrorType.XML);
return false; return false;
} }
} }
@ -387,7 +391,7 @@ namespace BizHawk.Client.Common
catch catch
{ {
// failed to load SGB bios. to avoid catch-22, disable SGB mode // failed to load SGB bios. to avoid catch-22, disable SGB mode
ThrowLoadError("Failed to load a GB rom in SGB mode. Disabling SGB Mode.", game.System); DoLoadErrorCallback("Failed to load a GB rom in SGB mode. Disabling SGB Mode.", game.System);
Global.Config.GB_AsSGB = false; Global.Config.GB_AsSGB = false;
throw; throw;
} }
@ -433,7 +437,7 @@ namespace BizHawk.Client.Common
if (nextEmulator == null) if (nextEmulator == null)
{ {
ThrowLoadError("No core could load the rom.", null); DoLoadErrorCallback("No core could load the rom.", null);
return false; return false;
} }
} }
@ -450,9 +454,13 @@ namespace BizHawk.Client.Common
{ {
return LoadRom(path, nextComm, forceAccurateCore: true); return LoadRom(path, nextComm, forceAccurateCore: true);
} }
else if (ex is MissingFirmwareException)
{
DoLoadErrorCallback(ex.Message, system, LoadErrorType.MissingFirmware);
}
else else
{ {
ThrowLoadError("A core accepted the rom, but threw an exception while loading it:\n\n" + ex, system); DoLoadErrorCallback("A core accepted the rom, but threw an exception while loading it:\n\n" + ex, system);
} }
return false; return false;

View File

@ -3021,11 +3021,28 @@ namespace BizHawk.Client.EmuHawk
private void ShowLoadError(object sender, RomLoader.RomErrorArgs e) private void ShowLoadError(object sender, RomLoader.RomErrorArgs e)
{ {
string title = "load error"; if (e.Type == RomLoader.LoadErrorType.MissingFirmware)
if (e.AttemptedCoreLoad != null) {
title = e.AttemptedCoreLoad + " load error"; var result = MessageBox.Show(
"You are missing the needed firmware files to load this Rom\n\nWould you like to open the firmware manager now and configure your firmwares?",
e.Message,
MessageBoxButtons.YesNo,
MessageBoxIcon.Error);
if (result == DialogResult.Yes)
{
FirmwaresMenuItem_Click(null, null);
}
}
else
{
string title = "load error";
if (e.AttemptedCoreLoad != null)
{
title = e.AttemptedCoreLoad + " load error";
}
MessageBox.Show(this, e.Message, title, MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show(this, e.Message, title, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
} }
private void NotifyCoreComm(string message) private void NotifyCoreComm(string message)

View File

@ -76,7 +76,7 @@ namespace BizHawk.Client.EmuHawk
void OnLoadError(object sender, RomLoader.RomErrorArgs e) void OnLoadError(object sender, RomLoader.RomErrorArgs e)
{ {
current.Status = Result.EStatus.ErrorOnLoad; current.Status = Result.EStatus.ErrorOnLoad;
current.Messages.Add(string.Format("OnLoadError: {0}, {1}", e.AttemptedCoreLoad, e.Message)); current.Messages.Add(string.Format("OnLoadError: {0}, {1}, {2}", e.AttemptedCoreLoad, e.Message, e.Type.ToString()));
} }
void CommMessage(string msg) void CommMessage(string msg)

View File

@ -54,6 +54,7 @@
<Compile Include="Database\Database.cs" /> <Compile Include="Database\Database.cs" />
<Compile Include="Database\FirmwareDatabase.cs" /> <Compile Include="Database\FirmwareDatabase.cs" />
<Compile Include="Database\GameInfo.cs" /> <Compile Include="Database\GameInfo.cs" />
<Compile Include="EmulationExceptions.cs" />
<Compile Include="Extensions.cs" /> <Compile Include="Extensions.cs" />
<Compile Include="Interfaces\Base Implementations\NullController.cs" /> <Compile Include="Interfaces\Base Implementations\NullController.cs" />
<Compile Include="Interfaces\Base Implementations\NullEmulator.cs" /> <Compile Include="Interfaces\Base Implementations\NullEmulator.cs" />

View File

@ -0,0 +1,12 @@
using System;
namespace BizHawk.Emulation.Common
{
public class MissingFirmwareException : Exception
{
public MissingFirmwareException(string message) : base(message)
{
}
}
}

View File

@ -511,7 +511,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
origin = EDetectionOrigin.FDS; origin = EDetectionOrigin.FDS;
LoadWriteLine("Found FDS header."); LoadWriteLine("Found FDS header.");
if (fdsbios == null) if (fdsbios == null)
throw new Exception("Missing FDS Bios!"); throw new MissingFirmwareException("Missing FDS Bios");
cart = new CartInfo(); cart = new CartInfo();
var fdsboard = new FDS(); var fdsboard = new FDS();
fdsboard.biosrom = fdsbios; fdsboard.biosrom = fdsbios;