Allow ToolManager.IsAvailable to check ext. tools

This commit is contained in:
YoshiRulz 2021-09-06 15:51:11 +10:00
parent 55a8936a30
commit 56a9e333e9
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
3 changed files with 11 additions and 10 deletions

View File

@ -393,8 +393,8 @@ namespace BizHawk.Client.EmuHawk
Controls.Add(_presentationPanel); Controls.Add(_presentationPanel);
Controls.SetChildIndex(_presentationPanel, 0); Controls.SetChildIndex(_presentationPanel, 0);
Tools = new ToolManager(this, Config, DisplayManager, InputManager, Emulator, MovieSession, Game);
ExtToolManager = new ExternalToolManager(Config.PathEntries, () => (EmuClientApi.SystemIdConverter.Convert(Emulator.SystemId), Game.Hash)); ExtToolManager = new ExternalToolManager(Config.PathEntries, () => (EmuClientApi.SystemIdConverter.Convert(Emulator.SystemId), Game.Hash));
Tools = new ToolManager(this, Config, DisplayManager, ExtToolManager, InputManager, Emulator, MovieSession, Game);
// TODO GL - move these event handlers somewhere less obnoxious line in the On* overrides // TODO GL - move these event handlers somewhere less obnoxious line in the On* overrides
Load += (o, e) => Load += (o, e) =>

View File

@ -21,6 +21,8 @@ namespace BizHawk.Client.EmuHawk
private readonly List<ToolStripMenuItem> MenuItems = new List<ToolStripMenuItem>(); private readonly List<ToolStripMenuItem> MenuItems = new List<ToolStripMenuItem>();
internal readonly IList<string> PossibleExtToolTypeNames = new List<string>();
public ExternalToolManager(PathEntryCollection paths, Func<(CoreSystem System, string Hash)> getLoadedRomInfoCallback) public ExternalToolManager(PathEntryCollection paths, Func<(CoreSystem System, string Hash)> getLoadedRomInfoCallback)
{ {
_getLoadedRomInfoCallback = getLoadedRomInfoCallback; _getLoadedRomInfoCallback = getLoadedRomInfoCallback;
@ -53,6 +55,7 @@ namespace BizHawk.Client.EmuHawk
internal void BuildToolStrip() internal void BuildToolStrip()
{ {
MenuItems.Clear(); MenuItems.Clear();
PossibleExtToolTypeNames.Clear();
if (DirectoryMonitor == null) return; if (DirectoryMonitor == null) return;
DirectoryInfo di = new(DirectoryMonitor.Path); DirectoryInfo di = new(DirectoryMonitor.Path);
if (!di.Exists) return; if (!di.Exists) return;
@ -93,6 +96,7 @@ namespace BizHawk.Client.EmuHawk
} }
item.Text = toolAttribute.Name; item.Text = toolAttribute.Name;
item.Tag = (externalToolFile.Location, entryPoint.FullName); // Tag set => no errors (show custom icon even when disabled) item.Tag = (externalToolFile.Location, entryPoint.FullName); // Tag set => no errors (show custom icon even when disabled)
PossibleExtToolTypeNames.Add(entryPoint.AssemblyQualifiedName);
if (applicabilityAttrs.Count == 1) if (applicabilityAttrs.Count == 1)
{ {
var (system, loadedRomHash) = _getLoadedRomInfoCallback(); var (system, loadedRomHash) = _getLoadedRomInfoCallback();

View File

@ -21,6 +21,7 @@ namespace BizHawk.Client.EmuHawk
private readonly MainForm _owner; private readonly MainForm _owner;
private Config _config; private Config _config;
private readonly DisplayManager _displayManager; private readonly DisplayManager _displayManager;
private readonly ExternalToolManager _extToolManager;
private readonly InputManager _inputManager; private readonly InputManager _inputManager;
private IExternalApiProvider _apiProvider; private IExternalApiProvider _apiProvider;
private IEmulator _emulator; private IEmulator _emulator;
@ -45,6 +46,7 @@ namespace BizHawk.Client.EmuHawk
MainForm owner, MainForm owner,
Config config, Config config,
DisplayManager displayManager, DisplayManager displayManager,
ExternalToolManager extToolManager,
InputManager inputManager, InputManager inputManager,
IEmulator emulator, IEmulator emulator,
IMovieSession movieSession, IMovieSession movieSession,
@ -53,6 +55,7 @@ namespace BizHawk.Client.EmuHawk
_owner = owner; _owner = owner;
_config = config; _config = config;
_displayManager = displayManager; _displayManager = displayManager;
_extToolManager = extToolManager;
_inputManager = inputManager; _inputManager = inputManager;
_emulator = emulator; _emulator = emulator;
_movieSession = movieSession; _movieSession = movieSession;
@ -731,18 +734,12 @@ namespace BizHawk.Client.EmuHawk
} }
} }
private static readonly Lazy<List<string>> LazyAsmTypes = new Lazy<List<string>>(() => private static readonly IList<string> PossibleToolTypeNames = EmuHawk.ReflectionCache.Types.Select(t => t.AssemblyQualifiedName).ToList();
EmuHawk.ReflectionCache.Types // Confining the search to only EmuHawk, for now at least, we may want to broaden for external tools one day
.Select(t => t.AssemblyQualifiedName)
.ToList());
public bool IsAvailable(Type tool) public bool IsAvailable(Type tool)
{ {
if (!ServiceInjector.IsAvailable(_emulator.ServiceProvider, tool) if (!ServiceInjector.IsAvailable(_emulator.ServiceProvider, tool)) return false;
|| !LazyAsmTypes.Value.Contains(tool.AssemblyQualifiedName)) // not a tool if (!PossibleToolTypeNames.Contains(tool.AssemblyQualifiedName) && !_extToolManager.PossibleExtToolTypeNames.Contains(tool.AssemblyQualifiedName)) return false; // not a tool
{
return false;
}
ToolAttribute attr = tool.GetCustomAttributes(false).OfType<ToolAttribute>().SingleOrDefault(); ToolAttribute attr = tool.GetCustomAttributes(false).OfType<ToolAttribute>().SingleOrDefault();
if (attr == null) if (attr == null)