From 6beaa79b2cd1186939d481391cf4f96af1c1dbeb Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Tue, 10 May 2022 00:27:31 +1000 Subject: [PATCH] Use `FirstOrNull` helper for `--open-ext-tool-dll` impl. fixes e128cb82f, 23c092810 --- src/BizHawk.Client.EmuHawk/MainForm.cs | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/src/BizHawk.Client.EmuHawk/MainForm.cs b/src/BizHawk.Client.EmuHawk/MainForm.cs index 4315021607..614eede306 100644 --- a/src/BizHawk.Client.EmuHawk/MainForm.cs +++ b/src/BizHawk.Client.EmuHawk/MainForm.cs @@ -40,6 +40,7 @@ using BizHawk.Emulation.Cores.Sony.PSX; using BizHawk.Client.EmuHawk.ToolExtensions; using BizHawk.Client.EmuHawk.CoreExtensions; using BizHawk.Client.EmuHawk.CustomControls; +using BizHawk.Common.CollectionExtensions; namespace BizHawk.Client.EmuHawk { @@ -129,27 +130,13 @@ namespace BizHawk.Client.EmuHawk var requestedExtToolDll = _argParser.openExtToolDll; if (requestedExtToolDll != null) { - IExternalToolForm loaded = null; - - var enabled = ExtToolManager.ToolStripMenu.Where(item => item.Enabled) - .Select(item => ((string, string)) item.Tag) - .ToList(); - try - { - int foundIndex = enabled.FindIndex(tuple => - tuple.Item1 == requestedExtToolDll + var found = ExtToolManager.ToolStripMenu.Where(static item => item.Enabled) + .Select(static item => ((string, string)) item.Tag) + .FirstOrNull(tuple => tuple.Item1 == requestedExtToolDll || Path.GetFileName(tuple.Item1) == requestedExtToolDll || Path.GetFileNameWithoutExtension(tuple.Item1) == requestedExtToolDll); - - if(foundIndex != -1) - loaded = Tools.LoadExternalToolForm(enabled[foundIndex].Item1, enabled[foundIndex].Item2, skipExtToolWarning: true); - } - catch - { - } - - if(loaded == null) - Console.WriteLine($"requested ext. tool dll {requestedExtToolDll} could not be loaded"); + if (found is not null) Tools.LoadExternalToolForm(found.Value.Item1, found.Value.Item2, skipExtToolWarning: true); + else Console.WriteLine($"requested ext. tool dll {requestedExtToolDll} could not be loaded"); } #if DEBUG