more braces and whitespace style errors (#5951)

This commit is contained in:
Clint Rutkas
2020-08-14 09:22:12 -07:00
committed by GitHub
parent 9e8b0d2807
commit 913615f1c2
14 changed files with 80 additions and 68 deletions

View File

@@ -51,8 +51,7 @@ namespace Microsoft.Plugin.Program.Logger
/// Logs an exception /// Logs an exception
/// </summary> /// </summary>
[MethodImpl(MethodImplOptions.Synchronized)] [MethodImpl(MethodImplOptions.Synchronized)]
internal static void LogException(string classname, string callingMethodName, string loadingProgramPath, internal static void LogException(string classname, string callingMethodName, string loadingProgramPath, string interpretationMessage, Exception e)
string interpretationMessage, Exception e)
{ {
Debug.WriteLine($"ERROR{classname}|{callingMethodName}|{loadingProgramPath}|{interpretationMessage}"); Debug.WriteLine($"ERROR{classname}|{callingMethodName}|{loadingProgramPath}|{interpretationMessage}");
@@ -122,10 +121,14 @@ namespace Microsoft.Plugin.Program.Logger
private static bool IsKnownWinProgramError(Exception e, string callingMethodName) private static bool IsKnownWinProgramError(Exception e, string callingMethodName)
{ {
if (e.TargetSite?.Name == "GetDescription" && callingMethodName == "LnkProgram") if (e.TargetSite?.Name == "GetDescription" && callingMethodName == "LnkProgram")
{
return true; return true;
}
if (e is SecurityException || e is UnauthorizedAccessException || e is DirectoryNotFoundException) if (e is SecurityException || e is UnauthorizedAccessException || e is DirectoryNotFoundException)
{
return true; return true;
}
return false; return false;
} }
@@ -135,10 +138,14 @@ namespace Microsoft.Plugin.Program.Logger
if (((e.HResult == -2147024774 || e.HResult == -2147009769) && callingMethodName == "ResourceFromPri") if (((e.HResult == -2147024774 || e.HResult == -2147009769) && callingMethodName == "ResourceFromPri")
|| (e.HResult == -2147024894 && (callingMethodName == "LogoPathFromUri" || callingMethodName == "ImageFromPath")) || (e.HResult == -2147024894 && (callingMethodName == "LogoPathFromUri" || callingMethodName == "ImageFromPath"))
|| (e.HResult == -2147024864 && callingMethodName == "InitializeAppInfo")) || (e.HResult == -2147024864 && callingMethodName == "InitializeAppInfo"))
{
return true; return true;
}
if (callingMethodName == "XmlNamespaces") if (callingMethodName == "XmlNamespaces")
{
return true; return true;
}
return false; return false;
} }

View File

@@ -52,13 +52,17 @@ namespace Microsoft.Plugin.Program
var a = Task.Run(() => var a = Task.Run(() =>
{ {
if (IsStartupIndexProgramsRequired || !_win32ProgramRepository.Any()) if (IsStartupIndexProgramsRequired || !_win32ProgramRepository.Any())
{
Stopwatch.Normal("|Microsoft.Plugin.Program.Main|Win32Program index cost", _win32ProgramRepository.IndexPrograms); Stopwatch.Normal("|Microsoft.Plugin.Program.Main|Win32Program index cost", _win32ProgramRepository.IndexPrograms);
}
}); });
var b = Task.Run(() => var b = Task.Run(() =>
{ {
if (IsStartupIndexProgramsRequired || !_packageRepository.Any()) if (IsStartupIndexProgramsRequired || !_packageRepository.Any())
{
Stopwatch.Normal("|Microsoft.Plugin.Program.Main|Win32Program index cost", _packageRepository.IndexPrograms); Stopwatch.Normal("|Microsoft.Plugin.Program.Main|Win32Program index cost", _packageRepository.IndexPrograms);
}
}); });
Task.WaitAll(a, b); Task.WaitAll(a, b);
@@ -92,7 +96,7 @@ namespace Microsoft.Plugin.Program
public void Init(PluginInitContext context) public void Init(PluginInitContext context)
{ {
_context = context ?? throw new ArgumentNullException(nameof(context)); ; _context = context ?? throw new ArgumentNullException(nameof(context));
_context.API.ThemeChanged += OnThemeChanged; _context.API.ThemeChanged += OnThemeChanged;
UpdateUWPIconPath(_context.API.GetCurrentTheme()); UpdateUWPIconPath(_context.API.GetCurrentTheme());
} }

View File

@@ -52,5 +52,7 @@ namespace Microsoft.Plugin.Program
public string UniqueIdentifier { get; set; } public string UniqueIdentifier { get; set; }
} }
public class DisabledProgramSource : ProgramSource { } public class DisabledProgramSource : ProgramSource
{
}
} }

