mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 11:16:51 +02:00
Program plugin fully on stylecop (#5964)
This commit is contained in:
@@ -1,38 +1,15 @@
|
||||
// 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.
|
||||
|
||||
// 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;
|
||||
|
||||
namespace Microsoft.Plugin.Program.Programs.ApplicationActivationHelper
|
||||
{
|
||||
// Reference : https://github.com/MicrosoftEdge/edge-launcher/blob/108e63df0b4cb5cd9d5e45aa7a264690851ec51d/MIcrosoftEdgeLauncherCsharp/Program.cs
|
||||
[Flags]
|
||||
public enum ActivateOptions
|
||||
{
|
||||
None = 0x00000000,
|
||||
DesignMode = 0x00000001,
|
||||
NoErrorUI = 0x00000002,
|
||||
NoSplashScreen = 0x00000004,
|
||||
}
|
||||
|
||||
// ApplicationActivationManager
|
||||
[ComImport]
|
||||
[Guid("2e941141-7f97-4756-ba1d-9decde894a3d")]
|
||||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
public interface IApplicationActivationManager
|
||||
{
|
||||
IntPtr ActivateApplication([In] string appUserModelId, [In] string arguments, [In] ActivateOptions options, [Out] out uint processId);
|
||||
|
||||
IntPtr ActivateForFile([In] string appUserModelId, [In] IntPtr /*IShellItemArray* */ itemArray, [In] string verb, [Out] out uint processId);
|
||||
|
||||
IntPtr ActivateForProtocol([In] string appUserModelId, [In] IntPtr /* IShellItemArray* */itemArray, [Out] out uint processId);
|
||||
}
|
||||
|
||||
{
|
||||
// Application Activation Manager Class
|
||||
[ComImport]
|
||||
[ComImport]
|
||||
[Guid("45BA127D-10A8-46EA-8AB7-56EA9078943C")]
|
||||
public class ApplicationActivationManager : IApplicationActivationManager
|
||||
{
|
||||
@@ -0,0 +1,16 @@
|
||||
// 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;
|
||||
|
||||
namespace Microsoft.Plugin.Program.Programs
|
||||
{
|
||||
// Reference : https://stackoverflow.com/questions/32122679/getting-icon-of-modern-windows-app-from-a-desktop-application
|
||||
[Guid("5842a140-ff9f-4166-8f5c-62f5b7b0c781")]
|
||||
[ComImport]
|
||||
public class AppxFactory
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -2,37 +2,37 @@
|
||||
// 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.Runtime.InteropServices;
|
||||
using System.Runtime.InteropServices.ComTypes;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.InteropServices.ComTypes;
|
||||
using static Microsoft.Plugin.Program.Programs.UWP;
|
||||
|
||||
namespace Microsoft.Plugin.Program.Programs
|
||||
{
|
||||
public static class AppxPackageHelper
|
||||
{
|
||||
// This function returns a list of attributes of applications
|
||||
public static List<IAppxManifestApplication> getAppsFromManifest(IStream stream)
|
||||
{
|
||||
List<IAppxManifestApplication> apps = new List<IAppxManifestApplication>();
|
||||
var appxFactory = new AppxFactory();
|
||||
var reader = ((IAppxFactory)appxFactory).CreateManifestReader(stream);
|
||||
var manifestApps = reader.GetApplications();
|
||||
while (manifestApps.GetHasCurrent())
|
||||
{
|
||||
var manifestApp = manifestApps.GetCurrent();
|
||||
var hr = manifestApp.GetStringValue("AppListEntry", out var appListEntry);
|
||||
_ = CheckHRAndReturnOrThrow(hr, appListEntry);
|
||||
if (appListEntry != "none")
|
||||
{
|
||||
apps.Add(manifestApp);
|
||||
}
|
||||
namespace Microsoft.Plugin.Program.Programs
|
||||
{
|
||||
public static class AppxPackageHelper
|
||||
{
|
||||
// This function returns a list of attributes of applications
|
||||
public static List<IAppxManifestApplication> GetAppsFromManifest(IStream stream)
|
||||
{
|
||||
List<IAppxManifestApplication> apps = new List<IAppxManifestApplication>();
|
||||
var appxFactory = new AppxFactory();
|
||||
var reader = ((IAppxFactory)appxFactory).CreateManifestReader(stream);
|
||||
var manifestApps = reader.GetApplications();
|
||||
|
||||
manifestApps.MoveNext();
|
||||
}
|
||||
while (manifestApps.GetHasCurrent())
|
||||
{
|
||||
var manifestApp = manifestApps.GetCurrent();
|
||||
var hr = manifestApp.GetStringValue("AppListEntry", out var appListEntry);
|
||||
_ = CheckHRAndReturnOrThrow(hr, appListEntry);
|
||||
if (appListEntry != "none")
|
||||
{
|
||||
apps.Add(manifestApp);
|
||||
}
|
||||
|
||||
return apps;
|
||||
manifestApps.MoveNext();
|
||||
}
|
||||
|
||||
return apps;
|
||||
}
|
||||
|
||||
public static T CheckHRAndReturnOrThrow<T>(Hresult hr, T result)
|
||||
@@ -43,71 +43,6 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Reference : https://stackoverflow.com/questions/32122679/getting-icon-of-modern-windows-app-from-a-desktop-application
|
||||
[Guid("5842a140-ff9f-4166-8f5c-62f5b7b0c781")]
|
||||
[ComImport]
|
||||
public class AppxFactory
|
||||
{
|
||||
}
|
||||
|
||||
[Guid("BEB94909-E451-438B-B5A7-D79E767B75D8")]
|
||||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
public interface IAppxFactory
|
||||
{
|
||||
[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);
|
||||
}
|
||||
|
||||
[Guid("4E1BD148-55A0-4480-A3D1-15544710637C")]
|
||||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
public interface IAppxManifestReader
|
||||
{
|
||||
[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();
|
||||
}
|
||||
|
||||
[Guid("9EB8A55A-F04B-4D0D-808D-686185D4847A")]
|
||||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
public interface IAppxManifestApplicationsEnumerator
|
||||
{
|
||||
IAppxManifestApplication GetCurrent();
|
||||
|
||||
bool GetHasCurrent();
|
||||
|
||||
bool MoveNext();
|
||||
}
|
||||
|
||||
[Guid("5DA89BF4-3773-46BE-B650-7E744863B7E8")]
|
||||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
public interface IAppxManifestApplication
|
||||
{
|
||||
[PreserveSig]
|
||||
Hresult GetStringValue([MarshalAs(UnmanagedType.LPWStr)] string name, [MarshalAs(UnmanagedType.LPWStr)] out string value);
|
||||
|
||||
[PreserveSig]
|
||||
Hresult GetAppUserModelId([MarshalAs(UnmanagedType.LPWStr)] out string value);
|
||||
}
|
||||
|
||||
[Guid("03FAF64D-F26F-4B2C-AAF7-8FE7789B8BCA")]
|
||||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
public interface IAppxManifestProperties
|
||||
{
|
||||
[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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
// 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;
|
||||
|
||||
namespace Microsoft.Plugin.Program.Programs.ApplicationActivationHelper
|
||||
{
|
||||
// Reference : https://github.com/MicrosoftEdge/edge-launcher/blob/108e63df0b4cb5cd9d5e45aa7a264690851ec51d/MIcrosoftEdgeLauncherCsharp/Program.cs
|
||||
[Flags]
|
||||
public enum ActivateOptions
|
||||
{
|
||||
None = 0x00000000,
|
||||
DesignMode = 0x00000001,
|
||||
NoErrorUI = 0x00000002,
|
||||
NoSplashScreen = 0x00000004,
|
||||
}
|
||||
|
||||
// ApplicationActivationManager
|
||||
[ComImport]
|
||||
[Guid("2e941141-7f97-4756-ba1d-9decde894a3d")]
|
||||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
public interface IApplicationActivationManager
|
||||
{
|
||||
IntPtr ActivateApplication([In] string appUserModelId, [In] string arguments, [In] ActivateOptions options, [Out] out uint processId);
|
||||
|
||||
IntPtr ActivateForFile([In] string appUserModelId, [In] IntPtr /*IShellItemArray* */ itemArray, [In] string verb, [Out] out uint processId);
|
||||
|
||||
IntPtr ActivateForProtocol([In] string appUserModelId, [In] IntPtr /* IShellItemArray* */itemArray, [Out] out uint processId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
// 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.Runtime.InteropServices.ComTypes;
|
||||
|
||||
namespace Microsoft.Plugin.Program.Programs
|
||||
{
|
||||
[Guid("BEB94909-E451-438B-B5A7-D79E767B75D8")]
|
||||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
public interface IAppxFactory
|
||||
{
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "Implements COM Interface")]
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1300:Element should begin with upper-case letter", Justification = "Implements COM Interface")]
|
||||
void _VtblGap0_2(); // skip 2 methods
|
||||
|
||||
IAppxManifestReader CreateManifestReader(IStream inputStream);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
// 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 static Microsoft.Plugin.Program.Programs.UWP;
|
||||
|
||||
namespace Microsoft.Plugin.Program.Programs
|
||||
{
|
||||
[Guid("5DA89BF4-3773-46BE-B650-7E744863B7E8")]
|
||||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
public interface IAppxManifestApplication
|
||||
{
|
||||
[PreserveSig]
|
||||
Hresult GetStringValue([MarshalAs(UnmanagedType.LPWStr)] string name, [MarshalAs(UnmanagedType.LPWStr)] out string value);
|
||||
|
||||
[PreserveSig]
|
||||
Hresult GetAppUserModelId([MarshalAs(UnmanagedType.LPWStr)] out string value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
// 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;
|
||||
|
||||
namespace Microsoft.Plugin.Program.Programs
|
||||
{
|
||||
[Guid("9EB8A55A-F04B-4D0D-808D-686185D4847A")]
|
||||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
public interface IAppxManifestApplicationsEnumerator
|
||||
{
|
||||
IAppxManifestApplication GetCurrent();
|
||||
|
||||
bool GetHasCurrent();
|
||||
|
||||
bool MoveNext();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
// 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 static Microsoft.Plugin.Program.Programs.UWP;
|
||||
|
||||
namespace Microsoft.Plugin.Program.Programs
|
||||
{
|
||||
[Guid("03FAF64D-F26F-4B2C-AAF7-8FE7789B8BCA")]
|
||||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
public interface IAppxManifestProperties
|
||||
{
|
||||
[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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
// 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;
|
||||
|
||||
namespace Microsoft.Plugin.Program.Programs
|
||||
{
|
||||
[Guid("4E1BD148-55A0-4480-A3D1-15544710637C")]
|
||||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
public interface IAppxManifestReader
|
||||
{
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "Implements COM Interface")]
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1300:Element should begin with upper-case letter", 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")]
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1300:Element should begin with upper-case letter", Justification = "Implements COM Interface")]
|
||||
void _VtblGap1_5(); // skip 5 methods
|
||||
|
||||
IAppxManifestApplicationsEnumerator GetApplications();
|
||||
}
|
||||
}
|
||||
@@ -8,10 +8,10 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
{
|
||||
string RetrieveTargetPath(string path);
|
||||
|
||||
string description { get; set; }
|
||||
string Description { get; set; }
|
||||
|
||||
string Arguments { get; set; }
|
||||
|
||||
bool hasArguments { get; set; }
|
||||
bool HasArguments { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
/// </summary>
|
||||
internal class PackageCatalogWrapper : IPackageCatalog
|
||||
{
|
||||
PackageCatalog _packageCatalog;
|
||||
private PackageCatalog _packageCatalog;
|
||||
|
||||
public PackageCatalogWrapper()
|
||||
{
|
||||
|
||||
@@ -27,14 +27,14 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
{
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
this.Name = Name;
|
||||
this.FullName = FullName;
|
||||
this.FamilyName = FamilyName;
|
||||
this.IsFramework = IsFramework;
|
||||
this.IsDevelopmentMode = IsDevelopmentMode;
|
||||
this.InstalledLocation = InstalledLocation;
|
||||
Name = name;
|
||||
FullName = fullName;
|
||||
FamilyName = familyName;
|
||||
IsFramework = isFramework;
|
||||
IsDevelopmentMode = isDevelopmentMode;
|
||||
InstalledLocation = installedLocation;
|
||||
}
|
||||
|
||||
public static PackageWrapper GetWrapperFromPackage(Package package)
|
||||
|
||||
@@ -11,11 +11,11 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
{
|
||||
public class PackageManagerWrapper : IPackageManager
|
||||
{
|
||||
readonly PackageManager packageManager;
|
||||
private readonly PackageManager _packageManager;
|
||||
|
||||
public PackageManagerWrapper()
|
||||
{
|
||||
packageManager = new PackageManager();
|
||||
_packageManager = new PackageManager();
|
||||
}
|
||||
|
||||
public IEnumerable<IPackage> FindPackagesForCurrentUser()
|
||||
@@ -26,7 +26,7 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
if (user != null)
|
||||
{
|
||||
var id = user.Value;
|
||||
var m = this.packageManager.FindPackagesForUser(id);
|
||||
var m = _packageManager.FindPackagesForUser(id);
|
||||
foreach (Package p in m)
|
||||
{
|
||||
packages.Add(PackageWrapper.GetWrapperFromPackage(p));
|
||||
|
||||
@@ -22,8 +22,9 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1307:Accessible fields should begin with upper-case letter", Justification = "Matching COM")]
|
||||
private struct WIN32_FIND_DATAW
|
||||
{
|
||||
{
|
||||
public uint dwFileAttributes;
|
||||
public long ftCreationTime;
|
||||
public long ftLastAccessTime;
|
||||
@@ -58,7 +59,7 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
[ComImport]
|
||||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
[Guid("000214F9-0000-0000-C000-000000000046")]
|
||||
interface IShellLinkW
|
||||
private interface IShellLinkW
|
||||
{
|
||||
/// <summary>Retrieves the path and file name of a Shell link object</summary>
|
||||
void GetPath([Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszFile, int cchMaxPath, ref WIN32_FIND_DATAW pfd, SLGP_FLAGS fFlags);
|
||||
@@ -122,12 +123,12 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
}
|
||||
|
||||
// Contains the description of the app
|
||||
public string description { get; set; } = string.Empty;
|
||||
public string Description { get; set; } = string.Empty;
|
||||
|
||||
// Contains the arguments to the app
|
||||
public string Arguments { get; set; } = string.Empty;
|
||||
|
||||
public bool hasArguments { get; set; } = false;
|
||||
public bool HasArguments { get; set; } = false;
|
||||
|
||||
// Retrieve the target path using Shell Link
|
||||
public string RetrieveTargetPath(string path)
|
||||
@@ -160,7 +161,7 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
{
|
||||
buffer = new StringBuilder(MAX_PATH);
|
||||
((IShellLinkW)link).GetDescription(buffer, MAX_PATH);
|
||||
description = buffer.ToString();
|
||||
Description = buffer.ToString();
|
||||
|
||||
StringBuilder argumentBuffer = new StringBuilder(MAX_PATH);
|
||||
((IShellLinkW)link).GetArguments(argumentBuffer, argumentBuffer.Capacity);
|
||||
@@ -169,7 +170,7 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
// Set variable to true if the program takes in any arguments
|
||||
if (argumentBuffer.Length != 0)
|
||||
{
|
||||
hasArguments = true;
|
||||
HasArguments = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -60,10 +60,10 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
{
|
||||
var apps = new List<UWPApplication>();
|
||||
|
||||
List<IAppxManifestApplication> _apps = AppxPackageHelper.getAppsFromManifest(stream);
|
||||
foreach (var _app in _apps)
|
||||
List<IAppxManifestApplication> appsViaManifests = AppxPackageHelper.GetAppsFromManifest(stream);
|
||||
foreach (var appInManifest in appsViaManifests)
|
||||
{
|
||||
var app = new UWPApplication(_app, this);
|
||||
var app = new UWPApplication(appInManifest, this);
|
||||
apps.Add(app);
|
||||
}
|
||||
|
||||
@@ -163,7 +163,7 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
}).ToArray();
|
||||
|
||||
var updatedListWithoutDisabledApps = applications
|
||||
.Where(t1 => !Main._settings.DisabledProgramSources
|
||||
.Where(t1 => !Main.Settings.DisabledProgramSources
|
||||
.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier))
|
||||
.Select(x => x);
|
||||
|
||||
|
||||
@@ -237,7 +237,7 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
|
||||
DisplayName = ResourceFromPri(package.FullName, DisplayName);
|
||||
Description = ResourceFromPri(package.FullName, Description);
|
||||
this.logoUri = LogoUriFromManifest(manifestApp);
|
||||
logoUri = LogoUriFromManifest(manifestApp);
|
||||
|
||||
Enabled = true;
|
||||
CanRunElevated = IfApplicationcanRunElevated();
|
||||
@@ -354,11 +354,11 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
{
|
||||
if (theme == Theme.Light || theme == Theme.HighContrastWhite)
|
||||
{
|
||||
LogoPath = LogoPathFromUri(this.logoUri, "contrast-white");
|
||||
LogoPath = LogoPathFromUri(logoUri, "contrast-white");
|
||||
}
|
||||
else
|
||||
{
|
||||
LogoPath = LogoPathFromUri(this.logoUri, "contrast-black");
|
||||
LogoPath = LogoPathFromUri(logoUri, "contrast-black");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
|
||||
public bool Enabled { get; set; }
|
||||
|
||||
public bool hasArguments { get; set; } = false;
|
||||
public bool HasArguments { get; set; } = false;
|
||||
|
||||
public string Arguments { get; set; } = string.Empty;
|
||||
|
||||
@@ -66,8 +66,8 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
private const string ExeExtension = "exe";
|
||||
private const string InternetShortcutExtension = "url";
|
||||
|
||||
private const string proxyWebApp = "_proxy.exe";
|
||||
private const string appIdArgument = "--app-id";
|
||||
private const string ProxyWebApp = "_proxy.exe";
|
||||
private const string AppIdArgument = "--app-id";
|
||||
|
||||
private enum ApplicationTypes
|
||||
{
|
||||
@@ -92,7 +92,7 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
// To Filter PWAs when the user searches for the main application
|
||||
// All Chromium based applications contain the --app-id argument
|
||||
// Reference : https://codereview.chromium.org/399045/show
|
||||
bool isWebApplication = FullPath.Contains(proxyWebApp, StringComparison.OrdinalIgnoreCase) && Arguments.Contains(appIdArgument, StringComparison.OrdinalIgnoreCase);
|
||||
bool isWebApplication = FullPath.Contains(ProxyWebApp, StringComparison.OrdinalIgnoreCase) && Arguments.Contains(AppIdArgument, StringComparison.OrdinalIgnoreCase);
|
||||
return isWebApplication;
|
||||
}
|
||||
|
||||
@@ -178,7 +178,7 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!hasArguments)
|
||||
if (!HasArguments)
|
||||
{
|
||||
var noArgumentScoreModifier = 5;
|
||||
score += noArgumentScoreModifier;
|
||||
@@ -348,13 +348,11 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
private static Win32Program InternetShortcutProgram(string path)
|
||||
{
|
||||
string[] lines = FileWrapper.ReadAllLines(path);
|
||||
string appName = string.Empty;
|
||||
string iconPath = string.Empty;
|
||||
string urlPath = string.Empty;
|
||||
string scheme = string.Empty;
|
||||
bool validApp = false;
|
||||
|
||||
Regex InternetShortcutURLPrefixes = new Regex(@"^steam:\/\/(rungameid|run)\/|^com\.epicgames\.launcher:\/\/apps\/");
|
||||
Regex internetShortcutURLPrefixes = new Regex(@"^steam:\/\/(rungameid|run)\/|^com\.epicgames\.launcher:\/\/apps\/");
|
||||
|
||||
const string urlPrefix = "URL=";
|
||||
const string iconFilePrefix = "IconFile=";
|
||||
@@ -367,7 +365,7 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
Uri uri = new Uri(urlPath);
|
||||
|
||||
// To filter out only those steam shortcuts which have 'run' or 'rungameid' as the hostname
|
||||
if (InternetShortcutURLPrefixes.Match(urlPath).Success)
|
||||
if (internetShortcutURLPrefixes.Match(urlPath).Success)
|
||||
{
|
||||
validApp = true;
|
||||
}
|
||||
@@ -429,10 +427,10 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
program.LnkResolvedPath = program.FullPath;
|
||||
program.FullPath = Path.GetFullPath(target).ToLower(CultureInfo.CurrentCulture);
|
||||
program.ExecutableName = Path.GetFileName(target);
|
||||
program.hasArguments = Helper.hasArguments;
|
||||
program.HasArguments = Helper.HasArguments;
|
||||
program.Arguments = Helper.Arguments;
|
||||
|
||||
var description = Helper.description;
|
||||
var description = Helper.Description;
|
||||
if (!string.IsNullOrEmpty(description))
|
||||
{
|
||||
program.Description = description;
|
||||
@@ -588,7 +586,8 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
$"|Win32|ProgramPaths|{currentDirectory}" +
|
||||
$"|Permission denied when trying to load programs from {currentDirectory}", e);
|
||||
}
|
||||
} while (folderQueue.Any());
|
||||
}
|
||||
while (folderQueue.Any());
|
||||
|
||||
return files;
|
||||
}
|
||||
@@ -613,7 +612,7 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
sources.Where(s => Directory.Exists(s.Location) && s.Enabled)
|
||||
.SelectMany(s => ProgramPaths(s.Location, suffixes))
|
||||
.ToList()
|
||||
.Where(t1 => !Main._settings.DisabledProgramSources.Any(x => t1 == x.UniqueIdentifier))
|
||||
.Where(t1 => !Main.Settings.DisabledProgramSources.Any(x => t1 == x.UniqueIdentifier))
|
||||
.ToList()
|
||||
.ForEach(x => listToAdd.Add(x));
|
||||
|
||||
@@ -660,20 +659,24 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
var allPrograms = programs1.Concat(programs2).Where(p => p.Valid)
|
||||
.Concat(programs3).Where(p => p.Valid)
|
||||
.Concat(programs4).Where(p => p.Valid)
|
||||
.Select(p => { p.AppType = (uint)ApplicationTypes.RUN_COMMAND; return p; });
|
||||
.Select(p =>
|
||||
{
|
||||
p.AppType = (uint)ApplicationTypes.RUN_COMMAND;
|
||||
return p;
|
||||
});
|
||||
|
||||
return allPrograms;
|
||||
}
|
||||
|
||||
private static ParallelQuery<Win32Program> IndexPath(IList<string> suffixes, List<string> IndexLocation)
|
||||
private static ParallelQuery<Win32Program> IndexPath(IList<string> suffixes, List<string> indexLocation)
|
||||
{
|
||||
var disabledProgramsList = Main._settings.DisabledProgramSources;
|
||||
var disabledProgramsList = Main.Settings.DisabledProgramSources;
|
||||
|
||||
IEnumerable<string> toFilter = new List<string>();
|
||||
foreach (string location in IndexLocation)
|
||||
foreach (string location in indexLocation)
|
||||
{
|
||||
var _paths = ProgramPaths(location, suffixes);
|
||||
toFilter = toFilter.Concat(_paths);
|
||||
var programPaths = ProgramPaths(location, suffixes);
|
||||
toFilter = toFilter.Concat(programPaths);
|
||||
}
|
||||
|
||||
var paths = toFilter
|
||||
@@ -696,17 +699,17 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
{
|
||||
var directory1 = Environment.GetFolderPath(Environment.SpecialFolder.Programs);
|
||||
var directory2 = Environment.GetFolderPath(Environment.SpecialFolder.CommonPrograms);
|
||||
List<string> IndexLocation = new List<string>() { directory1, directory2 };
|
||||
List<string> indexLocation = new List<string>() { directory1, directory2 };
|
||||
|
||||
return IndexPath(suffixes, IndexLocation);
|
||||
return IndexPath(suffixes, indexLocation);
|
||||
}
|
||||
|
||||
private static ParallelQuery<Win32Program> DesktopPrograms(IList<string> suffixes)
|
||||
{
|
||||
var directory1 = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
|
||||
List<string> IndexLocation = new List<string>() { directory1 };
|
||||
List<string> indexLocation = new List<string>() { directory1 };
|
||||
|
||||
return IndexPath(suffixes, IndexLocation);
|
||||
return IndexPath(suffixes, indexLocation);
|
||||
}
|
||||
|
||||
private static ParallelQuery<Win32Program> AppPathsPrograms(IList<string> suffixes)
|
||||
@@ -730,7 +733,7 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
}
|
||||
}
|
||||
|
||||
var disabledProgramsList = Main._settings.DisabledProgramSources;
|
||||
var disabledProgramsList = Main.Settings.DisabledProgramSources;
|
||||
var toFilter = programs.AsParallel().Where(p => suffixes.Contains(Extension(p.ExecutableName)));
|
||||
|
||||
var filtered = toFilter.Where(t1 => !disabledProgramsList.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier)).Select(t1 => t1);
|
||||
@@ -804,17 +807,15 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
// Overriding the object.GetHashCode() function to aid in removing duplicates while adding and removing apps from the concurrent dictionary storage
|
||||
public override int GetHashCode()
|
||||
{
|
||||
removeDuplicatesComparer _removeDuplicatesHelper = new removeDuplicatesComparer();
|
||||
return _removeDuplicatesHelper.GetHashCode(this);
|
||||
return new RemoveDuplicatesComparer().GetHashCode(this);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
removeDuplicatesComparer _removeDuplicatesHelper = new removeDuplicatesComparer();
|
||||
return obj is Win32Program win && _removeDuplicatesHelper.Equals(this, win);
|
||||
return obj is Win32Program win && new RemoveDuplicatesComparer().Equals(this, win);
|
||||
}
|
||||
|
||||
private class removeDuplicatesComparer : IEqualityComparer<Win32Program>
|
||||
private class RemoveDuplicatesComparer : IEqualityComparer<Win32Program>
|
||||
{
|
||||
public bool Equals(Win32Program app1, Win32Program app2)
|
||||
{
|
||||
@@ -838,9 +839,9 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
int fullPathPrime = 31;
|
||||
|
||||
int result = 1;
|
||||
result = result * namePrime + obj.Name.ToUpperInvariant().GetHashCode(StringComparison.Ordinal);
|
||||
result = result * executablePrime + obj.ExecutableName.ToUpperInvariant().GetHashCode(StringComparison.Ordinal);
|
||||
result = result * fullPathPrime + obj.FullPath.ToUpperInvariant().GetHashCode(StringComparison.Ordinal);
|
||||
result = (result * namePrime) + obj.Name.ToUpperInvariant().GetHashCode(StringComparison.Ordinal);
|
||||
result = (result * executablePrime) + obj.ExecutableName.ToUpperInvariant().GetHashCode(StringComparison.Ordinal);
|
||||
result = (result * fullPathPrime) + obj.FullPath.ToUpperInvariant().GetHashCode(StringComparison.Ordinal);
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -850,7 +851,7 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
public static Win32Program[] DeduplicatePrograms(ParallelQuery<Win32Program> programs)
|
||||
{
|
||||
var uniqueExePrograms = programs.Where(x => !(string.IsNullOrEmpty(x.LnkResolvedPath) && (Extension(x.FullPath) == ExeExtension) && !(x.AppType == (uint)ApplicationTypes.RUN_COMMAND)));
|
||||
var uniquePrograms = uniqueExePrograms.Distinct(new removeDuplicatesComparer());
|
||||
var uniquePrograms = uniqueExePrograms.Distinct(new RemoveDuplicatesComparer());
|
||||
return uniquePrograms.ToArray();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user