[stylecop] program plugin/unit test first pass (#5908)

* initial pass

* multiple whitespace fixes
This commit is contained in:
Clint Rutkas
2020-08-12 11:46:11 -07:00
committed by GitHub
parent 8888739867
commit 95e82ca359
36 changed files with 351 additions and 273 deletions

View File

@@ -1,8 +1,10 @@
using System;
using System.Diagnostics;
// 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;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
namespace Microsoft.Plugin.Program.Programs.ApplicationActivationHelper
{
@@ -21,7 +23,9 @@ namespace Microsoft.Plugin.Program.Programs.ApplicationActivationHelper
public interface IApplicationActivationManager
{
IntPtr ActivateApplication([In] String appUserModelId, [In] String arguments, [In] ActivateOptions options, [Out] out UInt32 processId);
IntPtr ActivateForFile([In] String appUserModelId, [In] IntPtr /*IShellItemArray* */ itemArray, [In] String verb, [Out] out UInt32 processId);
IntPtr ActivateForProtocol([In] String appUserModelId, [In] IntPtr /* IShellItemArray* */itemArray, [Out] out UInt32 processId);
}

View File

@@ -1,9 +1,11 @@
using System;
// 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;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using Windows.Storage;
using static Microsoft.Plugin.Program.Programs.UWP;
namespace Microsoft.Plugin.Program.Programs
@@ -52,6 +54,7 @@ namespace Microsoft.Plugin.Program.Programs
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "Implements COM Interface")]
void _VtblGap0_2(); // skip 2 methods
IAppxManifestReader CreateManifestReader(IStream inputStream);
}
@@ -60,10 +63,12 @@ namespace Microsoft.Plugin.Program.Programs
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "Implements COM Interface")]
void _VtblGap0_1(); // skip 1 method
IAppxManifestProperties GetProperties();
[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "Implements COM Interface")]
void _VtblGap1_5(); // skip 5 methods
IAppxManifestApplicationsEnumerator GetApplications();
}
@@ -71,7 +76,9 @@ namespace Microsoft.Plugin.Program.Programs
public interface IAppxManifestApplicationsEnumerator
{
IAppxManifestApplication GetCurrent();
bool GetHasCurrent();
bool MoveNext();
}
@@ -90,6 +97,7 @@ namespace Microsoft.Plugin.Program.Programs
{
[PreserveSig]
Hresult GetBoolValue([MarshalAs(UnmanagedType.LPWStr)] string name, out bool value);
[PreserveSig]
Hresult GetStringValue([MarshalAs(UnmanagedType.LPWStr)] string name, [MarshalAs(UnmanagedType.LPWStr)] out string value);
}

View File

@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using System.Text;
// 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.
namespace Microsoft.Plugin.Program.Programs
{

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Text;
// 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 Windows.ApplicationModel;
using Windows.Foundation;
@@ -9,7 +10,9 @@ namespace Microsoft.Plugin.Program.Programs
internal interface IPackageCatalog
{
event TypedEventHandler<PackageCatalog, PackageInstallingEventArgs> PackageInstalling;
event TypedEventHandler<PackageCatalog, PackageUninstallingEventArgs> PackageUninstalling;
event TypedEventHandler<PackageCatalog, PackageUpdatingEventArgs> PackageUpdating;
}
}

View File

@@ -1,6 +1,8 @@
using System;
// 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.Collections.Generic;
using System.Text;
namespace Microsoft.Plugin.Program.Programs
{

View File

@@ -1,4 +1,8 @@
using System.Collections.Generic;
// 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.Collections.Generic;
using Wox.Plugin;
namespace Microsoft.Plugin.Program.Programs
@@ -6,10 +10,15 @@ namespace Microsoft.Plugin.Program.Programs
public interface IProgram
{
List<ContextMenuResult> ContextMenus(IPublicAPI api);
Result Result(string query, IPublicAPI api);
string UniqueIdentifier { get; set; }
string Name { get; }
string Description { get; set; }
string Location { get; }
}
}

View File

