diff --git a/BizHawk.Client.Common/RomLoader.cs b/BizHawk.Client.Common/RomLoader.cs index a61dc5eca7..c1798cf099 100644 --- a/BizHawk.Client.Common/RomLoader.cs +++ b/BizHawk.Client.Common/RomLoader.cs @@ -29,6 +29,8 @@ namespace BizHawk.Client.Common { public class RomLoader { + public enum LoadErrorType { Unknown, MissingFirmware, XML } + // helper methods for the settings events private object GetCoreSettings() where T : IEmulator @@ -70,14 +72,16 @@ namespace BizHawk.Client.Common 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! - public RomErrorArgs(string message, string systemId) + public RomErrorArgs(string message, string systemId, LoadErrorType type) { Message = message; AttemptedCoreLoad = systemId; + Type = type; } public string Message { get; private set; } public string AttemptedCoreLoad { get; private set; } + public LoadErrorType Type { get; private set; } } public class SettingsLoadArgs : EventArgs @@ -112,11 +116,11 @@ namespace BizHawk.Client.Common return null; } - private void ThrowLoadError(string message, string systemId) + private void DoLoadErrorCallback(string message, string systemId, LoadErrorType type = LoadErrorType.Unknown) { 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) { - 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; } } @@ -387,7 +391,7 @@ namespace BizHawk.Client.Common catch { // 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; throw; } @@ -433,7 +437,7 @@ namespace BizHawk.Client.Common if (nextEmulator == null) { - ThrowLoadError("No core could load the rom.", null); + DoLoadErrorCallback("No core could load the rom.", null); return false; } } @@ -450,9 +454,13 @@ namespace BizHawk.Client.Common { return LoadRom(path, nextComm, forceAccurateCore: true); } + else if (ex is MissingFirmwareException) + { + DoLoadErrorCallback(ex.Message, system, LoadErrorType.MissingFirmware); + } 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; diff --git a/BizHawk.Client.EmuHawk/MainForm.cs b/BizHawk.Client.EmuHawk/MainForm.cs index a0c33b1d64..39b244df22 100644 --- a/BizHawk.Client.EmuHawk/MainForm.cs +++ b/BizHawk.Client.EmuHawk/MainForm.cs @@ -3021,11 +3021,28 @@ namespace BizHawk.Client.EmuHawk private void ShowLoadError(object sender, RomLoader.RomErrorArgs e) { - string title = "load error"; - if (e.AttemptedCoreLoad != null) - title = e.AttemptedCoreLoad + " load error"; + if (e.Type == RomLoader.LoadErrorType.MissingFirmware) + { + 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) diff --git a/BizHawk.Client.EmuHawk/tools/BatchRunner.cs b/BizHawk.Client.EmuHawk/tools/BatchRunner.cs index 298745f5d9..0ff62713e3 100644 --- a/BizHawk.Client.EmuHawk/tools/BatchRunner.cs +++ b/BizHawk.Client.EmuHawk/tools/BatchRunner.cs @@ -76,7 +76,7 @@ namespace BizHawk.Client.EmuHawk void OnLoadError(object sender, RomLoader.RomErrorArgs e) { 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) diff --git a/BizHawk.Emulation.Common/BizHawk.Emulation.Common.csproj b/BizHawk.Emulation.Common/BizHawk.Emulation.Common.csproj index f4d05929e4..037e7b02e1 100644 --- a/BizHawk.Emulation.Common/BizHawk.Emulation.Common.csproj +++ b/BizHawk.Emulation.Common/BizHawk.Emulation.Common.csproj @@ -54,6 +54,7 @@ + diff --git a/BizHawk.Emulation.Common/EmulationExceptions.cs b/BizHawk.Emulation.Common/EmulationExceptions.cs new file mode 100644 index 0000000000..dfaacced90 --- /dev/null +++ b/BizHawk.Emulation.Common/EmulationExceptions.cs @@ -0,0 +1,12 @@ +using System; + +namespace BizHawk.Emulation.Common +{ + public class MissingFirmwareException : Exception + { + public MissingFirmwareException(string message) : base(message) + { + + } + } +} diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.cs index 058f321f98..d8338adfc6 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.cs @@ -511,7 +511,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES origin = EDetectionOrigin.FDS; LoadWriteLine("Found FDS header."); if (fdsbios == null) - throw new Exception("Missing FDS Bios!"); + throw new MissingFirmwareException("Missing FDS Bios"); cart = new CartInfo(); var fdsboard = new FDS(); fdsboard.biosrom = fdsbios;