From 93ca66a243b60750a34552956a9e78501ec639f0 Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Fri, 11 Jun 2021 02:09:16 +1000 Subject: [PATCH] Fail properly when ext. tools dir is missing (fixes #2787 for real) --- .../tools/ExternalToolManager.cs | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/src/BizHawk.Client.EmuHawk/tools/ExternalToolManager.cs b/src/BizHawk.Client.EmuHawk/tools/ExternalToolManager.cs index 7fb312816e..96ea0c6cc5 100644 --- a/src/BizHawk.Client.EmuHawk/tools/ExternalToolManager.cs +++ b/src/BizHawk.Client.EmuHawk/tools/ExternalToolManager.cs @@ -35,29 +35,28 @@ namespace BizHawk.Client.EmuHawk DirectoryMonitor.Created -= DirectoryMonitor_Created; DirectoryMonitor.Dispose(); } - DirectoryMonitor = new FileSystemWatcher(_paths["Global", "External Tools"].Path, "*.dll") + var path = _paths["Global", "External Tools"].Path; + if (Directory.Exists(path)) { - IncludeSubdirectories = false, - NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName, - Filter = "*.dll" - }; - DirectoryMonitor.Created += DirectoryMonitor_Created; - DirectoryMonitor.EnableRaisingEvents = true; + DirectoryMonitor = new FileSystemWatcher(path, "*.dll") + { + IncludeSubdirectories = false, + NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName, + Filter = "*.dll" + }; + DirectoryMonitor.Created += DirectoryMonitor_Created; + DirectoryMonitor.EnableRaisingEvents = true; + } BuildToolStrip(); } internal void BuildToolStrip() { MenuItems.Clear(); - if (Directory.Exists(DirectoryMonitor.Path)) - { - DirectoryInfo dInfo = new DirectoryInfo(DirectoryMonitor.Path); - - foreach (FileInfo fi in dInfo.GetFiles("*.dll")) - { - MenuItems.Add(GenerateToolTipFromFileName(fi.FullName)); - } - } + if (DirectoryMonitor == null) return; + DirectoryInfo di = new(DirectoryMonitor.Path); + if (!di.Exists) return; + foreach (var fi in di.GetFiles("*.dll")) MenuItems.Add(GenerateToolTipFromFileName(fi.FullName)); } /// Generates a from an assembly at containing an external tool.