@@ -1,14 +1,17 @@
using System;
using System.Collections.Generic;
using System.Text;
// 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.
namespace Microsoft.Plugin.Program.Programs
{
public interface IShellLinkHelper
{
string RetrieveTargetPath(string path);
string description { get; set; }
string Arguments { get; set; }
bool hasArguments { get; set; }
}

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Text;
// 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 Windows.ApplicationModel;
using Windows.Foundation;
@@ -52,7 +53,6 @@ namespace Microsoft.Plugin.Program.Programs
}
}
//
// Summary:
// Indicates that an app package is updating.

View File

@@ -1,6 +1,10 @@
using Microsoft.Plugin.Program.Logger;
// 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;
using System.IO;
using Microsoft.Plugin.Program.Logger;
using Package = Windows.ApplicationModel.Package;
namespace Microsoft.Plugin.Program.Programs

View File

@@ -1,9 +1,10 @@
using System;
// 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.Collections.Generic;
using System.IO.Packaging;
using System.Security.Principal;
using Windows.Management.Deployment;
using Windows.ApplicationModel;
using Package = Windows.ApplicationModel.Package;
namespace Microsoft.Plugin.Program.Programs

View File

@@ -1,11 +1,12 @@
using System;
using System.Collections.Generic;
using System.Text;
// 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;
using System.Runtime.InteropServices;
using System.IO;
using Accessibility;
using System.Runtime.InteropServices.ComTypes;
using System.Security.Policy;
using System.Text;
using Accessibility;
using Microsoft.Plugin.Program.Logger;
namespace Microsoft.Plugin.Program.Programs
@@ -17,7 +18,7 @@ namespace Microsoft.Plugin.Program.Programs
{
SLGP_SHORTPATH = 0x1,
SLGP_UNCPRIORITY = 0x2,
SLGP_RAWPATH = 0x4
SLGP_RAWPATH = 0x4,
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
@@ -48,10 +49,9 @@ namespace Microsoft.Plugin.Program.Programs
SLR_NOSEARCH = 0x10,
SLR_NOTRACK = 0x20,
SLR_NOLINKINFO = 0x40,
SLR_INVOKE_MSI = 0x80
SLR_INVOKE_MSI = 0x80,
}
// Reference : http://www.pinvoke.net/default.aspx/Interfaces.IShellLinkW
/// The IShellLink interface allows Shell links to be created, modified, and resolved
[ComImport(), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("000214F9-0000-0000-C000-000000000046")]
@@ -106,6 +106,7 @@ namespace Microsoft.Plugin.Program.Programs
// Contains the arguments to the app
public string Arguments { get; set; } = String.Empty;
public bool hasArguments { get; set; } = false;
// Retrieve the target path using Shell Link
@@ -154,4 +155,4 @@ namespace Microsoft.Plugin.Program.Programs
return target;
}
}
}
}

View File

@@ -1,19 +1,17 @@
// 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;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Security.Principal;
using System.Text;
using System.Xml.Linq;
using Windows.ApplicationModel;
using Windows.Management.Deployment;
using Microsoft.Plugin.Program.Logger;
using Rect = System.Windows.Rect;
using System.Windows.Controls;
using System.Runtime.InteropServices.ComTypes;
using Wox.Infrastructure.Logger;
using System.Xml.Linq;
using Microsoft.Plugin.Program.Logger;
using Microsoft.Plugin.Program.Win32;
using Wox.Infrastructure.Logger;
namespace Microsoft.Plugin.Program.Programs
{
@@ -21,8 +19,11 @@ namespace Microsoft.Plugin.Program.Programs
public partial class UWP
{
public string Name { get; }
public string FullName { get; }
public string FamilyName { get; }
public string Location { get; set; }
public IList<UWPApplication> Apps { get; private set; }
@@ -86,9 +87,7 @@ namespace Microsoft.Plugin.Program.Programs
Apps = new List<UWPApplication>().ToArray();
}
}
/// http://www.hanselman.com/blog/GetNamespacesFromAnXMLDocumentWithXPathDocumentAndLINQToXML.aspx
private static string[] XmlNamespaces(string path)
{
@@ -195,7 +194,6 @@ namespace Microsoft.Plugin.Program.Programs
return false;
}
return valid;
});
@@ -229,7 +227,7 @@ namespace Microsoft.Plugin.Program.Programs
Windows10,
Windows81,
Windows8,
Unknown
Unknown,
}
[Flags]
@@ -244,6 +242,5 @@ namespace Microsoft.Plugin.Program.Programs
Ok = 0x0,
}
}
}
}

