From 995f670d3673e472810ca53dfc98b6d3149c4ab0 Mon Sep 17 00:00:00 2001 From: goyuken Date: Thu, 5 Feb 2015 23:25:28 +0000 Subject: [PATCH] frontend tracks loaded firmware: proof of concept --- BizHawk.Client.Common/CoreFileProvider.cs | 11 --------- BizHawk.Client.Common/FirmwareManager.cs | 23 +++++++++++++++++++ BizHawk.Client.EmuHawk/MainForm.cs | 13 +++++++++++ .../Interfaces/ICoreFileProvider.cs | 15 ++++-------- 4 files changed, 40 insertions(+), 22 deletions(-) diff --git a/BizHawk.Client.Common/CoreFileProvider.cs b/BizHawk.Client.Common/CoreFileProvider.cs index 127e5deefd..e11b4b8f6d 100644 --- a/BizHawk.Client.Common/CoreFileProvider.cs +++ b/BizHawk.Client.Common/CoreFileProvider.cs @@ -17,17 +17,6 @@ namespace BizHawk.Client.Common _showWarning = showWarning; } - public Stream OpenFirmware(string sysId, string key) - { - var fn = PathFirmware(sysId, key); - return new FileStream(fn, FileMode.Open, FileAccess.Read, FileShare.Read); - } - - public string PathFirmware(string sysId, string key) - { - return FirmwareManager.Request(sysId, key); - } - public string PathSubfile(string fname) { return Path.Combine(Path.GetDirectoryName(SubfileDirectory) ?? String.Empty, fname); diff --git a/BizHawk.Client.Common/FirmwareManager.cs b/BizHawk.Client.Common/FirmwareManager.cs index 548b0512fc..e250ee7727 100644 --- a/BizHawk.Client.Common/FirmwareManager.cs +++ b/BizHawk.Client.Common/FirmwareManager.cs @@ -30,6 +30,18 @@ namespace BizHawk.Client.Common private readonly Dictionary _resolutionDictionary = new Dictionary(); + public class FirmwareEventArgs + { + public string Hash { get; set; } + public long Size { get; set; } + public string SystemId { get; set; } + public string FirmwareId { get; set; } + } + + public delegate void FirmwareEventHandler(object sender, FirmwareEventArgs e); + + public event FirmwareEventHandler OnFirmwareRequestSatisfied; + public ResolutionInfo Resolve(string sysId, string firmwareId) { return Resolve(FirmwareDatabase.LookupFirmwareRecord(sysId, firmwareId)); @@ -63,6 +75,17 @@ namespace BizHawk.Client.Common { var resolved = Resolve(sysId, firmwareId); if (resolved == null) return null; + if (OnFirmwareRequestSatisfied != null) + { + OnFirmwareRequestSatisfied(this, + new FirmwareEventArgs + { + SystemId = sysId, + FirmwareId = firmwareId, + Hash = resolved.Hash, + Size = resolved.Size + }); + } return resolved.FilePath; } diff --git a/BizHawk.Client.EmuHawk/MainForm.cs b/BizHawk.Client.EmuHawk/MainForm.cs index dfec36eff5..f881d803bf 100644 --- a/BizHawk.Client.EmuHawk/MainForm.cs +++ b/BizHawk.Client.EmuHawk/MainForm.cs @@ -101,6 +101,7 @@ namespace BizHawk.Client.EmuHawk Global.ControllerInputCoalescer = new ControllerInputCoalescer(); Global.FirmwareManager = new FirmwareManager(); + Global.FirmwareManager.OnFirmwareRequestSatisfied += (o, e) => ActiveFirmwares[e.FirmwareId] = e.Hash; Global.MovieSession = new MovieSession { Movie = MovieService.DefaultInstance, @@ -565,6 +566,8 @@ namespace BizHawk.Client.EmuHawk public bool RestoreReadWriteOnStop = false; public bool UpdateFrame = false; + public Dictionary ActiveFirmwares = new Dictionary(); + private int? _pauseOnFrame; public int? PauseOnFrame // If set, upon completion of this frame, the client wil pause { @@ -3308,6 +3311,7 @@ namespace BizHawk.Client.EmuHawk Deterministic = deterministic, MessageCallback = GlobalWin.OSD.AddMessage }; + ActiveFirmwares.Clear(); loader.OnLoadError += ShowLoadError; loader.OnLoadSettings += CoreSettings; @@ -3421,6 +3425,15 @@ namespace BizHawk.Client.EmuHawk { LoadQuickSave("QuickSave" + Global.Config.SaveSlot); } + + if (ActiveFirmwares.Count > 0) + { + Console.WriteLine("Active Firmwares:"); + foreach (var kvp in ActiveFirmwares) + { + Console.WriteLine(" {0} : {1}", kvp.Key, kvp.Value); + } + } return true; } else diff --git a/BizHawk.Emulation.Common/Interfaces/ICoreFileProvider.cs b/BizHawk.Emulation.Common/Interfaces/ICoreFileProvider.cs index 167bc67183..b335f60d47 100644 --- a/BizHawk.Emulation.Common/Interfaces/ICoreFileProvider.cs +++ b/BizHawk.Emulation.Common/Interfaces/ICoreFileProvider.cs @@ -1,22 +1,14 @@ -using System.IO; +using System; +using System.IO; namespace BizHawk.Emulation.Common { public interface ICoreFileProvider { - /// - /// Opens a firmware according to the specified firmware ID key - /// - Stream OpenFirmware(string sysId, string key); - - /// - /// Returns the path to a firmware according to the specified firmware ID key. Use OpenFirmware instead - /// - string PathFirmware(string sysId, string key); - /// /// Produces a path to the requested file, expected to be parallel to the running rom. for example: cue+bin files or sfc+pcm (MSU-1 games) /// + [Obsolete] string PathSubfile(string fname); /// @@ -35,6 +27,7 @@ namespace BizHawk.Emulation.Common /// if true, result is guaranteed to be valid; else null is possible if not foun /// message to show if fail to get /// + [Obsolete] string GetFirmwarePath(string sysID, string firmwareID, bool required, string msg = null); ///