Program plugin fully on stylecop (#5964)

This commit is contained in:
Clint Rutkas
2020-08-14 12:46:23 -07:00
committed by GitHub
parent be5d58c849
commit e0a1b478a1
31 changed files with 361 additions and 279 deletions

View File

@@ -10,14 +10,16 @@ namespace Microsoft.Plugin.Program.Storage
{
internal class Win32ProgramFileSystemWatchers : IDisposable
{
public readonly string[] _pathsToWatch;
public List<FileSystemWatcherWrapper> _fileSystemWatchers;
public string[] PathsToWatch { get; set; }
public List<FileSystemWatcherWrapper> FileSystemWatchers { get; set; }
private bool _disposed = false;
// This class contains the list of directories to watch and initializes the File System Watchers
public Win32ProgramFileSystemWatchers()
{
_pathsToWatch = GetPathsToWatch();
PathsToWatch = GetPathsToWatch();
SetFileSystemWatchers();
}
@@ -36,10 +38,10 @@ namespace Microsoft.Plugin.Program.Storage
// Initializes the FileSystemWatchers
private void SetFileSystemWatchers()
{
_fileSystemWatchers = new List<FileSystemWatcherWrapper>();
for (int index = 0; index < _pathsToWatch.Length; index++)
FileSystemWatchers = new List<FileSystemWatcherWrapper>();
for (int index = 0; index < PathsToWatch.Length; index++)
{
_fileSystemWatchers.Add(new FileSystemWatcherWrapper());
FileSystemWatchers.Add(new FileSystemWatcherWrapper());
}
}
@@ -55,9 +57,9 @@ namespace Microsoft.Plugin.Program.Storage
{
if (disposing)
{
for (int index = 0; index < _pathsToWatch.Length; index++)
for (int index = 0; index < PathsToWatch.Length; index++)
{
_fileSystemWatchers[index].Dispose();
FileSystemWatchers[index].Dispose();
}
_disposed = true;

View File

@@ -15,22 +15,23 @@ namespace Microsoft.Plugin.Program.Storage
{
internal class Win32ProgramRepository : ListRepository<Programs.Win32Program>, IProgramRepository
{
private const string LnkExtension = ".lnk";
private const string UrlExtension = ".url";
private IStorage<IList<Programs.Win32Program>> _storage;
private ProgramPluginSettings _settings;
private IList<IFileSystemWatcherWrapper> _fileSystemWatcherHelpers;
private string[] _pathsToWatch;
private int _numberOfPathsToWatch;
private Collection<string> extensionsToWatch = new Collection<string> { "*.exe", "*.lnk", "*.appref-ms", "*.url" };
private readonly string lnkExtension = ".lnk";
private readonly string urlExtension = ".url";
private Collection<string> extensionsToWatch = new Collection<string> { "*.exe", $"*{LnkExtension}", "*.appref-ms", $"*{UrlExtension}" };
public Win32ProgramRepository(IList<IFileSystemWatcherWrapper> fileSystemWatcherHelpers, IStorage<IList<Win32Program>> storage, ProgramPluginSettings settings, string[] pathsToWatch)
{
this._fileSystemWatcherHelpers = fileSystemWatcherHelpers;
this._storage = storage ?? throw new ArgumentNullException(nameof(storage), "Win32ProgramRepository requires an initialized storage interface");
this._settings = settings ?? throw new ArgumentNullException(nameof(settings), "Win32ProgramRepository requires an initialized settings object");
this._pathsToWatch = pathsToWatch;
this._numberOfPathsToWatch = pathsToWatch.Length;
_fileSystemWatcherHelpers = fileSystemWatcherHelpers;
_storage = storage ?? throw new ArgumentNullException(nameof(storage), "Win32ProgramRepository requires an initialized storage interface");
_settings = settings ?? throw new ArgumentNullException(nameof(settings), "Win32ProgramRepository requires an initialized settings object");
_pathsToWatch = pathsToWatch;
_numberOfPathsToWatch = pathsToWatch.Length;
InitializeFileSystemWatchers();
}
@@ -77,11 +78,11 @@ namespace Microsoft.Plugin.Program.Storage
// This situation is not encountered for other application types because the fullPath is the path itself, instead of being computed by using the path to the app.
try
{
if (extension.Equals(lnkExtension, StringComparison.OrdinalIgnoreCase))
if (extension.Equals(LnkExtension, StringComparison.OrdinalIgnoreCase))
{
oldApp = new Win32Program() { Name = Path.GetFileNameWithoutExtension(e.OldName), ExecutableName = newApp.ExecutableName, FullPath = newApp.FullPath };
}
else if (extension.Equals(urlExtension, StringComparison.OrdinalIgnoreCase))
else if (extension.Equals(UrlExtension, StringComparison.OrdinalIgnoreCase))
{
oldApp = new Win32Program() { Name = Path.GetFileNameWithoutExtension(e.OldName), ExecutableName = Path.GetFileName(e.OldName), FullPath = newApp.FullPath };
}
@@ -117,11 +118,11 @@ namespace Microsoft.Plugin.Program.Storage
try
{
// To mitigate the issue of not having a FullPath for a shortcut app, we iterate through the items and find the app with the same hashcode.
if (extension.Equals(lnkExtension, StringComparison.OrdinalIgnoreCase))
if (extension.Equals(LnkExtension, StringComparison.OrdinalIgnoreCase))
{
app = GetAppWithSameLnkResolvedPath(path);
}
else if (extension.Equals(urlExtension, StringComparison.OrdinalIgnoreCase))
else if (extension.Equals(UrlExtension, StringComparison.OrdinalIgnoreCase))
{
app = GetAppWithSameNameAndExecutable(Path.GetFileNameWithoutExtension(path), Path.GetFileName(path));
}
@@ -173,7 +174,7 @@ namespace Microsoft.Plugin.Program.Storage
private void OnAppCreated(object sender, FileSystemEventArgs e)
{
string path = e.FullPath;
if (!Path.GetExtension(path).Equals(urlExtension, StringComparison.CurrentCultureIgnoreCase))
if (!Path.GetExtension(path).Equals(UrlExtension, StringComparison.CurrentCultureIgnoreCase))
{
Programs.Win32Program app = Programs.Win32Program.GetAppFromPath(path);
if (app != null)
@@ -186,7 +187,7 @@ namespace Microsoft.Plugin.Program.Storage
private void OnAppChanged(object sender, FileSystemEventArgs e)
{
string path = e.FullPath;
if (Path.GetExtension(path).Equals(urlExtension, StringComparison.CurrentCultureIgnoreCase))
if (Path.GetExtension(path).Equals(UrlExtension, StringComparison.CurrentCultureIgnoreCase))
{
Programs.Win32Program app = Programs.Win32Program.GetAppFromPath(path);
if (app != null)