View File

@@ -1,25 +1,28 @@
using System;
// 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;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using Wox.Infrastructure;
using Microsoft.Plugin.Program.Logger;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Wox.Plugin;
using System.Windows.Input;
using Wox.Plugin.SharedCommands;
using System.Reflection;
using Microsoft.Plugin.Program.Logger;
using Microsoft.Plugin.Program.Win32;
using Wox.Infrastructure;
using Wox.Infrastructure.Image;
using Wox.Infrastructure.Logger;
using Wox.Plugin;
using Wox.Plugin.SharedCommands;
using static Microsoft.Plugin.Program.Programs.UWP;
using System.Runtime.InteropServices.ComTypes;
using System.Globalization;
using Microsoft.Plugin.Program.Win32;
namespace Microsoft.Plugin.Program.Programs
{
@@ -28,20 +31,29 @@ namespace Microsoft.Plugin.Program.Programs
public class UWPApplication : IProgram
{
public string AppListEntry { get; set; }
public string UniqueIdentifier { get; set; }
public string DisplayName { get; set; }
public string Description { get; set; }
public string UserModelId { get; set; }
public string BackgroundColor { get; set; }
public string EntryPoint { get; set; }
public string Name => DisplayName;
public string Location => Package.Location;
public bool Enabled { get; set; }
public bool CanRunElevated { get; set; }
public string LogoPath { get; set; }
public UWP Package { get; set; }
private string logoUri;
@@ -84,14 +96,13 @@ namespace Microsoft.Plugin.Program.Programs
{
Launch(api);
return true;
}
},
};
// To set the title to always be the displayname of the packaged application
result.Title = DisplayName;
result.TitleHighlightData = StringMatcher.FuzzySearch(query, Name).MatchData;
var toolTipTitle = string.Format(CultureInfo.CurrentCulture, "{0}: {1}", api.GetTranslation("powertoys_run_plugin_program_file_name"), result.Title);
var toolTipText = string.Format(CultureInfo.CurrentCulture, "{0}: {1}", api.GetTranslation("powertoys_run_plugin_program_file_path"), Package.Location);
result.ToolTipData = new ToolTipData(toolTipTitle, toolTipText);
@@ -130,7 +141,7 @@ namespace Microsoft.Plugin.Program.Programs
Process.Start(info);
return true;
}
},
}
);
}
@@ -148,7 +159,7 @@ namespace Microsoft.Plugin.Program.Programs
Main.StartProcess(Process.Start, new ProcessStartInfo("explorer", Package.Location));
return true;
}
},
});
contextMenus.Add(new ContextMenuResult
@@ -171,7 +182,7 @@ namespace Microsoft.Plugin.Program.Programs
Log.Exception($"|Microsoft.Plugin.Program.UWP.ContextMenu| Failed to open {Name} in console, {e.Message}", e);
return false;
}
}
},
});
return contextMenus;
@@ -318,7 +329,6 @@ namespace Microsoft.Plugin.Program.Programs
}
}
internal string LogoUriFromManifest(IAppxManifestApplication app)
{
var logoKeyFromVersion = new Dictionary<PackageVersion, string>
@@ -382,7 +392,7 @@ namespace Microsoft.Plugin.Program.Programs
// scale factors on win10: https://docs.microsoft.com/en-us/windows/uwp/controls-and-patterns/tiles-and-notifications-app-assets#asset-size-tables,
{ PackageVersion.Windows10, new List<int> { 100, 125, 150, 200, 400 } },
{ PackageVersion.Windows81, new List<int> { 100, 120, 140, 160, 180 } },
{ PackageVersion.Windows8, new List<int> { 100 } }
{ PackageVersion.Windows8, new List<int> { 100 } },
};
if (scaleFactors.ContainsKey(Package.Version))
@@ -451,7 +461,6 @@ namespace Microsoft.Plugin.Program.Programs
return logo;
}
private BitmapImage ImageFromPath(string path)
{
if (File.Exists(path))
@@ -483,4 +492,4 @@ namespace Microsoft.Plugin.Program.Programs
}
}
}
}

