diff --git a/BizHawk.Client.Common/CoreFileProvider.cs b/BizHawk.Client.Common/CoreFileProvider.cs index a68a8a91f8..c5230b2bc6 100644 --- a/BizHawk.Client.Common/CoreFileProvider.cs +++ b/BizHawk.Client.Common/CoreFileProvider.cs @@ -62,7 +62,7 @@ namespace BizHawk.Client.Common /// not found and is true public string GetFirmwarePath(string sysId, string firmwareId, bool required, string msg = null) { - var path = FirmwareManager.Request(sysId, firmwareId); + var path = FirmwareManager.Request(Global.Config.PathEntries.FirmwaresPathFragment, sysId, firmwareId); if (path != null && !File.Exists(path)) { path = null; diff --git a/BizHawk.Client.Common/FirmwareManager.cs b/BizHawk.Client.Common/FirmwareManager.cs index ff54f17813..6f504868a5 100644 --- a/BizHawk.Client.Common/FirmwareManager.cs +++ b/BizHawk.Client.Common/FirmwareManager.cs @@ -41,7 +41,7 @@ namespace BizHawk.Client.Common public string FirmwareId { get; set; } } - public ResolutionInfo Resolve(FirmwareDatabase.FirmwareRecord record, bool forbidScan = false) + public ResolutionInfo Resolve(string firmwaresPath, FirmwareDatabase.FirmwareRecord record, bool forbidScan = false) { // purpose of forbidScan: sometimes this is called from a loop in Scan(). we don't want to repeatedly DoScanAndResolve in that case, its already been done. bool first = true; @@ -55,7 +55,7 @@ namespace BizHawk.Client.Common { if (!forbidScan) { - DoScanAndResolve(); + DoScanAndResolve(firmwaresPath); } first = false; @@ -66,9 +66,9 @@ namespace BizHawk.Client.Common } // Requests the specified firmware. tries really hard to scan and resolve as necessary - public string Request(string sysId, string firmwareId) + public string Request(string firmwaresPath, string sysId, string firmwareId) { - var resolved = Resolve(FirmwareDatabase.LookupFirmwareRecord(sysId, firmwareId)); + var resolved = Resolve(firmwaresPath, FirmwareDatabase.LookupFirmwareRecord(sysId, firmwareId)); if (resolved == null) { return null; @@ -138,7 +138,7 @@ namespace BizHawk.Client.Common return false; } - public void DoScanAndResolve() + public void DoScanAndResolve(string firmwaresPath) { // build a list of file sizes. Only those will be checked during scanning var sizes = new HashSet(); @@ -150,7 +150,7 @@ namespace BizHawk.Client.Common using var reader = new RealFirmwareReader(); // build a list of files under the global firmwares path, and build a hash for each of them while we're at it var todo = new Queue(); - todo.Enqueue(new DirectoryInfo(PathManager.MakeAbsolutePath(Global.Config.PathEntries.FirmwaresPathFragment, null))); + todo.Enqueue(new DirectoryInfo(PathManager.MakeAbsolutePath(firmwaresPath, null))); while (todo.Count != 0) { diff --git a/BizHawk.Client.EmuHawk/config/FirmwaresConfig.cs b/BizHawk.Client.EmuHawk/config/FirmwaresConfig.cs index 696cf02b2c..425f8fcf36 100644 --- a/BizHawk.Client.EmuHawk/config/FirmwaresConfig.cs +++ b/BizHawk.Client.EmuHawk/config/FirmwaresConfig.cs @@ -91,6 +91,8 @@ namespace BizHawk.Client.EmuHawk private string _currSelectorDir; private readonly ListViewSorter _listViewSorter; + private string FirmwaresPath => Global.Config.PathEntries.FirmwaresPathFragment; + public FirmwaresConfig(MainForm mainForm, bool retryLoadRom = false, string reloadRomPath = null) { _mainForm = mainForm; @@ -245,13 +247,13 @@ namespace BizHawk.Client.EmuHawk private void DoScan() { lvFirmwares.BeginUpdate(); - Manager.DoScanAndResolve(); + Manager.DoScanAndResolve(FirmwaresPath); // for each type of firmware, try resolving and record the result foreach (ListViewItem lvi in lvFirmwares.Items) { var fr = lvi.Tag as FirmwareDatabase.FirmwareRecord; - var ri = Manager.Resolve(fr, true); + var ri = Manager.Resolve(FirmwaresPath, fr, true); for(int i=4;i<=7;i++) lvi.SubItems[i].Text = ""; @@ -315,8 +317,9 @@ namespace BizHawk.Client.EmuHawk lvi.SubItems[6].Text = ri.Size.ToString(); - if (ri.Hash != null) lvi.SubItems[7].Text = $"sha1:{ri.Hash}"; - else lvi.SubItems[7].Text = ""; + lvi.SubItems[7].Text = ri.Hash != null + ? $"sha1:{ri.Hash}" + : ""; } } @@ -330,11 +333,11 @@ namespace BizHawk.Client.EmuHawk return; } - Manager.DoScanAndResolve(); + Manager.DoScanAndResolve(FirmwaresPath); foreach (var fr in FirmwareDatabase.FirmwareRecords) { - var ri = Manager.Resolve(fr); + var ri = Manager.Resolve(FirmwaresPath, fr); if (ri?.KnownFirmwareFile == null) continue; if (ri.UserSpecified) continue; @@ -650,7 +653,7 @@ namespace BizHawk.Client.EmuHawk { // blech. the worst extraction code in the universe. string extractPath = $"{Path.GetTempFileName()}.dir"; - DirectoryInfo di = Directory.CreateDirectory(extractPath); + var di = Directory.CreateDirectory(extractPath); try {