Skip to content

don't crash on non-existent profiles path #71

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions Hotsapi.Uploader.Common/Monitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand All @@ -57,7 +61,11 @@ public void Stop()
/// </summary>
public IEnumerable<string> ScanReplays()
{
return Directory.GetFiles(ProfilePath, "*.StormReplay", SearchOption.AllDirectories);
if (Directory.Exists(ProfilePath)) {
return Directory.GetFiles(ProfilePath, "*.StormReplay", SearchOption.AllDirectories);
} else {
return Enumerable.Empty<string>();
}
}
}
}