[PT Run] [Program] Fix FileSystemWatcher Crash (#14649)

This commit is contained in:
Davide Giacometti
2021-11-30 15:41:09 +01:00
committed by GitHub
parent 974bf4708c
commit ec11abbc52

View File

@@ -1,10 +1,13 @@
// Copyright (c) Microsoft Corporation // Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license. // The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq;
using Wox.Infrastructure.Storage; using Wox.Infrastructure.Storage;
using Wox.Plugin.Logger;
namespace Microsoft.Plugin.Program.Storage namespace Microsoft.Plugin.Program.Storage
{ {
@@ -33,7 +36,18 @@ namespace Microsoft.Plugin.Program.Storage
Environment.GetFolderPath(Environment.SpecialFolder.Desktop), Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
Environment.GetFolderPath(Environment.SpecialFolder.CommonDesktopDirectory), Environment.GetFolderPath(Environment.SpecialFolder.CommonDesktopDirectory),
}; };
return paths;
var invalidPaths = new List<string>();
foreach (var path in paths)
{
if (!Directory.Exists(path))
{
Log.Warn($"Directory {path} does not exist and will be ignored", typeof(Win32ProgramFileSystemWatchers));
invalidPaths.Add(path);
}
}
return paths.Except(invalidPaths).ToArray();
} }
// Initializes the FileSystemWatchers // Initializes the FileSystemWatchers