From 667e4273f38e67ddad23553ff9cd695b434c59ad Mon Sep 17 00:00:00 2001 From: scrimpeh Date: Sun, 12 Jul 2015 21:30:26 +0200 Subject: [PATCH] Firmware Manager - Add option to reload ROM if ROM load has failed before --- BizHawk.Client.Common/RomLoader.cs | 23 ++++++- BizHawk.Client.EmuHawk/MainForm.Events.cs | 11 +++- BizHawk.Client.EmuHawk/MainForm.cs | 18 +++++- .../config/FirmwaresConfig.Designer.cs | 62 ++++++++++++++++--- .../config/FirmwaresConfig.cs | 27 ++++++-- .../config/FirmwaresConfig.resx | 30 +++++++++ 6 files changed, 152 insertions(+), 19 deletions(-) diff --git a/BizHawk.Client.Common/RomLoader.cs b/BizHawk.Client.Common/RomLoader.cs index 9cbdd7b374..2d004f8984 100644 --- a/BizHawk.Client.Common/RomLoader.cs +++ b/BizHawk.Client.Common/RomLoader.cs @@ -99,8 +99,18 @@ namespace BizHawk.Client.Common Type = type; } + public RomErrorArgs(string message, string systemId, string path, bool? det, LoadErrorType type) + : this(message, systemId, type) + { + Deterministic = det; + RomPath = path; + } + public string Message { get; private set; } public string AttemptedCoreLoad { get; private set; } + public string RomPath { get; private set; } + public bool? Deterministic { get; set; } + public bool Retry { get; set; } public LoadErrorType Type { get; private set; } } @@ -119,7 +129,7 @@ namespace BizHawk.Client.Common public event SettingsLoadEventHandler OnLoadSettings; public event SettingsLoadEventHandler OnLoadSyncSettings; - public delegate void LoadErrorEventHandler(object sener, RomErrorArgs e); + public delegate void LoadErrorEventHandler(object sender, RomErrorArgs e); public event LoadErrorEventHandler OnLoadError; public Func ChooseArchive { get; set; } @@ -142,6 +152,7 @@ namespace BizHawk.Client.Common return null; } + //May want to phase out this method in favor of the overload with more paramaters private void DoLoadErrorCallback(string message, string systemId, LoadErrorType type = LoadErrorType.Unknown) { if (OnLoadError != null) @@ -150,6 +161,14 @@ namespace BizHawk.Client.Common } } + private void DoLoadErrorCallback(string message, string systemId, string path, bool det, LoadErrorType type = LoadErrorType.Unknown) + { + if (OnLoadError != null) + { + OnLoadError(this, new RomErrorArgs(message, systemId, path, det, type)); + } + } + private bool PreferredPlatformIsDefined(string extension) { if (Global.Config.PreferredPlatformsForExtensions.ContainsKey(extension)) @@ -595,7 +614,7 @@ namespace BizHawk.Client.Common } else if (ex is MissingFirmwareException) { - DoLoadErrorCallback(ex.Message, system, LoadErrorType.MissingFirmware); + DoLoadErrorCallback(ex.Message, system, path, Deterministic, LoadErrorType.MissingFirmware); } else if (ex is CGBNotSupportedException) { diff --git a/BizHawk.Client.EmuHawk/MainForm.Events.cs b/BizHawk.Client.EmuHawk/MainForm.Events.cs index c66f54e198..780d5878c8 100644 --- a/BizHawk.Client.EmuHawk/MainForm.Events.cs +++ b/BizHawk.Client.EmuHawk/MainForm.Events.cs @@ -880,7 +880,16 @@ namespace BizHawk.Client.EmuHawk private void FirmwaresMenuItem_Click(object sender, EventArgs e) { - new FirmwaresConfig().ShowDialog(); + if (e is RomLoader.RomErrorArgs) + { + var args = e as RomLoader.RomErrorArgs; + var firmwaredialog = new FirmwaresConfig(true).ShowDialog(); + args.Retry = firmwaredialog == DialogResult.Retry; + } + else + { + new FirmwaresConfig().ShowDialog(); + } } private void MessagesMenuItem_Click(object sender, EventArgs e) diff --git a/BizHawk.Client.EmuHawk/MainForm.cs b/BizHawk.Client.EmuHawk/MainForm.cs index b76d82aa42..e4431fce41 100644 --- a/BizHawk.Client.EmuHawk/MainForm.cs +++ b/BizHawk.Client.EmuHawk/MainForm.cs @@ -3229,7 +3229,14 @@ namespace BizHawk.Client.EmuHawk MessageBoxIcon.Error); if (result == DialogResult.Yes) { - FirmwaresMenuItem_Click(null, null); + FirmwaresMenuItem_Click(null, e); + if (e.Retry) + { + // Retry loading the ROM here. This leads to recursion, as the original call to LoadRom has not exited yet, + // but unless the user tries and fails to set his firmware a lot of times, nothing should happen. + // Refer to how RomLoader implemented its LoadRom method for a potential fix on this. + LoadRom(e.RomPath, e.Deterministic); + } } } else @@ -3409,6 +3416,13 @@ namespace BizHawk.Client.EmuHawk { //This shows up if there's a problem // TODO: put all these in a single method or something + + //The ROM has been loaded by a recursive invocation of the LoadROM method. + if (!(Global.Emulator is NullEmulator)) + { + return true; + } + HandlePlatformMenus(); _stateSlots.Clear(); UpdateStatusSlots(); @@ -3517,7 +3531,7 @@ namespace BizHawk.Client.EmuHawk GameIsClosing = false; } - public bool GameIsClosing { get; set; } // Let's tools make better decisions when being called by CloseGame + public bool GameIsClosing { get; set; } // Lets tools make better decisions when being called by CloseGame public void CloseRom(bool clearSram = false) { diff --git a/BizHawk.Client.EmuHawk/config/FirmwaresConfig.Designer.cs b/BizHawk.Client.EmuHawk/config/FirmwaresConfig.Designer.cs index a01cf344d6..332e2f0f91 100644 --- a/BizHawk.Client.EmuHawk/config/FirmwaresConfig.Designer.cs +++ b/BizHawk.Client.EmuHawk/config/FirmwaresConfig.Designer.cs @@ -52,6 +52,9 @@ this.tbbScan = new System.Windows.Forms.ToolStripButton(); this.tbbOrganize = new System.Windows.Forms.ToolStripButton(); this.tbbImport = new System.Windows.Forms.ToolStripButton(); + this.tbbClose = new System.Windows.Forms.ToolStripButton(); + this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); + this.tbbCloseReload = new System.Windows.Forms.ToolStripButton(); this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); this.panel2 = new System.Windows.Forms.Panel(); this.linkBasePath = new System.Windows.Forms.LinkLabel(); @@ -145,34 +148,34 @@ this.tsmiInfo, this.tsmiCopy}); this.lvFirmwaresContextMenuStrip.Name = "lvFirmwaresContextMenuStrip"; - this.lvFirmwaresContextMenuStrip.Size = new System.Drawing.Size(170, 92); + this.lvFirmwaresContextMenuStrip.Size = new System.Drawing.Size(182, 92); this.lvFirmwaresContextMenuStrip.Opening += new System.ComponentModel.CancelEventHandler(this.lvFirmwaresContextMenuStrip_Opening); // // tsmiSetCustomization // this.tsmiSetCustomization.Name = "tsmiSetCustomization"; - this.tsmiSetCustomization.Size = new System.Drawing.Size(169, 22); + this.tsmiSetCustomization.Size = new System.Drawing.Size(181, 22); this.tsmiSetCustomization.Text = "&Set Customization"; this.tsmiSetCustomization.Click += new System.EventHandler(this.tsmiSetCustomization_Click); // // tsmiClearCustomization // this.tsmiClearCustomization.Name = "tsmiClearCustomization"; - this.tsmiClearCustomization.Size = new System.Drawing.Size(169, 22); + this.tsmiClearCustomization.Size = new System.Drawing.Size(181, 22); this.tsmiClearCustomization.Text = "C&lear Customization"; this.tsmiClearCustomization.Click += new System.EventHandler(this.tsmiClearCustomization_Click); // // tsmiInfo // this.tsmiInfo.Name = "tsmiInfo"; - this.tsmiInfo.Size = new System.Drawing.Size(169, 22); + this.tsmiInfo.Size = new System.Drawing.Size(181, 22); this.tsmiInfo.Text = "&Info"; this.tsmiInfo.Click += new System.EventHandler(this.tsmiInfo_Click); // // tsmiCopy // this.tsmiCopy.Name = "tsmiCopy"; - this.tsmiCopy.Size = new System.Drawing.Size(169, 22); + this.tsmiCopy.Size = new System.Drawing.Size(181, 22); this.tsmiCopy.Text = "&Copy"; this.tsmiCopy.Click += new System.EventHandler(this.tsmiCopy_Click); // @@ -194,7 +197,10 @@ this.toolStripSeparator2, this.tbbScan, this.tbbOrganize, - this.tbbImport}); + this.tbbImport, + this.tbbClose, + this.toolStripSeparator1, + this.tbbCloseReload}); this.toolStrip1.Location = new System.Drawing.Point(0, 0); this.toolStrip1.Name = "toolStrip1"; this.toolStrip1.Size = new System.Drawing.Size(824, 25); @@ -210,7 +216,7 @@ this.tbbGroup.Image = ((System.Drawing.Image)(resources.GetObject("tbbGroup.Image"))); this.tbbGroup.ImageTransparentColor = System.Drawing.Color.Magenta; this.tbbGroup.Name = "tbbGroup"; - this.tbbGroup.Size = new System.Drawing.Size(40, 22); + this.tbbGroup.Size = new System.Drawing.Size(44, 22); this.tbbGroup.Text = "Group"; this.tbbGroup.Click += new System.EventHandler(this.tbbGroup_Click); // @@ -225,7 +231,7 @@ this.tbbScan.Image = ((System.Drawing.Image)(resources.GetObject("tbbScan.Image"))); this.tbbScan.ImageTransparentColor = System.Drawing.Color.Magenta; this.tbbScan.Name = "tbbScan"; - this.tbbScan.Size = new System.Drawing.Size(34, 22); + this.tbbScan.Size = new System.Drawing.Size(36, 22); this.tbbScan.Text = "Scan"; this.tbbScan.Click += new System.EventHandler(this.tbbScan_Click); // @@ -235,7 +241,7 @@ this.tbbOrganize.Image = ((System.Drawing.Image)(resources.GetObject("tbbOrganize.Image"))); this.tbbOrganize.ImageTransparentColor = System.Drawing.Color.Magenta; this.tbbOrganize.Name = "tbbOrganize"; - this.tbbOrganize.Size = new System.Drawing.Size(54, 22); + this.tbbOrganize.Size = new System.Drawing.Size(58, 22); this.tbbOrganize.Text = "Organize"; this.tbbOrganize.Click += new System.EventHandler(this.tbbOrganize_Click); // @@ -245,10 +251,43 @@ this.tbbImport.Image = ((System.Drawing.Image)(resources.GetObject("tbbImport.Image"))); this.tbbImport.ImageTransparentColor = System.Drawing.Color.Magenta; this.tbbImport.Name = "tbbImport"; - this.tbbImport.Size = new System.Drawing.Size(43, 22); + this.tbbImport.Size = new System.Drawing.Size(47, 22); this.tbbImport.Text = "Import"; this.tbbImport.Click += new System.EventHandler(this.tbbImport_Click); // + // tbbClose + // + this.tbbClose.Alignment = System.Windows.Forms.ToolStripItemAlignment.Right; + this.tbbClose.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; + this.tbbClose.Image = ((System.Drawing.Image)(resources.GetObject("tbbClose.Image"))); + this.tbbClose.ImageTransparentColor = System.Drawing.Color.Magenta; + this.tbbClose.Margin = new System.Windows.Forms.Padding(0, 1, 2, 2); + this.tbbClose.Name = "tbbClose"; + this.tbbClose.Size = new System.Drawing.Size(40, 22); + this.tbbClose.Text = "Close"; + this.tbbClose.Click += new System.EventHandler(this.tbbClose_Click); + // + // toolStripSeparator1 + // + this.toolStripSeparator1.Alignment = System.Windows.Forms.ToolStripItemAlignment.Right; + this.toolStripSeparator1.Name = "toolStripSeparator1"; + this.toolStripSeparator1.Size = new System.Drawing.Size(6, 25); + this.toolStripSeparator1.Visible = false; + // + // tbbCloseReload + // + this.tbbCloseReload.Alignment = System.Windows.Forms.ToolStripItemAlignment.Right; + this.tbbCloseReload.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; + this.tbbCloseReload.Enabled = false; + this.tbbCloseReload.Image = ((System.Drawing.Image)(resources.GetObject("tbbCloseReload.Image"))); + this.tbbCloseReload.ImageTransparentColor = System.Drawing.Color.Magenta; + this.tbbCloseReload.Name = "tbbCloseReload"; + this.tbbCloseReload.Size = new System.Drawing.Size(119, 22); + this.tbbCloseReload.Text = "Close and load ROM"; + this.tbbCloseReload.ToolTipText = "Close and reload ROM"; + this.tbbCloseReload.Visible = false; + this.tbbCloseReload.Click += new System.EventHandler(this.tbbCloseReload_Click); + // // tableLayoutPanel1 // this.tableLayoutPanel1.ColumnCount = 1; @@ -351,5 +390,8 @@ private System.Windows.Forms.Label label1; private System.Windows.Forms.ToolStripButton tbbImport; private System.Windows.Forms.ColumnHeader columnHeader8; + private System.Windows.Forms.ToolStripButton tbbClose; + private System.Windows.Forms.ToolStripButton tbbCloseReload; + private System.Windows.Forms.ToolStripSeparator toolStripSeparator1; } } \ No newline at end of file diff --git a/BizHawk.Client.EmuHawk/config/FirmwaresConfig.cs b/BizHawk.Client.EmuHawk/config/FirmwaresConfig.cs index 8762d580df..39d976e832 100644 --- a/BizHawk.Client.EmuHawk/config/FirmwaresConfig.cs +++ b/BizHawk.Client.EmuHawk/config/FirmwaresConfig.cs @@ -57,6 +57,8 @@ namespace BizHawk.Client.EmuHawk private const int idMissing = 1; private const int idOk = 2; + RomLoader.RomErrorArgs RomErrorArgs; + Font fixedFont, boldFont, boldFixedFont; class ListViewSorter : IComparer @@ -80,7 +82,7 @@ namespace BizHawk.Client.EmuHawk string currSelectorDir; ListViewSorter listviewSorter; - public FirmwaresConfig() + public FirmwaresConfig(bool retryLoadRom = false) { InitializeComponent(); @@ -88,6 +90,13 @@ namespace BizHawk.Client.EmuHawk imageList1.Images.AddRange(new[] { Properties.Resources.RetroQuestion, Properties.Resources.ExclamationRed, Properties.Resources.GreenCheck }); listviewSorter = new ListViewSorter(this, -1); + + if (retryLoadRom) + { + toolStripSeparator1.Visible = true; + tbbCloseReload.Visible = true; + tbbCloseReload.Enabled = true; + } } //makes sure that the specified SystemId is selected in the list (and that all the firmwares for it are visible) @@ -158,6 +167,19 @@ namespace BizHawk.Client.EmuHawk RefreshBasePath(); } + + private void tbbClose_Click(object sender, EventArgs e) + { + this.Close(); + DialogResult = DialogResult.Cancel; + } + + private void tbbCloseReload_Click(object sender, EventArgs e) + { + this.Close(); + DialogResult = DialogResult.Retry; + } + private void FirmwaresConfig_FormClosed(object sender, FormClosedEventArgs e) { fixedFont.Dispose(); @@ -544,8 +566,5 @@ namespace BizHawk.Client.EmuHawk RunImportJob(files); } } - - - } //class FirmwaresConfig } diff --git a/BizHawk.Client.EmuHawk/config/FirmwaresConfig.resx b/BizHawk.Client.EmuHawk/config/FirmwaresConfig.resx index 8387a6568d..7345957162 100644 --- a/BizHawk.Client.EmuHawk/config/FirmwaresConfig.resx +++ b/BizHawk.Client.EmuHawk/config/FirmwaresConfig.resx @@ -185,6 +185,36 @@ mDEo5mNjuweFGvjWg2EBhCbpkW78htSHHwRyNdmgAFzPEee2iFkzayy2OLXzT4gr6UdUnlXrullsxxQ+ kx0g8BTA3aZlButjSTyjODq/WcQcW/B/Je4OQhLvKQDnzN1mp0nnkvAhR8VuMzNrpm1mpjgkoVwB/v8D TgDQASA1MVpwzwAAAABJRU5ErkJggg== + + + + + iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 + YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAIDSURBVDhPpZLrS5NhGMb3j4SWh0oRQVExD4gonkDpg4hG + YKxG6WBogkMZKgPNCEVJFBGdGETEvgwyO9DJE5syZw3PIlPEE9pgBCLZ5XvdM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