View File

@@ -1,22 +1,25 @@
// 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;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Reflection;
using System.Security;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Input;
using Microsoft.Plugin.Program.Logger;
using Microsoft.Win32;
using Wox.Infrastructure;
using Microsoft.Plugin.Program.Logger;
using Wox.Plugin;
using System.Windows.Input;
using System.Reflection;
using System.Text.RegularExpressions;
using Wox.Infrastructure.Logger;
using Wox.Infrastructure.FileSystemHelper;
using System.Globalization;
using Wox.Infrastructure.Logger;
using Wox.Plugin;
namespace Microsoft.Plugin.Program.Programs
{
@@ -25,22 +28,38 @@ namespace Microsoft.Plugin.Program.Programs
public class Win32Program : IProgram
{
public string Name { get; set; }
public string UniqueIdentifier { get; set; }
public string IcoPath { get; set; }
public string FullPath { get; set; }
public string LnkResolvedPath { get; set; }
public string ParentDirectory { get; set; }
public string ExecutableName { get; set; }
public string Description { get; set; } = String.Empty;
public bool Valid { get; set; }
public bool Enabled { get; set; }
public bool hasArguments { get; set; } = false;
public string Arguments { get; set; } = String.Empty;
public string Location => ParentDirectory;
public uint AppType { get; set; }
// Wrappers for File Operations
public static IFileVersionInfoWrapper FileVersionInfoWrapper { get; set;} = new FileVersionInfoWrapper();
public static IFileWrapper FileWrapper { get; set; } = new FileWrapper();
public static IShellLinkHelper Helper { get; set; } = new ShellLinkHelper();
private const string ShortcutExtension = "lnk";
@@ -56,7 +75,7 @@ namespace Microsoft.Plugin.Program.Programs
WEB_APPLICATION = 0,
INTERNET_SHORTCUT_APPLICATION = 1,
WIN32_APPLICATION = 2,
RUN_COMMAND = 3
RUN_COMMAND = 3,
}
// Function to calculate the score of a result
@@ -197,7 +216,7 @@ namespace Microsoft.Plugin.Program.Programs
Main.StartProcess(Process.Start, info);
return true;
}
},
};
// To set the title for the result to always be the name of the application
@@ -244,7 +263,7 @@ namespace Microsoft.Plugin.Program.Programs
Task.Run(() => Main.StartProcess(Process.Start, info));
return true;
}
},
});
}
@@ -261,7 +280,7 @@ namespace Microsoft.Plugin.Program.Programs
{
Main.StartProcess(Process.Start, new ProcessStartInfo("explorer", ParentDirectory));
return true;
}
},
});
contextMenus.Add(
@@ -285,14 +304,12 @@ namespace Microsoft.Plugin.Program.Programs
Log.Exception($"|Microsoft.Plugin.Program.Win32.ContextMenu| Failed to open {Name} in console, {e.Message}", e);
return false;
}
}
},
});
return contextMenus;
}
public override string ToString()
{
return ExecutableName;
@@ -313,7 +330,7 @@ namespace Microsoft.Plugin.Program.Programs
Description = string.Empty,
Valid = true,
Enabled = true,
AppType = (uint)ApplicationTypes.WIN32_APPLICATION
AppType = (uint)ApplicationTypes.WIN32_APPLICATION,
};
return p;
}
@@ -378,7 +395,7 @@ namespace Microsoft.Plugin.Program.Programs
ParentDirectory = Directory.GetParent(path).FullName,
Valid = true,
Enabled = true,
AppType = (uint)ApplicationTypes.INTERNET_SHORTCUT_APPLICATION
AppType = (uint)ApplicationTypes.INTERNET_SHORTCUT_APPLICATION,
};
return p;
}
@@ -602,8 +619,7 @@ namespace Microsoft.Plugin.Program.Programs
select CreateWin32Program(p);
return programs1.Concat(programs2).Concat(programs3);
}
// 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)
{