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(); + } } } }