From 84f0d57fd54f48a2c25ba2779b9cbbbb9d7523c2 Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Sun, 29 Nov 2020 18:55:47 +1000 Subject: [PATCH] Add restarting to ExternalToolManager, called when replacing Config --- src/BizHawk.Client.EmuHawk/MainForm.cs | 1 + .../tools/ExternalToolManager.cs | 27 ++++++++++--------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/BizHawk.Client.EmuHawk/MainForm.cs b/src/BizHawk.Client.EmuHawk/MainForm.cs index 45614e4485..8d46d2ddb1 100644 --- a/src/BizHawk.Client.EmuHawk/MainForm.cs +++ b/src/BizHawk.Client.EmuHawk/MainForm.cs @@ -2793,6 +2793,7 @@ namespace BizHawk.Client.EmuHawk InitControls(); // rebind hotkeys InputManager.SyncControls(Emulator, MovieSession, Config); Tools.Restart(Config, Emulator, Game); + ExtToolManager.Restart(); AddOnScreenMessage($"Config file loaded: {iniPath}"); } diff --git a/src/BizHawk.Client.EmuHawk/tools/ExternalToolManager.cs b/src/BizHawk.Client.EmuHawk/tools/ExternalToolManager.cs index f2ca8feb7d..f67513a26c 100644 --- a/src/BizHawk.Client.EmuHawk/tools/ExternalToolManager.cs +++ b/src/BizHawk.Client.EmuHawk/tools/ExternalToolManager.cs @@ -13,26 +13,29 @@ namespace BizHawk.Client.EmuHawk { public sealed class ExternalToolManager { - private readonly FileSystemWatcher DirectoryMonitor; + private FileSystemWatcher DirectoryMonitor; private readonly List MenuItems = new List(); - public ExternalToolManager() - { - if(!Directory.Exists(GlobalWin.Config.PathEntries["Global", "External Tools"].Path)) - { - Directory.CreateDirectory(GlobalWin.Config.PathEntries["Global", "External Tools"].Path); - } + public ExternalToolManager() => Restart(); - DirectoryMonitor = new FileSystemWatcher(GlobalWin.Config.PathEntries["Global", "External Tools"].Path, "*.dll") + public void Restart() + { + if (DirectoryMonitor != null) { - IncludeSubdirectories = false - , NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName - , Filter = "*.dll" + DirectoryMonitor.Created -= DirectoryMonitor_Created; + DirectoryMonitor.Dispose(); + } + var extToolsDir = GlobalWin.Config.PathEntries["Global", "External Tools"].Path; + if (!Directory.Exists(extToolsDir)) Directory.CreateDirectory(extToolsDir); + DirectoryMonitor = new FileSystemWatcher(extToolsDir, "*.dll") + { + IncludeSubdirectories = false, + NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName, + Filter = "*.dll" }; DirectoryMonitor.Created += DirectoryMonitor_Created; DirectoryMonitor.EnableRaisingEvents = true; - BuildToolStrip(); }