2020-08-13 02:46:11 +08:00
|
|
|
|
// Copyright (c) Microsoft Corporation
|
|
|
|
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
|
|
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
|
|
|
|
|
|
using System;
|
2020-07-18 13:32:21 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using Wox.Infrastructure.Storage;
|
|
|
|
|
|
|
|
|
|
namespace Microsoft.Plugin.Program.Storage
|
|
|
|
|
{
|
|
|
|
|
internal class Win32ProgramFileSystemWatchers : IDisposable
|
|
|
|
|
{
|
2020-08-15 03:46:23 +08:00
|
|
|
|
public string[] PathsToWatch { get; set; }
|
|
|
|
|
|
|
|
|
|
public List<FileSystemWatcherWrapper> FileSystemWatchers { get; set; }
|
|
|
|
|
|
2020-08-22 03:40:31 +08:00
|
|
|
|
private bool _disposed;
|
2020-07-18 13:32:21 +08:00
|
|
|
|
|
|
|
|
|
// This class contains the list of directories to watch and initializes the File System Watchers
|
|
|
|
|
public Win32ProgramFileSystemWatchers()
|
|
|
|
|
{
|
2020-08-15 03:46:23 +08:00
|
|
|
|
PathsToWatch = GetPathsToWatch();
|
2020-07-18 13:32:21 +08:00
|
|
|
|
SetFileSystemWatchers();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Returns an array of paths to be watched
|
2020-08-12 00:08:44 +08:00
|
|
|
|
private static string[] GetPathsToWatch()
|
2020-07-18 13:32:21 +08:00
|
|
|
|
{
|
|
|
|
|
string[] paths = new string[]
|
|
|
|
|
{
|
2020-10-08 03:27:56 +08:00
|
|
|
|
Environment.GetFolderPath(Environment.SpecialFolder.StartMenu),
|
|
|
|
|
Environment.GetFolderPath(Environment.SpecialFolder.CommonStartMenu),
|
2020-08-13 02:46:11 +08:00
|
|
|
|
Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
|
2020-10-08 03:27:56 +08:00
|
|
|
|
Environment.GetFolderPath(Environment.SpecialFolder.CommonDesktopDirectory),
|
2020-07-18 13:32:21 +08:00
|
|
|
|
};
|
|
|
|
|
return paths;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Initializes the FileSystemWatchers
|
|
|
|
|
private void SetFileSystemWatchers()
|
|
|
|
|
{
|
2020-08-15 03:46:23 +08:00
|
|
|
|
FileSystemWatchers = new List<FileSystemWatcherWrapper>();
|
|
|
|
|
for (int index = 0; index < PathsToWatch.Length; index++)
|
2020-07-18 13:32:21 +08:00
|
|
|
|
{
|
2020-08-15 03:46:23 +08:00
|
|
|
|
FileSystemWatchers.Add(new FileSystemWatcherWrapper());
|
2020-07-18 13:32:21 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
Dispose(disposing: true);
|
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected virtual void Dispose(bool disposing)
|
|
|
|
|
{
|
|
|
|
|
if (!_disposed)
|
|
|
|
|
{
|
|
|
|
|
if (disposing)
|
|
|
|
|
{
|
2020-08-15 03:46:23 +08:00
|
|
|
|
for (int index = 0; index < PathsToWatch.Length; index++)
|
2020-07-18 13:32:21 +08:00
|
|
|
|
{
|
2020-08-15 03:46:23 +08:00
|
|
|
|
FileSystemWatchers[index].Dispose();
|
2020-07-18 13:32:21 +08:00
|
|
|
|
}
|
2020-08-14 06:31:14 +08:00
|
|
|
|
|
2020-07-18 13:32:21 +08:00
|
|
|
|
_disposed = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|