View File

@@ -36,7 +36,6 @@ namespace Microsoft.Plugin.Program.Programs.ApplicationActivationHelper
[Guid("45BA127D-10A8-46EA-8AB7-56EA9078943C")] [Guid("45BA127D-10A8-46EA-8AB7-56EA9078943C")]
public class ApplicationActivationManager : IApplicationActivationManager public class ApplicationActivationManager : IApplicationActivationManager
{ {
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)/*, PreserveSig*/] [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)/*, PreserveSig*/]
public extern IntPtr ActivateApplication([In] string appUserModelId, [In] string arguments, [In] ActivateOptions options, [Out] out uint processId); public extern IntPtr ActivateApplication([In] string appUserModelId, [In] string arguments, [In] ActivateOptions options, [Out] out uint processId);

View File

@@ -7,7 +7,6 @@ using Windows.Foundation;
namespace Microsoft.Plugin.Program.Programs namespace Microsoft.Plugin.Program.Programs
{ {
/// <summary> /// <summary>
/// This is a simple wrapper class around the PackageCatalog to facilitate unit testing. /// This is a simple wrapper class around the PackageCatalog to facilitate unit testing.
/// </summary> /// </summary>

View File

@@ -23,7 +23,9 @@ namespace Microsoft.Plugin.Program.Programs
public string InstalledLocation { get; } = string.Empty; public string InstalledLocation { get; } = string.Empty;
public PackageWrapper() { } public PackageWrapper()
{
}
public PackageWrapper(string Name, string FullName, string FamilyName, bool IsFramework, bool IsDevelopmentMode, string InstalledLocation) public PackageWrapper(string Name, string FullName, string FamilyName, bool IsFramework, bool IsDevelopmentMode, string InstalledLocation)
{ {
@@ -65,8 +67,7 @@ namespace Microsoft.Plugin.Program.Programs
package.Id.FamilyName, package.Id.FamilyName,
package.IsFramework, package.IsFramework,
package.IsDevelopmentMode, package.IsDevelopmentMode,
path path);
);
} }
} }
} }

View File

