mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-01-14 08:16:50 +01:00
lots of baseline adjustments
This commit is contained in:
@@ -30,8 +30,10 @@ public sealed class AllAppsPage : ListPage
|
||||
{
|
||||
PopulateApps();
|
||||
}
|
||||
return [this.allAppsSection];
|
||||
|
||||
return [allAppsSection];
|
||||
}
|
||||
|
||||
private void PopulateApps()
|
||||
{
|
||||
var apps = GetPrograms();
|
||||
@@ -41,13 +43,12 @@ public sealed class AllAppsPage : ListPage
|
||||
Title = "Apps",
|
||||
Items = apps
|
||||
.Select((app) => new AppListItem(app))
|
||||
.ToArray()
|
||||
.ToArray(),
|
||||
};
|
||||
}
|
||||
|
||||
internal static List<AppItem> GetPrograms()
|
||||
{
|
||||
|
||||
// NOTE TO SELF:
|
||||
//
|
||||
// There's logic in Win32Program.All() here to pick the "sources" for programs.
|
||||
@@ -58,7 +59,6 @@ public sealed class AllAppsPage : ListPage
|
||||
// for now. I've disabled the "PATH" source too, because it's n o i s y
|
||||
//
|
||||
// This also doesn't include Packaged apps, cause they're enumerated entirely seperately.
|
||||
|
||||
var cache = AppCache.Instance.Value;
|
||||
var uwps = cache.UWPs;
|
||||
var win32s = cache.Win32s;
|
||||
@@ -69,10 +69,11 @@ public sealed class AllAppsPage : ListPage
|
||||
{
|
||||
Name = app.Name,
|
||||
Subtitle = app.Description,
|
||||
IcoPath = app.LogoType != LogoType.Error ? app.LogoPath : "",
|
||||
//ExePath = app.FullPath,
|
||||
IcoPath = app.LogoType != LogoType.Error ? app.LogoPath : string.Empty,
|
||||
DirPath = app.Location,
|
||||
UserModelId = app.UserModelId,
|
||||
|
||||
// ExePath = app.FullPath,
|
||||
});
|
||||
var win32Results = win32s
|
||||
.Where((application) => application.Enabled /*&& application.Valid*/)
|
||||
@@ -89,15 +90,3 @@ public sealed class AllAppsPage : ListPage
|
||||
return uwpResults.Concat(win32Results).OrderBy(app => app.Name).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
//internal sealed class AppAndScore
|
||||
//{
|
||||
// public AppItem app;
|
||||
// public int score;
|
||||
//}
|
||||
|
||||
//internal sealed class AppSearchState
|
||||
//{
|
||||
// public string Query { get; set; } = "";
|
||||
// public List<AppAndScore> Results { get; set; } = new();
|
||||
//}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
// 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 AllApps.Programs;
|
||||
|
||||
public enum LogoType
|
||||
{
|
||||
Error,
|
||||
Colored,
|
||||
HighContrast,
|
||||
}
|
||||
@@ -0,0 +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.
|
||||
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace AllApps.Programs;
|
||||
|
||||
internal sealed class Native
|
||||
{
|
||||
[DllImport("shlwapi.dll", CharSet = CharSet.Unicode)]
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1838:Avoid 'StringBuilder' parameters for P/Invokes", Justification = "<Pending>")]
|
||||
public static extern int SHLoadIndirectString(string pszSource, StringBuilder pszOutBuf, int cchOutBuf, string ppvReserved);
|
||||
}
|
||||
@@ -2,12 +2,8 @@
|
||||
// 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.Linq;
|
||||
using System.Security.Principal;
|
||||
using Windows.Management.Deployment;
|
||||
// using Wox.Plugin.Logger;
|
||||
using Package = Windows.ApplicationModel.Package;
|
||||
|
||||
namespace AllApps.Programs;
|
||||
@@ -25,12 +21,14 @@ public class PackageManagerWrapper : IPackageManager
|
||||
{
|
||||
var user = WindowsIdentity.GetCurrent().User;
|
||||
|
||||
var pkgs = _packageManager.FindPackagesForUser(user.Value);
|
||||
if (user != null)
|
||||
{
|
||||
var pkgs = _packageManager.FindPackagesForUser(user.Value);
|
||||
|
||||
return user != null
|
||||
? pkgs
|
||||
.Select(TryGetWrapperFromPackage).Where(package => package != null)
|
||||
: Enumerable.Empty<IPackage>();
|
||||
return pkgs.Select(TryGetWrapperFromPackage).Where(package => package != null);
|
||||
}
|
||||
|
||||
return Enumerable.Empty<IPackage>();
|
||||
}
|
||||
|
||||
private static PackageWrapper TryGetWrapperFromPackage(Package package)
|
||||
@@ -46,4 +44,4 @@ public class PackageManagerWrapper : IPackageManager
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,19 +2,10 @@
|
||||
// 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.Abstractions;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
//using System.Runtime.InteropServices;
|
||||
//using System.Runtime.InteropServices.ComTypes;
|
||||
using System.Xml.Linq;
|
||||
using Windows.Win32;
|
||||
using Windows.Win32.System.Com;
|
||||
//using Microsoft.Plugin.Program.Logger;
|
||||
//using Wox.Plugin.Common.Win32;
|
||||
//using Wox.Plugin.Logger;
|
||||
|
||||
namespace AllApps.Programs;
|
||||
|
||||
@@ -59,18 +50,19 @@ public partial class UWP
|
||||
public void InitializeAppInfo(string installedLocation)
|
||||
{
|
||||
Location = installedLocation;
|
||||
LocationLocalized = installedLocation;// Main.ShellLocalizationHelper.GetLocalizedPath(installedLocation);
|
||||
LocationLocalized = installedLocation; // Main.ShellLocalizationHelper.GetLocalizedPath(installedLocation);
|
||||
var path = Path.Combine(installedLocation, "AppxManifest.xml");
|
||||
|
||||
var namespaces = XmlNamespaces(path);
|
||||
InitPackageVersion(namespaces);
|
||||
|
||||
const uint noAttribute = 0x80;
|
||||
//const STGM exclusiveRead = STGM.READ;
|
||||
|
||||
// const STGM exclusiveRead = STGM.READ;
|
||||
uint access = 0; // STGM.READ
|
||||
var hResult = PInvoke.SHCreateStreamOnFileEx(path, access, noAttribute, false, null, out IStream stream);
|
||||
|
||||
if (hResult == 0) //S_OK
|
||||
if (hResult == 0) // S_OK
|
||||
{
|
||||
Apps = AppxPackageHelper.GetAppsFromManifest(stream).Select(appInManifest => new UWPApplication(appInManifest, this)).Where(a =>
|
||||
{
|
||||
@@ -81,17 +73,11 @@ public partial class UWP
|
||||
|
||||
return valid;
|
||||
}).ToList();
|
||||
|
||||
//if (Marshal.ReleaseComObject(stream) > 0)
|
||||
//{
|
||||
// //Log.Error("AppxManifest.xml was leaked", MethodBase.GetCurrentMethod().DeclaringType);
|
||||
//}
|
||||
}
|
||||
else
|
||||
{
|
||||
//var e = Marshal.GetExceptionForHR((int)hResult);
|
||||
//ProgramLogger.Exception("Error caused while trying to get the details of the UWP program", e, GetType(), path);
|
||||
|
||||
// var e = Marshal.GetExceptionForHR((int)hResult);
|
||||
// ProgramLogger.Exception("Error caused while trying to get the details of the UWP program", e, GetType(), path);
|
||||
Apps = Array.Empty<UWPApplication>();
|
||||
}
|
||||
}
|
||||
@@ -112,8 +98,7 @@ public partial class UWP
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Error($"Error occurred while trying to get the XML from {path}", MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
// Log.Error($"Error occurred while trying to get the XML from {path}", MethodBase.GetCurrentMethod().DeclaringType);
|
||||
return Array.Empty<string>();
|
||||
}
|
||||
}
|
||||
@@ -126,8 +111,7 @@ public partial class UWP
|
||||
return;
|
||||
}
|
||||
|
||||
//ProgramLogger.Exception($"|Trying to get the package version of the UWP program, but a unknown UWP appmanifest version {FullName} from location {Location} is returned.", new FormatException(), GetType(), Location);
|
||||
|
||||
// ProgramLogger.Exception($"|Trying to get the package version of the UWP program, but a unknown UWP appmanifest version {FullName} from location {Location} is returned.", new FormatException(), GetType(), Location);
|
||||
Version = PackageVersion.Unknown;
|
||||
}
|
||||
|
||||
@@ -147,17 +131,14 @@ public partial class UWP
|
||||
}
|
||||
catch (Exception )
|
||||
{
|
||||
//ProgramLogger.Exception($"Unable to convert Package to UWP for {p.FullName}", e, MethodBase.GetCurrentMethod().DeclaringType, p.InstalledLocation);
|
||||
|
||||
// ProgramLogger.Exception($"Unable to convert Package to UWP for {p.FullName}", e, MethodBase.GetCurrentMethod().DeclaringType, p.InstalledLocation);
|
||||
return Array.Empty<UWPApplication>();
|
||||
}
|
||||
|
||||
return u.Apps;
|
||||
});
|
||||
|
||||
var updatedListWithoutDisabledApps = applications
|
||||
//.Where(t1 => Main.Settings.DisabledProgramSources.All(x => x.UniqueIdentifier != t1.UniqueIdentifier))
|
||||
.Select(x => x);
|
||||
var updatedListWithoutDisabledApps = applications.Select(x => x);
|
||||
|
||||
return updatedListWithoutDisabledApps.ToArray();
|
||||
}
|
||||
@@ -179,7 +160,7 @@ public partial class UWP
|
||||
}
|
||||
catch (Exception )
|
||||
{
|
||||
//ProgramLogger.Exception("An unexpected error occurred and unable to verify if package is valid", e, MethodBase.GetCurrentMethod().DeclaringType, "id");
|
||||
// ProgramLogger.Exception("An unexpected error occurred and unable to verify if package is valid", e, MethodBase.GetCurrentMethod().DeclaringType, "id");
|
||||
return false;
|
||||
}
|
||||
});
|
||||
@@ -217,4 +198,4 @@ public partial class UWP
|
||||
Windows8,
|
||||
Unknown,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,36 +2,14 @@
|
||||
// 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.IO.Abstractions;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Xml;
|
||||
using Windows.ApplicationModel.Contacts;
|
||||
using Windows.Win32;
|
||||
|
||||
using PackageVersion = AllApps.Programs.UWP.PackageVersion;
|
||||
|
||||
namespace AllApps.Programs;
|
||||
|
||||
internal sealed class Native
|
||||
{
|
||||
|
||||
[DllImport("shlwapi.dll", CharSet = CharSet.Unicode)]
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1838:Avoid 'StringBuilder' parameters for P/Invokes", Justification = "<Pending>")]
|
||||
public static extern int SHLoadIndirectString(string pszSource, StringBuilder pszOutBuf, int cchOutBuf, string ppvReserved);
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class UWPApplication : IProgram
|
||||
{
|
||||
@@ -76,153 +54,12 @@ public class UWPApplication : IProgram
|
||||
|
||||
private const string ContrastBlack = "contrast-black";
|
||||
|
||||
// Function to calculate the score of a result
|
||||
//private int Score(string query)
|
||||
//{
|
||||
// var displayNameMatch = StringMatcher.FuzzySearch(query, DisplayName);
|
||||
// var descriptionMatch = StringMatcher.FuzzySearch(query, Description);
|
||||
// var score = new[] { displayNameMatch.Score, descriptionMatch.Score / 2 }.Max();
|
||||
// return score;
|
||||
//}
|
||||
|
||||
// Function to set the subtitle based on the Type of application
|
||||
private static string SetSubtitle()
|
||||
{
|
||||
return "";// Properties.Resources.powertoys_run_plugin_program_packaged_application;
|
||||
return string.Empty; // Properties.Resources.powertoys_run_plugin_program_packaged_application;
|
||||
}
|
||||
|
||||
//public Result Result(string query, string queryArguments, IPublicAPI api)
|
||||
//{
|
||||
// ArgumentNullException.ThrowIfNull(api);
|
||||
|
||||
// var score = Score(query);
|
||||
// if (score <= 0)
|
||||
// { // no need to create result if score is 0
|
||||
// return null;
|
||||
// }
|
||||
|
||||
// var result = new Result
|
||||
// {
|
||||
// SubTitle = SetSubtitle(),
|
||||
// Icon = Logo,
|
||||
// Score = score,
|
||||
// ContextData = this,
|
||||
// ProgramArguments = queryArguments,
|
||||
// Action = e =>
|
||||
// {
|
||||
// Launch(api, queryArguments);
|
||||
// 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;
|
||||
|
||||
// // Using CurrentCulture since this is user facing
|
||||
// var toolTipTitle = result.Title;
|
||||
// var toolTipText = LocationLocalized;
|
||||
// result.ToolTipData = new ToolTipData(toolTipTitle, toolTipText);
|
||||
|
||||
// return result;
|
||||
//}
|
||||
|
||||
//public List<ContextMenuResult> ContextMenus(string queryArguments, IPublicAPI api)
|
||||
//{
|
||||
// ArgumentNullException.ThrowIfNull(api);
|
||||
|
||||
// var contextMenus = new List<ContextMenuResult>();
|
||||
|
||||
// if (CanRunElevated)
|
||||
// {
|
||||
// contextMenus.Add(
|
||||
// new ContextMenuResult
|
||||
// {
|
||||
// PluginName = Assembly.GetExecutingAssembly().GetName().Name,
|
||||
// Title = Properties.Resources.wox_plugin_program_run_as_administrator,
|
||||
// Glyph = "\xE7EF",
|
||||
// FontFamily = "Segoe Fluent Icons,Segoe MDL2 Assets",
|
||||
// AcceleratorKey = Key.Enter,
|
||||
// AcceleratorModifiers = ModifierKeys.Control | ModifierKeys.Shift,
|
||||
// Action = _ =>
|
||||
// {
|
||||
// string command = "shell:AppsFolder\\" + UniqueIdentifier;
|
||||
// command = Environment.ExpandEnvironmentVariables(command.Trim());
|
||||
|
||||
// var info = ShellCommand.SetProcessStartInfo(command, verb: "runas");
|
||||
// info.UseShellExecute = true;
|
||||
// info.Arguments = queryArguments;
|
||||
// Process.Start(info);
|
||||
// return true;
|
||||
// },
|
||||
// });
|
||||
|
||||
// // We don't add context menu to 'run as different user', because UWP applications normally installed per user and not for all users.
|
||||
// }
|
||||
|
||||
// contextMenus.Add(
|
||||
// new ContextMenuResult
|
||||
// {
|
||||
// PluginName = Assembly.GetExecutingAssembly().GetName().Name,
|
||||
// Title = Properties.Resources.wox_plugin_program_open_containing_folder,
|
||||
// Glyph = "\xE838",
|
||||
// FontFamily = "Segoe Fluent Icons,Segoe MDL2 Assets",
|
||||
// AcceleratorKey = Key.E,
|
||||
// AcceleratorModifiers = ModifierKeys.Control | ModifierKeys.Shift,
|
||||
// Action = _ =>
|
||||
// {
|
||||
// Helper.OpenInShell(Package.Location);
|
||||
|
||||
// return true;
|
||||
// },
|
||||
// });
|
||||
|
||||
// contextMenus.Add(new ContextMenuResult
|
||||
// {
|
||||
// PluginName = Assembly.GetExecutingAssembly().GetName().Name,
|
||||
// Title = Properties.Resources.wox_plugin_program_open_in_console,
|
||||
// Glyph = "\xE756",
|
||||
// FontFamily = "Segoe Fluent Icons,Segoe MDL2 Assets",
|
||||
// AcceleratorKey = Key.C,
|
||||
// AcceleratorModifiers = ModifierKeys.Control | ModifierKeys.Shift,
|
||||
// Action = (context) =>
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// Helper.OpenInConsole(Package.Location);
|
||||
// return true;
|
||||
// }
|
||||
// catch (Exception e)
|
||||
// {
|
||||
// Log.Exception($"Failed to open {Name} in console, {e.Message}", e, GetType());
|
||||
// return false;
|
||||
// }
|
||||
// },
|
||||
// });
|
||||
|
||||
// return contextMenus;
|
||||
//}
|
||||
|
||||
//private async void Launch(/*IPublicAPI api, */string queryArguments)
|
||||
//{
|
||||
// var appManager = new ApplicationActivationManager();
|
||||
// const ActivateOptions noFlags = ActivateOptions.None;
|
||||
// await Task.Run(() =>
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// appManager.ActivateApplication(UserModelId, queryArguments, noFlags, out var unusedPid);
|
||||
// }
|
||||
// catch (Exception)
|
||||
// {
|
||||
// //ProgramLogger.Exception($"Unable to launch UWP {DisplayName}", ex, MethodBase.GetCurrentMethod().DeclaringType, queryArguments);
|
||||
// //var name = "Plugin: " + Properties.Resources.wox_plugin_program_plugin_name;
|
||||
// //var message = $"{Properties.Resources.powertoys_run_plugin_program_uwp_failed}: {DisplayName}";
|
||||
// //api.ShowMsg(name, message, string.Empty);
|
||||
// }
|
||||
// }).ConfigureAwait(false);
|
||||
//}
|
||||
|
||||
public UWPApplication(IAppxManifestApplication manifestApp, UWP package)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(manifestApp);
|
||||
@@ -251,6 +88,7 @@ public class UWPApplication : IProgram
|
||||
Description = ResourceFromPri(package.FullName, Description);
|
||||
logoUri = LogoUriFromManifest(manifestApp);
|
||||
UpdateLogoPath();
|
||||
|
||||
// logoUri = "";
|
||||
Enabled = true;
|
||||
CanRunElevated = IfApplicationcanRunElevated();
|
||||
@@ -293,10 +131,8 @@ public class UWPApplication : IProgram
|
||||
return false;
|
||||
}
|
||||
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "<Pending>")]
|
||||
internal string ResourceFromPri(string packageFullName, string resourceReference)
|
||||
{
|
||||
//return "";
|
||||
const string prefix = "ms-resource:";
|
||||
|
||||
// Using OrdinalIgnoreCase since this is used internally
|
||||
@@ -330,8 +166,7 @@ public class UWPApplication : IProgram
|
||||
}
|
||||
|
||||
var outBuffer = new StringBuilder(128);
|
||||
//var outBox = " ";
|
||||
|
||||
|
||||
var source = $"@{{{packageFullName}? {parsed}}}";
|
||||
var hResult = Native.SHLoadIndirectString(source, outBuffer, outBuffer.Capacity, null);
|
||||
if (hResult != 0)
|
||||
@@ -349,12 +184,10 @@ public class UWPApplication : IProgram
|
||||
}
|
||||
else
|
||||
{
|
||||
//ProgramLogger.Exception($"Can't load null or empty result pri {sourceFallback} in uwp location {Package.Location}", new ArgumentNullException(null), GetType(), Package.Location);
|
||||
|
||||
// ProgramLogger.Exception($"Can't load null or empty result pri {sourceFallback} in uwp location {Package.Location}", new ArgumentNullException(null), GetType(), Package.Location);
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// https://github.com/Wox-launcher/Wox/issues/964
|
||||
@@ -363,9 +196,9 @@ public class UWPApplication : IProgram
|
||||
// for
|
||||
// Microsoft.MicrosoftOfficeHub_17.7608.23501.0_x64__8wekyb3d8bbwe: ms-resource://Microsoft.MicrosoftOfficeHub/officehubintl/AppManifest_GetOffice_Description
|
||||
// Microsoft.BingFoodAndDrink_3.0.4.336_x64__8wekyb3d8bbwe: ms-resource:AppDescription
|
||||
var e = Marshal.GetExceptionForHR((int)hResult);
|
||||
//ProgramLogger.Exception($"Load pri failed {source} with HResult {hResult} and location {Package.Location}", e, GetType(), Package.Location);
|
||||
|
||||
// var e = Marshal.GetExceptionForHR((int)hResult);
|
||||
// ProgramLogger.Exception($"Load pri failed {source} with HResult {hResult} and location {Package.Location}", e, GetType(), Package.Location);
|
||||
return string.Empty;
|
||||
}
|
||||
else
|
||||
@@ -377,12 +210,10 @@ public class UWPApplication : IProgram
|
||||
}
|
||||
else
|
||||
{
|
||||
//ProgramLogger.Exception($"Can't load null or empty result pri {source} in uwp location {Package.Location}", new ArgumentNullException(null), GetType(), Package.Location);
|
||||
|
||||
// ProgramLogger.Exception($"Can't load null or empty result pri {source} in uwp location {Package.Location}", new ArgumentNullException(null), GetType(), Package.Location);
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -390,7 +221,7 @@ public class UWPApplication : IProgram
|
||||
}
|
||||
}
|
||||
|
||||
private static readonly Dictionary<PackageVersion, string> _logoKeyFromVersion = new Dictionary<PackageVersion, string>
|
||||
private static readonly Dictionary<PackageVersion, string> _logoKeyFromVersion = new()
|
||||
{
|
||||
{ PackageVersion.Windows10, "Square44x44Logo" },
|
||||
{ PackageVersion.Windows81, "Square30x30Logo" },
|
||||
@@ -438,7 +269,7 @@ public class UWPApplication : IProgram
|
||||
paths.Add(path);
|
||||
}
|
||||
|
||||
if (_scaleFactors.TryGetValue(Package.Version, out List<int> factors))
|
||||
if (_scaleFactors.TryGetValue(Package.Version, out var factors))
|
||||
{
|
||||
foreach (var factor in factors)
|
||||
{
|
||||
@@ -490,8 +321,9 @@ public class UWPApplication : IProgram
|
||||
{
|
||||
if (highContrast)
|
||||
{
|
||||
string suffixThemePath = $"{prefix}.targetsize-{factor}_{colorscheme}{extension}";
|
||||
string prefixThemePath = $"{prefix}.{colorscheme}_targetsize-{factor}{extension}";
|
||||
var suffixThemePath = $"{prefix}.targetsize-{factor}_{colorscheme}{extension}";
|
||||
var prefixThemePath = $"{prefix}.{colorscheme}_targetsize-{factor}{extension}";
|
||||
|
||||
paths.Add(suffixThemePath);
|
||||
paths.Add(prefixThemePath);
|
||||
pathFactorPairs.Add(suffixThemePath, factor);
|
||||
@@ -499,8 +331,9 @@ public class UWPApplication : IProgram
|
||||
}
|
||||
else
|
||||
{
|
||||
string simplePath = $"{prefix}.targetsize-{factor}{extension}";
|
||||
string altformUnPlatedPath = $"{prefix}.targetsize-{factor}_altform-unplated{extension}";
|
||||
var simplePath = $"{prefix}.targetsize-{factor}{extension}";
|
||||
var altformUnPlatedPath = $"{prefix}.targetsize-{factor}_altform-unplated{extension}";
|
||||
|
||||
paths.Add(simplePath);
|
||||
paths.Add(altformUnPlatedPath);
|
||||
pathFactorPairs.Add(simplePath, factor);
|
||||
@@ -606,151 +439,21 @@ public class UWPApplication : IProgram
|
||||
path = Path.Combine(Package.Location, "Assets", uri);
|
||||
}
|
||||
|
||||
//switch (theme)
|
||||
//{
|
||||
// case Theme.HighContrastBlack:
|
||||
// case Theme.HighContrastOne:
|
||||
// case Theme.HighContrastTwo:
|
||||
// isLogoUriSet = SetHighContrastIcon(path, ContrastBlack);
|
||||
// break;
|
||||
// case Theme.HighContrastWhite:
|
||||
// isLogoUriSet = SetHighContrastIcon(path, ContrastWhite);
|
||||
// break;
|
||||
// case Theme.Light:
|
||||
// isLogoUriSet = SetColoredIcon(path, ContrastWhite);
|
||||
// break;
|
||||
// default:
|
||||
// isLogoUriSet = SetColoredIcon(path, ContrastBlack);
|
||||
// break;
|
||||
//}
|
||||
isLogoUriSet = SetColoredIcon(path, ContrastBlack) || SetColoredIcon(path, ContrastWhite);
|
||||
|
||||
if (!isLogoUriSet)
|
||||
{
|
||||
LogoPath = string.Empty;
|
||||
LogoType = LogoType.Error;
|
||||
//ProgramLogger.Exception($"|{UserModelId} can't find logo uri for {uri} in package location: {Package.Location}", new FileNotFoundException(), GetType(), Package.Location);
|
||||
|
||||
// ProgramLogger.Exception($"|{UserModelId} can't find logo uri for {uri} in package location: {Package.Location}", new FileNotFoundException(), GetType(), Package.Location);
|
||||
}
|
||||
//LogoPath = path;
|
||||
}
|
||||
|
||||
//public ImageSource Logo()
|
||||
//{
|
||||
// if (LogoType == LogoType.Colored)
|
||||
// {
|
||||
// var logo = ImageFromPath(LogoPath);
|
||||
// var platedImage = PlatedImage(logo);
|
||||
// return platedImage;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// return ImageFromPath(LogoPath);
|
||||
// }
|
||||
//}
|
||||
|
||||
private const int _dpiScale100 = 96;
|
||||
|
||||
//private ImageSource PlatedImage(BitmapImage image)
|
||||
//{
|
||||
// if (!string.IsNullOrEmpty(BackgroundColor))
|
||||
// {
|
||||
// string currentBackgroundColor;
|
||||
// if (BackgroundColor == "transparent")
|
||||
// {
|
||||
// // Using InvariantCulture since this is internal
|
||||
// currentBackgroundColor = SystemParameters.WindowGlassBrush.ToString(CultureInfo.InvariantCulture);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// currentBackgroundColor = BackgroundColor;
|
||||
// }
|
||||
|
||||
// var padding = 8;
|
||||
// var width = image.Width + (2 * padding);
|
||||
// var height = image.Height + (2 * padding);
|
||||
// var x = 0;
|
||||
// var y = 0;
|
||||
|
||||
// var group = new DrawingGroup();
|
||||
// var converted = ColorConverter.ConvertFromString(currentBackgroundColor);
|
||||
// if (converted != null)
|
||||
// {
|
||||
// var color = (Color)converted;
|
||||
// var brush = new SolidColorBrush(color);
|
||||
// var pen = new Pen(brush, 1);
|
||||
// var backgroundArea = new Rect(0, 0, width, height);
|
||||
// var rectangleGeometry = new RectangleGeometry(backgroundArea, 8, 8);
|
||||
// var rectDrawing = new GeometryDrawing(brush, pen, rectangleGeometry);
|
||||
// group.Children.Add(rectDrawing);
|
||||
|
||||
// var imageArea = new Rect(x + padding, y + padding, image.Width, image.Height);
|
||||
// var imageDrawing = new ImageDrawing(image, imageArea);
|
||||
// group.Children.Add(imageDrawing);
|
||||
|
||||
// // http://stackoverflow.com/questions/6676072/get-system-drawing-bitmap-of-a-wpf-area-using-visualbrush
|
||||
// var visual = new DrawingVisual();
|
||||
// var context = visual.RenderOpen();
|
||||
// context.DrawDrawing(group);
|
||||
// context.Close();
|
||||
|
||||
// var bitmap = new RenderTargetBitmap(
|
||||
// Convert.ToInt32(width),
|
||||
// Convert.ToInt32(height),
|
||||
// _dpiScale100,
|
||||
// _dpiScale100,
|
||||
// PixelFormats.Pbgra32);
|
||||
|
||||
// bitmap.Render(visual);
|
||||
|
||||
// return bitmap;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// ProgramLogger.Exception($"Unable to convert background string {BackgroundColor} to color for {Package.Location}", new InvalidOperationException(), GetType(), Package.Location);
|
||||
|
||||
// return new BitmapImage(new Uri(Constant.ErrorIcon));
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// // todo use windows theme as background
|
||||
// return image;
|
||||
// }
|
||||
//}
|
||||
|
||||
//private BitmapImage ImageFromPath(string path)
|
||||
//{
|
||||
// if (File.Exists(path))
|
||||
// {
|
||||
// var memoryStream = new MemoryStream();
|
||||
// using (var fileStream = File.OpenRead(path))
|
||||
// {
|
||||
// fileStream.CopyTo(memoryStream);
|
||||
// memoryStream.Position = 0;
|
||||
|
||||
// var image = new BitmapImage();
|
||||
// image.BeginInit();
|
||||
// image.StreamSource = memoryStream;
|
||||
// image.EndInit();
|
||||
// return image;
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// ProgramLogger.Exception($"Unable to get logo for {UserModelId} from {path} and located in {Package.Location}", new FileNotFoundException(), GetType(), path);
|
||||
// return new BitmapImage(new Uri(ImageLoader.ErrorIconPath));
|
||||
// }
|
||||
//}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{DisplayName}: {Description}";
|
||||
}
|
||||
}
|
||||
|
||||
public enum LogoType
|
||||
{
|
||||
Error,
|
||||
Colored,
|
||||
HighContrast,
|
||||
}
|
||||
@@ -4,25 +4,19 @@
|
||||
|
||||
using System.Diagnostics;
|
||||
using System.Security;
|
||||
// using Microsoft.Plugin.Program.Logger;
|
||||
// using Microsoft.Plugin.Program.Utils;
|
||||
using Microsoft.Win32;
|
||||
using WindowsCommandPalette.BuiltinCommands.AllApps;
|
||||
// using Wox.Plugin;
|
||||
// using Wox.Plugin.Logger;
|
||||
// using DirectoryWrapper = Wox.Infrastructure.FileSystemHelper.DirectoryWrapper;
|
||||
|
||||
namespace AllApps.Programs;
|
||||
|
||||
[Serializable]
|
||||
public class Win32Program // : IProgram
|
||||
{
|
||||
public static readonly Win32Program InvalidProgram = new(){ Valid = false, Enabled = false };
|
||||
|
||||
// private static readonly IFileSystem FileSystem = new FileSystem();
|
||||
//private static readonly IPath Path = FileSystem.Path;
|
||||
//private static readonly IFile File = FileSystem.File;
|
||||
//private static readonly IDirectory Directory = FileSystem.Directory;
|
||||
public static readonly Win32Program InvalidProgram = new()
|
||||
{
|
||||
Valid = false,
|
||||
Enabled = false,
|
||||
};
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
@@ -71,12 +65,8 @@ public class Win32Program // : IProgram
|
||||
// Wrappers for File Operations
|
||||
public static IFileVersionInfoWrapper FileVersionInfoWrapper { get; set; } = new FileVersionInfoWrapper();
|
||||
|
||||
//public static IFile FileWrapper { get; set; } = new FileSystem().File;
|
||||
|
||||
public static IShellLinkHelper ShellLinkHelper { get; set; } = new ShellLinkHelper();
|
||||
|
||||
//public static IDirectoryWrapper DirectoryWrapper { get; set; } = new DirectoryWrapper();
|
||||
|
||||
private const string ShortcutExtension = "lnk";
|
||||
private const string ApplicationReferenceExtension = "appref-ms";
|
||||
private const string InternetShortcutExtension = "url";
|
||||
@@ -100,16 +90,6 @@ public class Win32Program // : IProgram
|
||||
// Function to calculate the score of a result
|
||||
private int Score(string query)
|
||||
{
|
||||
//var nameMatch = StringMatcher.FuzzySearch(query, Name);
|
||||
//var locNameMatch = StringMatcher.FuzzySearch(query, NameLocalized);
|
||||
//var descriptionMatch = StringMatcher.FuzzySearch(query, Description);
|
||||
//var executableNameMatch = StringMatcher.FuzzySearch(query, ExecutableName);
|
||||
//var locExecutableNameMatch = StringMatcher.FuzzySearch(query, ExecutableNameLocalized);
|
||||
//var lnkResolvedExecutableNameMatch = StringMatcher.FuzzySearch(query, LnkResolvedExecutableName);
|
||||
//var locLnkResolvedExecutableNameMatch = StringMatcher.FuzzySearch(query, LnkResolvedExecutableNameLocalized);
|
||||
//var score = new[] { nameMatch.Score, locNameMatch.Score, descriptionMatch.Score / 2, executableNameMatch.Score, locExecutableNameMatch.Score, lnkResolvedExecutableNameMatch.Score, locLnkResolvedExecutableNameMatch.Score }.Max();
|
||||
//return score;
|
||||
|
||||
return query.Length + Name.Length;
|
||||
}
|
||||
|
||||
@@ -161,20 +141,6 @@ public class Win32Program // : IProgram
|
||||
{
|
||||
switch (AppType)
|
||||
{
|
||||
//case ApplicationType.Win32Application:
|
||||
//case ApplicationType.ShortcutApplication:
|
||||
//case ApplicationType.ApprefApplication:
|
||||
// return Properties.Resources.powertoys_run_plugin_program_win32_application;
|
||||
//case ApplicationType.InternetShortcutApplication:
|
||||
// return Properties.Resources.powertoys_run_plugin_program_internet_shortcut_application;
|
||||
//case ApplicationType.WebApplication:
|
||||
// return Properties.Resources.powertoys_run_plugin_program_web_application;
|
||||
//case ApplicationType.RunCommand:
|
||||
// return Properties.Resources.powertoys_run_plugin_program_run_command;
|
||||
//case ApplicationType.Folder:
|
||||
// return Properties.Resources.powertoys_run_plugin_program_folder_type;
|
||||
//case ApplicationType.GenericFile:
|
||||
// return Properties.Resources.powertoys_run_plugin_program_generic_file_type;
|
||||
default:
|
||||
return string.Empty;
|
||||
}
|
||||
@@ -194,158 +160,6 @@ public class Win32Program // : IProgram
|
||||
return true;
|
||||
}
|
||||
|
||||
//public Result Result(string query, string queryArguments, IPublicAPI api)
|
||||
//{
|
||||
// ArgumentNullException.ThrowIfNull(api);
|
||||
|
||||
// var score = Score(query);
|
||||
// if (score <= 0)
|
||||
// { // no need to create result if this is zero
|
||||
// return null;
|
||||
// }
|
||||
|
||||
// if (!HasArguments)
|
||||
// {
|
||||
// var noArgumentScoreModifier = 5;
|
||||
// score += noArgumentScoreModifier;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// // Filter Web Applications when searching for the main application
|
||||
// if (FilterWebApplication(query))
|
||||
// {
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
|
||||
// // NOTE: This is to display run commands only when there is an exact match, like in start menu
|
||||
// if (!QueryEqualsNameForRunCommands(query))
|
||||
// {
|
||||
// return null;
|
||||
// }
|
||||
|
||||
// var result = new Result
|
||||
// {
|
||||
// // To set the title for the result to always be the name of the application
|
||||
// Title = !string.IsNullOrEmpty(NameLocalized) ? NameLocalized : Name,
|
||||
// SubTitle = GetSubtitle(),
|
||||
// IcoPath = IcoPath,
|
||||
// Score = score,
|
||||
// ContextData = this,
|
||||
// ProgramArguments = queryArguments,
|
||||
// Action = e =>
|
||||
// {
|
||||
// var info = GetProcessStartInfo(queryArguments);
|
||||
|
||||
// Main.StartProcess(Process.Start, info);
|
||||
|
||||
// return true;
|
||||
// },
|
||||
// };
|
||||
|
||||
// // Adjust title of RunCommand result
|
||||
// if (AppType == ApplicationType.RunCommand)
|
||||
// {
|
||||
// result.Title = ExecutableName;
|
||||
// }
|
||||
|
||||
// result.TitleHighlightData = StringMatcher.FuzzySearch(query, result.Title).MatchData;
|
||||
|
||||
// // Using CurrentCulture since this is user facing
|
||||
// var toolTipTitle = result.Title;
|
||||
// string filePath = !string.IsNullOrEmpty(FullPathLocalized) ? FullPathLocalized : FullPath;
|
||||
// var toolTipText = filePath;
|
||||
// result.ToolTipData = new ToolTipData(toolTipTitle, toolTipText);
|
||||
|
||||
// return result;
|
||||
//}
|
||||
|
||||
//public List<ContextMenuResult> ContextMenus(string queryArguments, IPublicAPI api)
|
||||
//{
|
||||
// ArgumentNullException.ThrowIfNull(api);
|
||||
|
||||
// var contextMenus = new List<ContextMenuResult>();
|
||||
|
||||
// if (AppType != ApplicationType.InternetShortcutApplication && AppType != ApplicationType.Folder && AppType != ApplicationType.GenericFile)
|
||||
// {
|
||||
// contextMenus.Add(new ContextMenuResult
|
||||
// {
|
||||
// PluginName = Assembly.GetExecutingAssembly().GetName().Name,
|
||||
// Title = Properties.Resources.wox_plugin_program_run_as_administrator,
|
||||
// Glyph = "\xE7EF",
|
||||
// FontFamily = "Segoe Fluent Icons,Segoe MDL2 Assets",
|
||||
// AcceleratorKey = Key.Enter,
|
||||
// AcceleratorModifiers = ModifierKeys.Control | ModifierKeys.Shift,
|
||||
// Action = _ =>
|
||||
// {
|
||||
// var info = GetProcessStartInfo(queryArguments, RunAsType.Administrator);
|
||||
// Task.Run(() => Main.StartProcess(Process.Start, info));
|
||||
|
||||
// return true;
|
||||
// },
|
||||
// });
|
||||
|
||||
// contextMenus.Add(new ContextMenuResult
|
||||
// {
|
||||
// PluginName = Assembly.GetExecutingAssembly().GetName().Name,
|
||||
// Title = Properties.Resources.wox_plugin_program_run_as_user,
|
||||
// Glyph = "\xE7EE",
|
||||
// FontFamily = "Segoe Fluent Icons,Segoe MDL2 Assets",
|
||||
// AcceleratorKey = Key.U,
|
||||
// AcceleratorModifiers = ModifierKeys.Control | ModifierKeys.Shift,
|
||||
// Action = _ =>
|
||||
// {
|
||||
// var info = GetProcessStartInfo(queryArguments, RunAsType.OtherUser);
|
||||
// Task.Run(() => Main.StartProcess(Process.Start, info));
|
||||
|
||||
// return true;
|
||||
// },
|
||||
// });
|
||||
// }
|
||||
|
||||
// contextMenus.Add(
|
||||
// new ContextMenuResult
|
||||
// {
|
||||
// PluginName = Assembly.GetExecutingAssembly().GetName().Name,
|
||||
// Title = Properties.Resources.wox_plugin_program_open_containing_folder,
|
||||
// Glyph = "\xE838",
|
||||
// FontFamily = "Segoe Fluent Icons,Segoe MDL2 Assets",
|
||||
// AcceleratorKey = Key.E,
|
||||
// AcceleratorModifiers = ModifierKeys.Control | ModifierKeys.Shift,
|
||||
// Action = _ =>
|
||||
// {
|
||||
// Helper.OpenInShell(ParentDirectory);
|
||||
// return true;
|
||||
// },
|
||||
// });
|
||||
|
||||
// contextMenus.Add(
|
||||
// new ContextMenuResult
|
||||
// {
|
||||
// PluginName = Assembly.GetExecutingAssembly().GetName().Name,
|
||||
// Title = Properties.Resources.wox_plugin_program_open_in_console,
|
||||
// Glyph = "\xE756",
|
||||
// FontFamily = "Segoe Fluent Icons,Segoe MDL2 Assets",
|
||||
// AcceleratorKey = Key.C,
|
||||
// AcceleratorModifiers = ModifierKeys.Control | ModifierKeys.Shift,
|
||||
// Action = (context) =>
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// Helper.OpenInConsole(ParentDirectory);
|
||||
// return true;
|
||||
// }
|
||||
// catch (Exception e)
|
||||
// {
|
||||
// Log.Exception($"|Failed to open {Name} in console, {e.Message}", e, GetType());
|
||||
// return false;
|
||||
// }
|
||||
// },
|
||||
// });
|
||||
|
||||
// return contextMenus;
|
||||
//}
|
||||
|
||||
private ProcessStartInfo GetProcessStartInfo(string programArguments, RunAsType runAs = RunAsType.None)
|
||||
{
|
||||
return new ProcessStartInfo
|
||||
@@ -392,109 +206,29 @@ public class Win32Program // : IProgram
|
||||
// Localized name, path and executable based on windows display language
|
||||
NameLocalized = Path.GetFileNameWithoutExtension(path), // Main.ShellLocalizationHelper.GetLocalizedName(path),
|
||||
FullPathLocalized = path, // Main.ShellLocalizationHelper.GetLocalizedPath(path),
|
||||
ExecutableNameLocalized = Path.GetFileName(path),// Path.GetFileName(Main.ShellLocalizationHelper.GetLocalizedPath(path)),
|
||||
ExecutableNameLocalized = Path.GetFileName(path), // Path.GetFileName(Main.ShellLocalizationHelper.GetLocalizedPath(path)),
|
||||
};
|
||||
}
|
||||
catch (Exception e) when (e is SecurityException || e is UnauthorizedAccessException)
|
||||
{
|
||||
//ProgramLogger.Warn($"|Permission denied when trying to load the program from {path}", e, MethodBase.GetCurrentMethod().DeclaringType, path);
|
||||
|
||||
// ProgramLogger.Warn($"|Permission denied when trying to load the program from {path}", e, MethodBase.GetCurrentMethod().DeclaringType, path);
|
||||
return InvalidProgram;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//ProgramLogger.Exception($"|An unexpected error occurred in the calling method CreateWin32Program at {path}", e, MethodBase.GetCurrentMethod().DeclaringType, path);
|
||||
|
||||
// ProgramLogger.Exception($"|An unexpected error occurred in the calling method CreateWin32Program at {path}", e, MethodBase.GetCurrentMethod().DeclaringType, path);
|
||||
return InvalidProgram;
|
||||
}
|
||||
}
|
||||
|
||||
//private static readonly Regex InternetShortcutURLPrefixes = new Regex(@"^steam:\/\/(rungameid|run|open)\/|^com\.epicgames\.launcher:\/\/apps\/", RegexOptions.Compiled);
|
||||
|
||||
// This function filters Internet Shortcut programs
|
||||
private static Win32Program InternetShortcutProgram(string path)
|
||||
{
|
||||
return InvalidProgram;
|
||||
// try
|
||||
// {
|
||||
// // We don't want to read the whole file if we don't need to
|
||||
// var lines = FileWrapper.ReadLines(path);
|
||||
// string iconPath = string.Empty;
|
||||
// string urlPath = string.Empty;
|
||||
// bool validApp = false;
|
||||
|
||||
// const string urlPrefix = "URL=";
|
||||
// const string iconFilePrefix = "IconFile=";
|
||||
|
||||
// foreach (string line in lines)
|
||||
// {
|
||||
// // Using OrdinalIgnoreCase since this is used internally
|
||||
// if (line.StartsWith(urlPrefix, StringComparison.OrdinalIgnoreCase))
|
||||
// {
|
||||
// urlPath = line.Substring(urlPrefix.Length);
|
||||
|
||||
// if (!Uri.TryCreate(urlPath, UriKind.RelativeOrAbsolute, out Uri _))
|
||||
// {
|
||||
// ProgramLogger.Warn("url could not be parsed", null, MethodBase.GetCurrentMethod().DeclaringType, urlPath);
|
||||
// return InvalidProgram;
|
||||
// }
|
||||
|
||||
// // To filter out only those steam shortcuts which have 'run' or 'rungameid' as the hostname
|
||||
// if (InternetShortcutURLPrefixes.Match(urlPath).Success)
|
||||
// {
|
||||
// validApp = true;
|
||||
// }
|
||||
// }
|
||||
// else if (line.StartsWith(iconFilePrefix, StringComparison.OrdinalIgnoreCase))
|
||||
// {
|
||||
// iconPath = line.Substring(iconFilePrefix.Length);
|
||||
// }
|
||||
|
||||
// // If we resolved an urlPath & and an iconPath quit reading the file
|
||||
// if (!string.IsNullOrEmpty(urlPath) && !string.IsNullOrEmpty(iconPath))
|
||||
// {
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
|
||||
// if (!validApp)
|
||||
// {
|
||||
// return InvalidProgram;
|
||||
// }
|
||||
|
||||
// try
|
||||
// {
|
||||
// return new Win32Program
|
||||
// {
|
||||
// Name = Path.GetFileNameWithoutExtension(path),
|
||||
// ExecutableName = Path.GetFileName(path),
|
||||
// IcoPath = iconPath,
|
||||
// FullPath = urlPath,
|
||||
// UniqueIdentifier = path,
|
||||
// ParentDirectory = Directory.GetParent(path).FullName,
|
||||
// Valid = true,
|
||||
// Enabled = true,
|
||||
// AppType = ApplicationType.InternetShortcutApplication,
|
||||
// };
|
||||
// }
|
||||
// catch (Exception e) when (e is SecurityException || e is UnauthorizedAccessException)
|
||||
// {
|
||||
// ProgramLogger.Warn($"|Permission denied when trying to load the program from {path}", e, MethodBase.GetCurrentMethod().DeclaringType, path);
|
||||
|
||||
// return InvalidProgram;
|
||||
// }
|
||||
// }
|
||||
// catch (Exception e)
|
||||
// {
|
||||
// ProgramLogger.Exception($"|An unexpected error occurred in the calling method InternetShortcutProgram at {path}", e, MethodBase.GetCurrentMethod().DeclaringType, path);
|
||||
|
||||
// return InvalidProgram;
|
||||
// }
|
||||
}
|
||||
|
||||
private static Win32Program LnkProgram(string path)
|
||||
{
|
||||
//return InvalidProgram;
|
||||
try
|
||||
{
|
||||
var program = CreateWin32Program(path);
|
||||
@@ -510,11 +244,11 @@ public class Win32Program // : IProgram
|
||||
|
||||
program.LnkFilePath = program.FullPath;
|
||||
program.LnkResolvedExecutableName = Path.GetFileName(target);
|
||||
program.LnkResolvedExecutableNameLocalized = Path.GetFileName(target);// Path.GetFileName(Main.ShellLocalizationHelper.GetLocalizedPath(target));
|
||||
program.LnkResolvedExecutableNameLocalized = Path.GetFileName(target); // Path.GetFileName(Main.ShellLocalizationHelper.GetLocalizedPath(target));
|
||||
|
||||
// Using CurrentCulture since this is user facing
|
||||
program.FullPath = Path.GetFullPath(target);
|
||||
program.FullPathLocalized = Path.GetFullPath(target);// Main.ShellLocalizationHelper.GetLocalizedPath(target);
|
||||
program.FullPathLocalized = Path.GetFullPath(target); // Main.ShellLocalizationHelper.GetLocalizedPath(target);
|
||||
|
||||
program.Arguments = ShellLinkHelper.Arguments;
|
||||
|
||||
@@ -542,7 +276,7 @@ public class Win32Program // : IProgram
|
||||
}
|
||||
catch (System.IO.FileLoadException)
|
||||
{
|
||||
//ProgramLogger.Warn($"Couldn't load the link file at {path}. This might be caused by a new link being created and locked by the OS.", e, MethodBase.GetCurrentMethod().DeclaringType, path);
|
||||
// ProgramLogger.Warn($"Couldn't load the link file at {path}. This might be caused by a new link being created and locked by the OS.", e, MethodBase.GetCurrentMethod().DeclaringType, path);
|
||||
return InvalidProgram;
|
||||
}
|
||||
|
||||
@@ -550,8 +284,7 @@ public class Win32Program // : IProgram
|
||||
// Error caused likely due to trying to get the description of the program
|
||||
catch (Exception)
|
||||
{
|
||||
//ProgramLogger.Exception($"|An unexpected error occurred in the calling method LnkProgram at {path}", e, MethodBase.GetCurrentMethod().DeclaringType, path);
|
||||
|
||||
// ProgramLogger.Exception($"|An unexpected error occurred in the calling method LnkProgram at {path}", e, MethodBase.GetCurrentMethod().DeclaringType, path);
|
||||
return InvalidProgram;
|
||||
}
|
||||
}
|
||||
@@ -571,20 +304,17 @@ public class Win32Program // : IProgram
|
||||
}
|
||||
catch (Exception e) when (e is SecurityException || e is UnauthorizedAccessException)
|
||||
{
|
||||
//ProgramLogger.Warn($"|Permission denied when trying to load the program from {path}", e, MethodBase.GetCurrentMethod().DeclaringType, path);
|
||||
|
||||
// ProgramLogger.Warn($"|Permission denied when trying to load the program from {path}", e, MethodBase.GetCurrentMethod().DeclaringType, path);
|
||||
return InvalidProgram;
|
||||
}
|
||||
catch (FileNotFoundException)
|
||||
{
|
||||
//ProgramLogger.Warn($"|Unable to locate exe file at {path}", e, MethodBase.GetCurrentMethod().DeclaringType, path);
|
||||
|
||||
// ProgramLogger.Warn($"|Unable to locate exe file at {path}", e, MethodBase.GetCurrentMethod().DeclaringType, path);
|
||||
return InvalidProgram;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//ProgramLogger.Exception($"|An unexpected error occurred in the calling method ExeProgram at {path}", e, MethodBase.GetCurrentMethod().DeclaringType, path);
|
||||
|
||||
// ProgramLogger.Exception($"|An unexpected error occurred in the calling method ExeProgram at {path}", e, MethodBase.GetCurrentMethod().DeclaringType, path);
|
||||
return InvalidProgram;
|
||||
}
|
||||
}
|
||||
@@ -613,7 +343,7 @@ public class Win32Program // : IProgram
|
||||
{
|
||||
return ApplicationType.InternetShortcutApplication;
|
||||
}
|
||||
else if (string.IsNullOrEmpty(extension))// && DirectoryWrapper.Exists(path))
|
||||
else if (string.IsNullOrEmpty(extension))
|
||||
{
|
||||
return ApplicationType.Folder;
|
||||
}
|
||||
@@ -622,11 +352,11 @@ public class Win32Program // : IProgram
|
||||
}
|
||||
|
||||
// Function to get the Win32 application, given the path to the application
|
||||
public static Win32Program GetAppFromPath(string path)
|
||||
public static Win32Program? GetAppFromPath(string path)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(path);
|
||||
|
||||
Win32Program app;
|
||||
Win32Program? app;
|
||||
switch (GetAppTypeFromPath(path))
|
||||
{
|
||||
case ApplicationType.Win32Application:
|
||||
@@ -692,17 +422,17 @@ public class Win32Program // : IProgram
|
||||
}
|
||||
catch (DirectoryNotFoundException )
|
||||
{
|
||||
//ProgramLogger.Warn("|The directory trying to load the program from does not exist", e, MethodBase.GetCurrentMethod().DeclaringType, currentDirectory);
|
||||
// ProgramLogger.Warn("|The directory trying to load the program from does not exist", e, MethodBase.GetCurrentMethod().DeclaringType, currentDirectory);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e) when (e is SecurityException || e is UnauthorizedAccessException)
|
||||
{
|
||||
//ProgramLogger.Warn($"|Permission denied when trying to load programs from {currentDirectory}", e, MethodBase.GetCurrentMethod().DeclaringType, currentDirectory);
|
||||
// ProgramLogger.Warn($"|Permission denied when trying to load programs from {currentDirectory}", e, MethodBase.GetCurrentMethod().DeclaringType, currentDirectory);
|
||||
}
|
||||
catch (Exception )
|
||||
{
|
||||
//ProgramLogger.Exception($"|An unexpected error occurred in the calling method ProgramPaths at {currentDirectory}", e, MethodBase.GetCurrentMethod().DeclaringType, currentDirectory);
|
||||
// ProgramLogger.Exception($"|An unexpected error occurred in the calling method ProgramPaths at {currentDirectory}", e, MethodBase.GetCurrentMethod().DeclaringType, currentDirectory);
|
||||
}
|
||||
|
||||
try
|
||||
@@ -726,11 +456,11 @@ public class Win32Program // : IProgram
|
||||
}
|
||||
catch (Exception e) when (e is SecurityException || e is UnauthorizedAccessException)
|
||||
{
|
||||
//ProgramLogger.Warn($"|Permission denied when trying to load programs from {currentDirectory}", e, MethodBase.GetCurrentMethod().DeclaringType, currentDirectory);
|
||||
// ProgramLogger.Warn($"|Permission denied when trying to load programs from {currentDirectory}", e, MethodBase.GetCurrentMethod().DeclaringType, currentDirectory);
|
||||
}
|
||||
catch (Exception )
|
||||
{
|
||||
//ProgramLogger.Exception($"|An unexpected error occurred in the calling method ProgramPaths at {currentDirectory}", e, MethodBase.GetCurrentMethod().DeclaringType, currentDirectory);
|
||||
// ProgramLogger.Exception($"|An unexpected error occurred in the calling method ProgramPaths at {currentDirectory}", e, MethodBase.GetCurrentMethod().DeclaringType, currentDirectory);
|
||||
}
|
||||
}
|
||||
while (folderQueue.Count > 0);
|
||||
@@ -858,23 +588,26 @@ public class Win32Program // : IProgram
|
||||
}
|
||||
catch (Exception e) when (e is SecurityException || e is UnauthorizedAccessException)
|
||||
{
|
||||
//ProgramLogger.Warn($"|Permission denied when trying to load the program from {path}", e, MethodBase.GetCurrentMethod().DeclaringType, path);
|
||||
|
||||
// ProgramLogger.Warn($"|Permission denied when trying to load the program from {path}", e, MethodBase.GetCurrentMethod().DeclaringType, path);
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
private static string ExpandEnvironmentVariables(string path) =>
|
||||
path != null
|
||||
private static string? ExpandEnvironmentVariables(string path)
|
||||
{
|
||||
return path != null
|
||||
? Environment.ExpandEnvironmentVariables(path)
|
||||
: null;
|
||||
}
|
||||
|
||||
// Overriding the object.GetHashCode() function to aid in removing duplicates while adding and removing apps from the concurrent dictionary storage
|
||||
public override int GetHashCode()
|
||||
=> Win32ProgramEqualityComparer.Default.GetHashCode(this);
|
||||
|
||||
public override bool Equals(object obj)
|
||||
=> obj is Win32Program win32Program && Win32ProgramEqualityComparer.Default.Equals(this, win32Program);
|
||||
{
|
||||
return obj is Win32Program win32Program && Win32ProgramEqualityComparer.Default.Equals(this, win32Program);
|
||||
}
|
||||
|
||||
private sealed class Win32ProgramEqualityComparer : IEqualityComparer<Win32Program>
|
||||
{
|
||||
@@ -900,7 +633,7 @@ public class Win32Program // : IProgram
|
||||
public static List<Win32Program> DeduplicatePrograms(IEnumerable<Win32Program> programs)
|
||||
=> new HashSet<Win32Program>(programs, Win32ProgramEqualityComparer.Default).ToList();
|
||||
|
||||
private static Win32Program GetProgramFromPath(string path)
|
||||
private static Win32Program? GetProgramFromPath(string path)
|
||||
{
|
||||
var extension = Extension(path);
|
||||
if (ExecutableApplicationExtensions.Contains(extension))
|
||||
@@ -938,7 +671,7 @@ public class Win32Program // : IProgram
|
||||
// https://msdn.microsoft.com/library/windows/desktop/ee872121
|
||||
try
|
||||
{
|
||||
var redirectionPath = ""; // ReparsePoint.GetTarget(program.FullPath);
|
||||
var redirectionPath = string.Empty; // ReparsePoint.GetTarget(program.FullPath);
|
||||
if (string.IsNullOrEmpty(redirectionPath))
|
||||
{
|
||||
return false;
|
||||
@@ -949,7 +682,7 @@ public class Win32Program // : IProgram
|
||||
}
|
||||
catch (IOException )
|
||||
{
|
||||
//ProgramLogger.Warn($"|Error whilst retrieving the redirection path from app execution alias {program.FullPath}", e, MethodBase.GetCurrentMethod().DeclaringType, program.FullPath);
|
||||
// ProgramLogger.Warn($"|Error whilst retrieving the redirection path from app execution alias {program.FullPath}", e, MethodBase.GetCurrentMethod().DeclaringType, program.FullPath);
|
||||
}
|
||||
|
||||
icoPath = null;
|
||||
@@ -998,19 +731,14 @@ public class Win32Program // : IProgram
|
||||
(/*settings.EnablePathEnvironmentVariableSource*/ false, () => PathEnvironmentProgramPaths(settings_RunCommandSuffixes)),
|
||||
};
|
||||
|
||||
//var disabledProgramsList = settings.DisabledProgramSources;
|
||||
|
||||
// Get all paths but exclude all normal .Executables
|
||||
paths.UnionWith(sources
|
||||
.AsParallel()
|
||||
.SelectMany(source => source.IsEnabled ? source.GetPaths() : Enumerable.Empty<string>())
|
||||
//.Where(programPath => disabledProgramsList.All(x => x.UniqueIdentifier != programPath))
|
||||
.Where(path => !ExecutableApplicationExtensions.Contains(Extension(path))));
|
||||
runCommandPaths.UnionWith(runCommandSources
|
||||
.AsParallel()
|
||||
.SelectMany(source => source.IsEnabled ? source.GetPaths() : Enumerable.Empty<string>())
|
||||
//.Where(programPath => disabledProgramsList.All(x => x.UniqueIdentifier != programPath))
|
||||
);
|
||||
.SelectMany(source => source.IsEnabled ? source.GetPaths() : Enumerable.Empty<string>()));
|
||||
|
||||
var programs = paths.AsParallel().Select(source => GetProgramFromPath(source));
|
||||
var runCommandPrograms = runCommandPaths.AsParallel().Select(source => GetRunCommandProgramFromPath(source));
|
||||
@@ -1020,7 +748,6 @@ public class Win32Program // : IProgram
|
||||
catch (Exception )
|
||||
{
|
||||
// ProgramLogger.Exception("An unexpected error occurred", e, MethodBase.GetCurrentMethod().DeclaringType, "Not available");
|
||||
|
||||
return Array.Empty<Win32Program>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,9 +98,6 @@
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Views\" />
|
||||
</ItemGroup>
|
||||
<Target Name="CopyAdaptiveCardsToTargetDir" BeforeTargets="BeforeBuild">
|
||||
<Message text="PkgAdaptiveCards_ObjectModel_WinUI3 = '$(PkgAdaptiveCards_ObjectModel_WinUI3)'" Importance="high" />
|
||||
<Message text="PkgAdaptiveCards_Rendering_WinUI3 = '$(PkgAdaptiveCards_Rendering_WinUI3)'" Importance="high" />
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
// 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.ObjectModel;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.InteropServices.WindowsRuntime;
|
||||
using CmdPal.Models;
|
||||
using DeveloperCommandPalette;
|
||||
using Microsoft.CmdPal.Common.Extensions;
|
||||
using Microsoft.CmdPal.Common.Services;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Input;
|
||||
using Microsoft.UI.Xaml.Media.Animation;
|
||||
using Microsoft.Windows.CommandPalette.Extensions;
|
||||
using Microsoft.Windows.CommandPalette.Extensions.Helpers;
|
||||
using Windows.Foundation;
|
||||
using Windows.Win32;
|
||||
using WindowsCommandPalette.BuiltinCommands;
|
||||
using WindowsCommandPalette.BuiltinCommands.AllApps;
|
||||
using WindowsCommandPalette.Builtins;
|
||||
|
||||
namespace WindowsCommandPalette.Views;
|
||||
|
||||
sealed class ActionsProviderWrapper
|
||||
{
|
||||
public bool IsExtension => extensionWrapper != null;
|
||||
|
||||
private readonly bool isValid;
|
||||
|
||||
private ICommandProvider ActionProvider { get; }
|
||||
|
||||
private readonly IExtensionWrapper? extensionWrapper;
|
||||
private IListItem[] _topLevelItems = [];
|
||||
|
||||
public IListItem[] TopLevelItems => _topLevelItems;
|
||||
|
||||
public ActionsProviderWrapper(ICommandProvider provider)
|
||||
{
|
||||
ActionProvider = provider;
|
||||
isValid = true;
|
||||
}
|
||||
|
||||
public ActionsProviderWrapper(IExtensionWrapper extension)
|
||||
{
|
||||
extensionWrapper = extension;
|
||||
var extensionImpl = extension.GetExtensionObject();
|
||||
if (extensionImpl?.GetProvider(ProviderType.Commands) is not ICommandProvider provider)
|
||||
{
|
||||
throw new ArgumentException("extension didn't actually implement ICommandProvider");
|
||||
}
|
||||
|
||||
ActionProvider = provider;
|
||||
isValid = true;
|
||||
}
|
||||
|
||||
public async Task LoadTopLevelCommands()
|
||||
{
|
||||
if (!isValid)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var t = new Task<IListItem[]>(() => ActionProvider.TopLevelCommands());
|
||||
t.Start();
|
||||
var commands = await t.ConfigureAwait(false);
|
||||
|
||||
// On a BG thread here
|
||||
if (commands != null)
|
||||
{
|
||||
_topLevelItems = commands;
|
||||
}
|
||||
}
|
||||
|
||||
public void AllowSetForeground(bool allow)
|
||||
{
|
||||
if (!IsExtension)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var iextn = extensionWrapper?.GetExtensionObject();
|
||||
unsafe
|
||||
{
|
||||
PInvoke.CoAllowSetForegroundWindow(iextn);
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Equals(object? obj) => obj is ActionsProviderWrapper wrapper && isValid == wrapper.isValid;
|
||||
}
|
||||
@@ -219,7 +219,7 @@ public sealed partial class MainPage : Page
|
||||
_ = LoadAllCommands();
|
||||
}
|
||||
|
||||
private void _HackyBadClearFilter()
|
||||
private void HackyBadClearFilter()
|
||||
{
|
||||
// BODGY but I don't care, cause i'm throwing this all out
|
||||
if ((this.RootFrame.Content as Page)?.FindName("FilterBox") is TextBox tb)
|
||||
@@ -235,7 +235,7 @@ public sealed partial class MainPage : Page
|
||||
{
|
||||
if (!RootFrame.CanGoBack)
|
||||
{
|
||||
_HackyBadClearFilter();
|
||||
HackyBadClearFilter();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -376,7 +376,7 @@ public sealed partial class MainPage : Page
|
||||
RootFrame.GoBack();
|
||||
if (!RootFrame.CanGoBack)
|
||||
{
|
||||
_HackyBadClearFilter();
|
||||
HackyBadClearFilter();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -394,7 +394,7 @@ public sealed partial class MainPage : Page
|
||||
|
||||
if (!RootFrame.CanGoBack)
|
||||
{
|
||||
_HackyBadClearFilter();
|
||||
HackyBadClearFilter();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -504,70 +504,3 @@ public sealed partial class MainPage : Page
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sealed class ActionsProviderWrapper
|
||||
{
|
||||
public bool IsExtension => extensionWrapper != null;
|
||||
|
||||
private readonly bool isValid;
|
||||
|
||||
private ICommandProvider ActionProvider { get; }
|
||||
|
||||
private readonly IExtensionWrapper? extensionWrapper;
|
||||
private IListItem[] _topLevelItems = [];
|
||||
|
||||
public IListItem[] TopLevelItems => _topLevelItems;
|
||||
|
||||
public ActionsProviderWrapper(ICommandProvider provider)
|
||||
{
|
||||
ActionProvider = provider;
|
||||
isValid = true;
|
||||
}
|
||||
|
||||
public ActionsProviderWrapper(IExtensionWrapper extension)
|
||||
{
|
||||
extensionWrapper = extension;
|
||||
var extensionImpl = extension.GetExtensionObject();
|
||||
if (extensionImpl?.GetProvider(ProviderType.Commands) is not ICommandProvider provider)
|
||||
{
|
||||
throw new ArgumentException("extension didn't actually implement ICommandProvider");
|
||||
}
|
||||
|
||||
ActionProvider = provider;
|
||||
isValid = true;
|
||||
}
|
||||
|
||||
public async Task LoadTopLevelCommands()
|
||||
{
|
||||
if (!isValid)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var t = new Task<IListItem[]>(() => ActionProvider.TopLevelCommands());
|
||||
t.Start();
|
||||
var commands = await t.ConfigureAwait(false);
|
||||
|
||||
// On a BG thread here
|
||||
if (commands != null)
|
||||
{
|
||||
_topLevelItems = commands;
|
||||
}
|
||||
}
|
||||
|
||||
public void AllowSetForeground(bool allow)
|
||||
{
|
||||
if (!IsExtension)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var iextn = extensionWrapper?.GetExtensionObject();
|
||||
unsafe
|
||||
{
|
||||
PInvoke.CoAllowSetForegroundWindow(iextn);
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Equals(object? obj) => obj is ActionsProviderWrapper wrapper && isValid == wrapper.isValid;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user