Use `FirstOrNull` helper for `--open-ext-tool-dll` impl.

fixes e128cb82f, 23c092810
This commit is contained in:
YoshiRulz 2022-05-10 00:27:31 +10:00
parent 6e46cb550b
commit 6beaa79b2c
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
1 changed files with 6 additions and 19 deletions

View File

@ -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