From 1b3126d48e34ec27b537f29cd3ffbe7458dd5a87 Mon Sep 17 00:00:00 2001 From: Martijn Hoekstra Date: Fri, 7 Feb 2020 16:15:56 +0100 Subject: [PATCH] don't crash on non-existant profiles path --- Hotsapi.Uploader.Common/Monitor.cs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/Hotsapi.Uploader.Common/Monitor.cs b/Hotsapi.Uploader.Common/Monitor.cs index 90e4527..f1de928 100644 --- a/Hotsapi.Uploader.Common/Monitor.cs +++ b/Hotsapi.Uploader.Common/Monitor.cs @@ -30,14 +30,18 @@ protected virtual void OnReplayAdded(string path) public void Start() { if (_watcher == null) { - _watcher = new FileSystemWatcher() { - Path = ProfilePath, - Filter = "*.StormReplay", - IncludeSubdirectories = true - }; - _watcher.Created += (o, e) => OnReplayAdded(e.FullPath); + if (Directory.Exists(ProfilePath)) { + _watcher = new FileSystemWatcher() { + Path = ProfilePath, + Filter = "*.StormReplay", + IncludeSubdirectories = true + }; + _watcher.Created += (o, e) => OnReplayAdded(e.FullPath); + } + } + if (_watcher != null) { + _watcher.EnableRaisingEvents = true; } - _watcher.EnableRaisingEvents = true; _log.Debug($"Started watching for new replays"); } @@ -57,7 +61,11 @@ public void Stop() /// public IEnumerable ScanReplays() { - return Directory.GetFiles(ProfilePath, "*.StormReplay", SearchOption.AllDirectories); + if (Directory.Exists(ProfilePath)) { + return Directory.GetFiles(ProfilePath, "*.StormReplay", SearchOption.AllDirectories); + } else { + return Enumerable.Empty(); + } } } }