@@ -98,10 +98,8 @@ namespace Microsoft.Plugin.Program.Programs
Where(a => a.IsNamespaceDeclaration). Where(a => a.IsNamespaceDeclaration).
GroupBy( GroupBy(
a => a.Name.Namespace == XNamespace.None ? string.Empty : a.Name.LocalName, a => a.Name.Namespace == XNamespace.None ? string.Empty : a.Name.LocalName,
a => XNamespace.Get(a.Value) a => XNamespace.Get(a.Value)).Select(
).Select( g => g.First().ToString()).ToArray();
g => g.First().ToString()
).ToArray();
return namespaces; return namespaces;
} }
else else
@@ -116,9 +114,9 @@ namespace Microsoft.Plugin.Program.Programs
{ {
var versionFromNamespace = new Dictionary<string, PackageVersion> var versionFromNamespace = new Dictionary<string, PackageVersion>
{ {
{"http://schemas.microsoft.com/appx/manifest/foundation/windows10", PackageVersion.Windows10}, { "http://schemas.microsoft.com/appx/manifest/foundation/windows10", PackageVersion.Windows10 },
{"http://schemas.microsoft.com/appx/2013/manifest", PackageVersion.Windows81}, { "http://schemas.microsoft.com/appx/2013/manifest", PackageVersion.Windows81 },
{"http://schemas.microsoft.com/appx/2010/manifest", PackageVersion.Windows8}, { "http://schemas.microsoft.com/appx/2010/manifest", PackageVersion.Windows8 },
}; };
foreach (var n in versionFromNamespace.Keys) foreach (var n in versionFromNamespace.Keys)

View File

@@ -26,7 +26,6 @@ using static Microsoft.Plugin.Program.Programs.UWP;
namespace Microsoft.Plugin.Program.Programs namespace Microsoft.Plugin.Program.Programs
{ {
[Serializable] [Serializable]
public class UWPApplication : IProgram public class UWPApplication : IProgram
{ {
@@ -130,7 +129,7 @@ namespace Microsoft.Plugin.Program.Programs
Glyph = "\xE7EF", Glyph = "\xE7EF",
FontFamily = "Segoe MDL2 Assets", FontFamily = "Segoe MDL2 Assets",
AcceleratorKey = Key.Enter, AcceleratorKey = Key.Enter,
AcceleratorModifiers = (ModifierKeys.Control | ModifierKeys.Shift), AcceleratorModifiers = ModifierKeys.Control | ModifierKeys.Shift,
Action = _ => Action = _ =>
{ {
string command = "shell:AppsFolder\\" + UniqueIdentifier; string command = "shell:AppsFolder\\" + UniqueIdentifier;
@@ -142,8 +141,7 @@ namespace Microsoft.Plugin.Program.Programs
Process.Start(info); Process.Start(info);
return true; return true;
}, },
} });
);
} }
contextMenus.Add( contextMenus.Add(
@@ -154,7 +152,7 @@ namespace Microsoft.Plugin.Program.Programs
Glyph = "\xE838", Glyph = "\xE838",
FontFamily = "Segoe MDL2 Assets", FontFamily = "Segoe MDL2 Assets",
AcceleratorKey = Key.E, AcceleratorKey = Key.E,
AcceleratorModifiers = (ModifierKeys.Control | ModifierKeys.Shift), AcceleratorModifiers = ModifierKeys.Control | ModifierKeys.Shift,
Action = _ => Action = _ =>
{ {
Main.StartProcess(Process.Start, new ProcessStartInfo("explorer", Package.Location)); Main.StartProcess(Process.Start, new ProcessStartInfo("explorer", Package.Location));

View File

@@ -23,7 +23,6 @@ using Wox.Plugin;
namespace Microsoft.Plugin.Program.Programs namespace Microsoft.Plugin.Program.Programs
{ {
[Serializable] [Serializable]
public class Win32Program : IProgram public class Win32Program : IProgram
{ {
@@ -211,7 +210,7 @@ namespace Microsoft.Plugin.Program.Programs
{ {
FileName = LnkResolvedPath ?? FullPath, FileName = LnkResolvedPath ?? FullPath,
WorkingDirectory = ParentDirectory, WorkingDirectory = ParentDirectory,
UseShellExecute = true UseShellExecute = true,
}; };
Main.StartProcess(Process.Start, info); Main.StartProcess(Process.Start, info);
@@ -250,7 +249,7 @@ namespace Microsoft.Plugin.Program.Programs
Glyph = "\xE7EF", Glyph = "\xE7EF",
FontFamily = "Segoe MDL2 Assets", FontFamily = "Segoe MDL2 Assets",
AcceleratorKey = Key.Enter, AcceleratorKey = Key.Enter,
AcceleratorModifiers = (ModifierKeys.Control | ModifierKeys.Shift), AcceleratorModifiers = ModifierKeys.Control | ModifierKeys.Shift,
Action = _ => Action = _ =>
{ {
var info = new ProcessStartInfo var info = new ProcessStartInfo
@@ -258,7 +257,7 @@ namespace Microsoft.Plugin.Program.Programs
FileName = FullPath, FileName = FullPath,
WorkingDirectory = ParentDirectory, WorkingDirectory = ParentDirectory,
Verb = "runas", Verb = "runas",
UseShellExecute = true UseShellExecute = true,
}; };
Task.Run(() => Main.StartProcess(Process.Start, info)); Task.Run(() => Main.StartProcess(Process.Start, info));
@@ -276,7 +275,7 @@ namespace Microsoft.Plugin.Program.Programs
Glyph = "\xE838", Glyph = "\xE838",
FontFamily = "Segoe MDL2 Assets", FontFamily = "Segoe MDL2 Assets",
AcceleratorKey = Key.E, AcceleratorKey = Key.E,
AcceleratorModifiers = (ModifierKeys.Control | ModifierKeys.Shift), AcceleratorModifiers = ModifierKeys.Control | ModifierKeys.Shift,
Action = _ => Action = _ =>
{ {
Main.StartProcess(Process.Start, new ProcessStartInfo("explorer", ParentDirectory)); Main.StartProcess(Process.Start, new ProcessStartInfo("explorer", ParentDirectory));
@@ -632,7 +631,6 @@ namespace Microsoft.Plugin.Program.Programs
// Function to obtain the list of applications, the locations of which have been added to the env variable PATH // Function to obtain the list of applications, the locations of which have been added to the env variable PATH
private static ParallelQuery<Win32Program> PathEnvironmentPrograms(IList<string> suffixes) private static ParallelQuery<Win32Program> PathEnvironmentPrograms(IList<string> suffixes)
{ {
// To get all the locations stored in the PATH env variable // To get all the locations stored in the PATH env variable
var pathEnvVariable = Environment.GetEnvironmentVariable("PATH"); var pathEnvVariable = Environment.GetEnvironmentVariable("PATH");
string[] searchPaths = pathEnvVariable.Split(Path.PathSeparator); string[] searchPaths = pathEnvVariable.Split(Path.PathSeparator);
@@ -757,14 +755,18 @@ namespace Microsoft.Plugin.Program.Programs
using (var key = root.OpenSubKey(subkey)) using (var key = root.OpenSubKey(subkey))
{ {
if (key == null) if (key == null)
{
return string.Empty; return string.Empty;
}
var defaultValue = string.Empty; var defaultValue = string.Empty;
path = key.GetValue(defaultValue) as string; path = key.GetValue(defaultValue) as string;
} }
if (string.IsNullOrEmpty(path)) if (string.IsNullOrEmpty(path))
{
return string.Empty; return string.Empty;
}
// fix path like this: ""\"C:\\folder\\executable.exe\"" // fix path like this: ""\"C:\\folder\\executable.exe\""
return path = path.Trim('"', ' '); return path = path.Trim('"', ' ');
@@ -782,12 +784,16 @@ namespace Microsoft.Plugin.Program.Programs
private static Win32Program GetProgramFromPath(string path) private static Win32Program GetProgramFromPath(string path)
{ {
if (string.IsNullOrEmpty(path)) if (string.IsNullOrEmpty(path))
{
return new Win32Program(); return new Win32Program();
}
path = Environment.ExpandEnvironmentVariables(path); path = Environment.ExpandEnvironmentVariables(path);
if (!File.Exists(path)) if (!File.Exists(path))
{
return new Win32Program(); return new Win32Program();
}
var entry = CreateWin32Program(path); var entry = CreateWin32Program(path);
entry.ExecutableName = Path.GetFileName(path); entry.ExecutableName = Path.GetFileName(path);
@@ -812,7 +818,6 @@ namespace Microsoft.Plugin.Program.Programs
{ {
public bool Equals(Win32Program app1, Win32Program app2) public bool Equals(Win32Program app1, Win32Program app2)
{ {
if (!string.IsNullOrEmpty(app1.Name) && !string.IsNullOrEmpty(app2.Name) if (!string.IsNullOrEmpty(app1.Name) && !string.IsNullOrEmpty(app2.Name)
&& !string.IsNullOrEmpty(app1.ExecutableName) && !string.IsNullOrEmpty(app2.ExecutableName) && !string.IsNullOrEmpty(app1.ExecutableName) && !string.IsNullOrEmpty(app2.ExecutableName)
&& !string.IsNullOrEmpty(app1.FullPath) && !string.IsNullOrEmpty(app2.FullPath)) && !string.IsNullOrEmpty(app1.FullPath) && !string.IsNullOrEmpty(app2.FullPath))

View File

@@ -34,7 +34,6 @@ namespace Microsoft.Plugin.Program.Storage
{ {
if (args.IsComplete) if (args.IsComplete)
{ {
try try
{ {
var packageWrapper = PackageWrapper.GetWrapperFromPackage(args.Package); var packageWrapper = PackageWrapper.GetWrapperFromPackage(args.Package);

View File

@@ -10,7 +10,6 @@ namespace Microsoft.Plugin.Program.Storage
{ {
internal class Win32ProgramFileSystemWatchers : IDisposable internal class Win32ProgramFileSystemWatchers : IDisposable
{ {
public readonly string[] _pathsToWatch; public readonly string[] _pathsToWatch;
public List<FileSystemWatcherWrapper> _fileSystemWatchers; public List<FileSystemWatcherWrapper> _fileSystemWatchers;
private bool _disposed = false; private bool _disposed = false;

View File

@@ -21,8 +21,7 @@ namespace Microsoft.Plugin.Program.Views.Commands
Location = x.Location, Location = x.Location,
Name = x.Name, Name = x.Name,
UniqueIdentifier = x.UniqueIdentifier, UniqueIdentifier = x.UniqueIdentifier,
} }));
));
// Even though these are disabled, we still want to display them so users can enable later on // Even though these are disabled, we still want to display them so users can enable later on
Main._settings Main._settings
@@ -40,8 +39,7 @@ namespace Microsoft.Plugin.Program.Views.Commands
Location = x.Location, Location = x.Location,
Name = x.Name, Name = x.Name,
UniqueIdentifier = x.UniqueIdentifier, UniqueIdentifier = x.UniqueIdentifier,
} }));
));
return list; return list;
} }
@@ -95,8 +93,7 @@ namespace Microsoft.Plugin.Program.Views.Commands
Location = x.Location, Location = x.Location,
UniqueIdentifier = x.UniqueIdentifier, UniqueIdentifier = x.UniqueIdentifier,
Enabled = false, Enabled = false,
} }));
));
} }
internal static void RemoveDisabledFromSettings(this List<ProgramSource> list) internal static void RemoveDisabledFromSettings(this List<ProgramSource> list)
@@ -115,13 +112,17 @@ namespace Microsoft.Plugin.Program.Views.Commands
internal static bool IsReindexRequired(this List<ProgramSource> selectedItems) internal static bool IsReindexRequired(this List<ProgramSource> selectedItems)
{ {
if (selectedItems.Where(t1 => t1.Enabled).Any()) if (selectedItems.Where(t1 => t1.Enabled).Any())
{
return true; return true;
}
// ProgramSources holds list of user added directories, // ProgramSources holds list of user added directories,
// so when we enable/disable we need to reindex to show/not show the programs // so when we enable/disable we need to reindex to show/not show the programs
// that are found in those directories. // that are found in those directories.
if (selectedItems.Where(t1 => Main._settings.ProgramSources.Any(x => t1.UniqueIdentifier == x.UniqueIdentifier)).Any()) if (selectedItems.Where(t1 => Main._settings.ProgramSources.Any(x => t1.UniqueIdentifier == x.UniqueIdentifier)).Any())
{
return true; return true;
}
return false; return false;
} }

View File

@@ -218,7 +218,9 @@ namespace Microsoft.Plugin.Program.Views
} }
if (selectedItems.IsReindexRequired()) if (selectedItems.IsReindexRequired())
{
ReIndexing(); ReIndexing();
}
programSourceView.SelectedItems.Clear(); programSourceView.SelectedItems.Clear();

View File

@@ -13,11 +13,9 @@ namespace Microsoft.Plugin.Program.Win32
class NativeMethods class NativeMethods
{ {
[DllImport("shlwapi.dll", CharSet = CharSet.Unicode)] [DllImport("shlwapi.dll", CharSet = CharSet.Unicode)]
internal static extern Hresult SHCreateStreamOnFileEx(string fileName, Stgm grfMode, uint attributes, bool create, internal static extern Hresult SHCreateStreamOnFileEx(string fileName, Stgm grfMode, uint attributes, bool create, IStream reserved, out IStream stream);
IStream reserved, out IStream stream);
[DllImport("shlwapi.dll", CharSet = CharSet.Unicode)] [DllImport("shlwapi.dll", CharSet = CharSet.Unicode)]
internal static extern Hresult SHLoadIndirectString(string pszSource, StringBuilder pszOutBuf, uint cchOutBuf, internal static extern Hresult SHLoadIndirectString(string pszSource, StringBuilder pszOutBuf, uint cchOutBuf, IntPtr ppvReserved);
IntPtr ppvReserved);
} }
} }