mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-04 18:26:39 +02:00
Merge branch 'master' into spelling
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Security;
|
||||
|
||||
@@ -23,6 +23,7 @@ namespace Microsoft.Plugin.Program
|
||||
{
|
||||
for (var i = 1; i < query.Terms.Count; i++)
|
||||
{
|
||||
// Using Ordinal since this is internal and used with a symbol
|
||||
if (!string.Equals(query.Terms[i], DoubleDash, StringComparison.Ordinal))
|
||||
{
|
||||
continue;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// 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.IO;
|
||||
using System.IO.Abstractions;
|
||||
|
||||
namespace Microsoft.Plugin.Program
|
||||
{
|
||||
@@ -16,11 +16,13 @@ namespace Microsoft.Plugin.Program
|
||||
/// </remarks>
|
||||
public class ProgramSource
|
||||
{
|
||||
private static readonly IFileSystem FileSystem = new FileSystem();
|
||||
|
||||
private string name;
|
||||
|
||||
public string Location { get; set; }
|
||||
|
||||
public string Name { get => name ?? new DirectoryInfo(Location).Name; set => name = value; }
|
||||
public string Name { get => name ?? FileSystem.DirectoryInfo.FromDirectoryName(Location).Name; set => name = value; }
|
||||
|
||||
public bool Enabled { get; set; } = true;
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.IO.Abstractions;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
@@ -19,6 +19,8 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
[Serializable]
|
||||
public partial class UWP
|
||||
{
|
||||
private static readonly IPath Path = new FileSystem().Path;
|
||||
|
||||
public string Name { get; }
|
||||
|
||||
public string FullName { get; }
|
||||
@@ -204,6 +206,7 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
{
|
||||
if (obj is UWP uwp)
|
||||
{
|
||||
// Using CurrentCultureIgnoreCase since this is used with FamilyName
|
||||
return FamilyName.Equals(uwp.FamilyName, StringComparison.CurrentCultureIgnoreCase);
|
||||
}
|
||||
else
|
||||
@@ -214,6 +217,7 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
// Using CurrentCultureIgnoreCase since this is used with FamilyName
|
||||
return FamilyName.GetHashCode(StringComparison.CurrentCultureIgnoreCase);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ 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.InteropServices;
|
||||
@@ -31,6 +32,10 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
[Serializable]
|
||||
public class UWPApplication : IProgram
|
||||
{
|
||||
private static readonly IFileSystem FileSystem = new FileSystem();
|
||||
private static readonly IPath Path = FileSystem.Path;
|
||||
private static readonly IFile File = FileSystem.File;
|
||||
|
||||
public string AppListEntry { get; set; }
|
||||
|
||||
public string UniqueIdentifier { get; set; }
|
||||
@@ -111,6 +116,7 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
result.Title = DisplayName;
|
||||
result.SetTitleHighlightData(StringMatcher.FuzzySearch(query, Name).MatchData);
|
||||
|
||||
// Using CurrentCulture since this is user facing
|
||||
var toolTipTitle = string.Format(CultureInfo.CurrentCulture, "{0}: {1}", Properties.Resources.powertoys_run_plugin_program_file_name, result.Title);
|
||||
var toolTipText = string.Format(CultureInfo.CurrentCulture, "{0}: {1}", Properties.Resources.powertoys_run_plugin_program_file_path, Package.Location);
|
||||
result.ToolTipData = new ToolTipData(toolTipTitle, toolTipText);
|
||||
@@ -263,6 +269,8 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
if (File.Exists(manifest))
|
||||
{
|
||||
var file = File.ReadAllText(manifest);
|
||||
|
||||
// Using OrdinalIgnoreCase since this is used internally
|
||||
if (file.Contains("TrustLevel=\"mediumIL\"", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return true;
|
||||
@@ -276,12 +284,16 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
internal string ResourceFromPri(string packageFullName, string resourceReference)
|
||||
{
|
||||
const string prefix = "ms-resource:";
|
||||
|
||||
// Using OrdinalIgnoreCase since this is used internally
|
||||
if (!string.IsNullOrWhiteSpace(resourceReference) && resourceReference.StartsWith(prefix, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
// magic comes from @talynone
|
||||
// https://github.com/talynone/Wox.Plugin.WindowsUniversalAppLauncher/blob/master/StoreAppLauncher/Helpers/NativeApiHelper.cs#L139-L153
|
||||
string key = resourceReference.Substring(prefix.Length);
|
||||
string parsed;
|
||||
|
||||
// Using Ordinal/OrdinalIgnorcase since these are used internally
|
||||
if (key.StartsWith("//", StringComparison.Ordinal))
|
||||
{
|
||||
parsed = prefix + key;
|
||||
@@ -540,6 +552,8 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
// windows 8 https://msdn.microsoft.com/en-us/library/windows/apps/br211475.aspx
|
||||
string path;
|
||||
bool isLogoUriSet;
|
||||
|
||||
// Using Ordinal since this is used internally with uri
|
||||
if (uri.Contains("\\", StringComparison.Ordinal))
|
||||
{
|
||||
path = Path.Combine(Package.Location, uri);
|
||||
@@ -598,6 +612,7 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
string currentBackgroundColor;
|
||||
if (BackgroundColor == "transparent")
|
||||
{
|
||||
// Using InvariantCulture since this is internal
|
||||
currentBackgroundColor = SystemParameters.WindowGlassBrush.ToString(CultureInfo.InvariantCulture);
|
||||
}
|
||||
else
|
||||
|
||||
@@ -7,6 +7,7 @@ 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.Security;
|
||||
@@ -20,12 +21,18 @@ using Wox.Infrastructure;
|
||||
using Wox.Infrastructure.FileSystemHelper;
|
||||
using Wox.Plugin;
|
||||
using Wox.Plugin.Logger;
|
||||
using DirectoryWrapper = Wox.Infrastructure.FileSystemHelper.DirectoryWrapper;
|
||||
|
||||
namespace Microsoft.Plugin.Program.Programs
|
||||
{
|
||||
[Serializable]
|
||||
public class Win32Program : IProgram
|
||||
{
|
||||
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 string Name { get; set; }
|
||||
|
||||
public string UniqueIdentifier { get; set; }
|
||||
@@ -57,7 +64,7 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
// Wrappers for File Operations
|
||||
public static IFileVersionInfoWrapper FileVersionInfoWrapper { get; set; } = new FileVersionInfoWrapper();
|
||||
|
||||
public static IFileWrapper FileWrapper { get; set; } = new FileWrapper();
|
||||
public static IFile FileWrapper { get; set; } = new FileSystem().File;
|
||||
|
||||
public static IShellLinkHelper Helper { get; set; } = new ShellLinkHelper();
|
||||
|
||||
@@ -98,6 +105,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
|
||||
// Using Ordinal IgnoreCase since this is used internally
|
||||
bool isWebApplication = FullPath.Contains(ProxyWebApp, StringComparison.OrdinalIgnoreCase) && Arguments.Contains(AppIdArgument, StringComparison.OrdinalIgnoreCase);
|
||||
return isWebApplication;
|
||||
}
|
||||
@@ -121,6 +129,7 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
// check if any space separated query is a part of the app name or path name
|
||||
foreach (var subquery in subqueries)
|
||||
{
|
||||
// Using OrdinalIgnoreCase since these are used internally
|
||||
if (FullPath.Contains(subquery, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
pathContainsQuery = true;
|
||||
@@ -172,6 +181,7 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
{
|
||||
if (query != null && AppType == ApplicationType.RunCommand)
|
||||
{
|
||||
// Using OrdinalIgnoreCase since this is used internally
|
||||
if (!query.Equals(Name, StringComparison.OrdinalIgnoreCase) && !query.Equals(ExecutableName, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
@@ -235,6 +245,7 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
result.Title = Name;
|
||||
result.SetTitleHighlightData(StringMatcher.FuzzySearch(query, Name).MatchData);
|
||||
|
||||
// Using CurrentCulture since this is user facing
|
||||
var toolTipTitle = string.Format(CultureInfo.CurrentCulture, "{0}: {1}", Properties.Resources.powertoys_run_plugin_program_file_name, result.Title);
|
||||
var toolTipText = string.Format(CultureInfo.CurrentCulture, "{0}: {1}", Properties.Resources.powertoys_run_plugin_program_file_path, FullPath);
|
||||
result.ToolTipData = new ToolTipData(toolTipTitle, toolTipText);
|
||||
@@ -342,6 +353,8 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
Name = Path.GetFileNameWithoutExtension(path),
|
||||
ExecutableName = Path.GetFileName(path),
|
||||
IcoPath = path,
|
||||
|
||||
// Using CurrentCulture since this is user facing
|
||||
FullPath = path.ToLower(CultureInfo.CurrentCulture),
|
||||
UniqueIdentifier = path,
|
||||
ParentDirectory = Directory.GetParent(path).FullName,
|
||||
@@ -384,6 +397,7 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
|
||||
foreach (string line in lines)
|
||||
{
|
||||
// Using OrdinalIgnoreCase since this is used internally
|
||||
if (line.StartsWith(urlPrefix, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
urlPath = line.Substring(urlPrefix.Length);
|
||||
@@ -407,6 +421,7 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
}
|
||||
}
|
||||
|
||||
// Using OrdinalIgnoreCase since this is used internally
|
||||
if (line.StartsWith(iconFilePrefix, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
iconPath = line.Substring(iconFilePrefix.Length);
|
||||
@@ -465,6 +480,8 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
if (File.Exists(target) || Directory.Exists(target))
|
||||
{
|
||||
program.LnkResolvedPath = program.FullPath;
|
||||
|
||||
// Using CurrentCulture since this is user facing
|
||||
program.FullPath = Path.GetFullPath(target).ToLower(CultureInfo.CurrentCulture);
|
||||
program.AppType = GetAppTypeFromPath(target);
|
||||
|
||||
@@ -543,6 +560,7 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
string extension = Extension(path);
|
||||
ApplicationType appType = ApplicationType.GenericFile;
|
||||
|
||||
// Using OrdinalIgnoreCase since these are used internally with paths
|
||||
if (ExecutableApplicationExtensions.Contains(extension))
|
||||
{
|
||||
appType = ApplicationType.Win32Application;
|
||||
@@ -677,6 +695,7 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
|
||||
private static string Extension(string path)
|
||||
{
|
||||
// Using CurrentCulture since this is user facing
|
||||
var extension = Path.GetExtension(path)?.ToLower(CultureInfo.CurrentCulture);
|
||||
|
||||
if (!string.IsNullOrEmpty(extension))
|
||||
@@ -734,6 +753,7 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
.Distinct()
|
||||
.ToArray();
|
||||
|
||||
// Using OrdinalIgnoreCase since this is used internally with paths
|
||||
var programs1 = allPaths.AsParallel().Where(p => Extension(p).Equals(ShortcutExtension, StringComparison.OrdinalIgnoreCase)).Select(LnkProgram);
|
||||
var programs2 = allPaths.AsParallel().Where(p => Extension(p).Equals(ApplicationReferenceExtension, StringComparison.OrdinalIgnoreCase)).Select(CreateWin32Program);
|
||||
var programs3 = allPaths.AsParallel().Where(p => Extension(p).Equals(InternetShortcutExtension, StringComparison.OrdinalIgnoreCase)).Select(InternetShortcutProgram);
|
||||
@@ -768,6 +788,7 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
.Distinct()
|
||||
.ToArray();
|
||||
|
||||
// Using OrdinalIgnoreCase since this is used internally with paths
|
||||
var programs1 = paths.AsParallel().Where(p => Extension(p).Equals(ShortcutExtension, StringComparison.OrdinalIgnoreCase)).Select(LnkProgram);
|
||||
var programs2 = paths.AsParallel().Where(p => Extension(p).Equals(ApplicationReferenceExtension, StringComparison.OrdinalIgnoreCase)).Select(CreateWin32Program);
|
||||
var programs3 = paths.AsParallel().Where(p => Extension(p).Equals(InternetShortcutExtension, StringComparison.OrdinalIgnoreCase)).Select(InternetShortcutProgram);
|
||||
@@ -908,6 +929,7 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
&& !string.IsNullOrEmpty(app1.ExecutableName) && !string.IsNullOrEmpty(app2.ExecutableName)
|
||||
&& !string.IsNullOrEmpty(app1.FullPath) && !string.IsNullOrEmpty(app2.FullPath))
|
||||
{
|
||||
// Using OrdinalIgnoreCase since this is used internally
|
||||
return app1.Name.Equals(app2.Name, StringComparison.OrdinalIgnoreCase)
|
||||
&& app1.ExecutableName.Equals(app2.ExecutableName, StringComparison.OrdinalIgnoreCase)
|
||||
&& app1.FullPath.Equals(app2.FullPath, StringComparison.OrdinalIgnoreCase);
|
||||
@@ -924,6 +946,8 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
int fullPathPrime = 31;
|
||||
|
||||
int result = 1;
|
||||
|
||||
// Using Ordinal since this is used internally
|
||||
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);
|
||||
|
||||
@@ -24,6 +24,7 @@ namespace Microsoft.Plugin.Program.Storage
|
||||
// To obtain the last event associated with a particular app.
|
||||
while (eventHandlingQueue.TryPeek(out string currentAppPath))
|
||||
{
|
||||
// Using OrdinalIgnoreCase since this is used internally with paths
|
||||
if (string.IsNullOrEmpty(previousAppPath) || previousAppPath.Equals(currentAppPath, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
// To dequeue a path only if it is the first one in the queue or if the path was the same as thre previous one (to avoid trying to create apps on duplicate events)
|
||||
|
||||
@@ -8,6 +8,7 @@ using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.IO.Abstractions;
|
||||
using System.Threading.Tasks;
|
||||
using Wox.Infrastructure.Storage;
|
||||
using Wox.Plugin.Logger;
|
||||
@@ -17,6 +18,9 @@ namespace Microsoft.Plugin.Program.Storage
|
||||
{
|
||||
internal class Win32ProgramRepository : ListRepository<Programs.Win32Program>, IProgramRepository
|
||||
{
|
||||
private static readonly IFileSystem FileSystem = new FileSystem();
|
||||
private static readonly IPath Path = FileSystem.Path;
|
||||
|
||||
private const string LnkExtension = ".lnk";
|
||||
private const string UrlExtension = ".url";
|
||||
|
||||
@@ -145,6 +149,7 @@ namespace Microsoft.Plugin.Program.Storage
|
||||
try
|
||||
{
|
||||
// To mitigate the issue of not having a FullPath for a shortcut app, we iterate through the items and find the app with the same hashcode.
|
||||
// Using OrdinalIgnoreCase since this is used internally
|
||||
if (extension.Equals(LnkExtension, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
app = GetAppWithSameLnkResolvedPath(path);
|
||||
@@ -174,6 +179,7 @@ namespace Microsoft.Plugin.Program.Storage
|
||||
{
|
||||
foreach (Win32Program app in Items)
|
||||
{
|
||||
// Using CurrentCultureIgnoreCase since application names could be dependent on currentculture See: https://github.com/microsoft/PowerToys/pull/5847/files#r468245190
|
||||
if (name.Equals(app.Name, StringComparison.CurrentCultureIgnoreCase) && executableName.Equals(app.ExecutableName, StringComparison.CurrentCultureIgnoreCase))
|
||||
{
|
||||
return app;
|
||||
@@ -189,7 +195,8 @@ namespace Microsoft.Plugin.Program.Storage
|
||||
{
|
||||
foreach (Programs.Win32Program app in Items)
|
||||
{
|
||||
if (lnkResolvedPath.ToLower(CultureInfo.CurrentCulture).Equals(app.LnkResolvedPath, StringComparison.CurrentCultureIgnoreCase))
|
||||
// Using Invariant / OrdinalIgnoreCase since we're comparing paths
|
||||
if (lnkResolvedPath.ToUpperInvariant().Equals(app.LnkResolvedPath, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return app;
|
||||
}
|
||||
@@ -201,7 +208,9 @@ namespace Microsoft.Plugin.Program.Storage
|
||||
private void OnAppCreated(object sender, FileSystemEventArgs e)
|
||||
{
|
||||
string path = e.FullPath;
|
||||
if (!Path.GetExtension(path).Equals(UrlExtension, StringComparison.CurrentCultureIgnoreCase) && !Path.GetExtension(path).Equals(LnkExtension, StringComparison.CurrentCultureIgnoreCase))
|
||||
|
||||
// Using OrdinalIgnoreCase since we're comparing extensions
|
||||
if (!Path.GetExtension(path).Equals(UrlExtension, StringComparison.OrdinalIgnoreCase) && !Path.GetExtension(path).Equals(LnkExtension, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
Programs.Win32Program app = Programs.Win32Program.GetAppFromPath(path);
|
||||
if (app != null)
|
||||
@@ -214,7 +223,9 @@ namespace Microsoft.Plugin.Program.Storage
|
||||
private void OnAppChanged(object sender, FileSystemEventArgs e)
|
||||
{
|
||||
string path = e.FullPath;
|
||||
if (Path.GetExtension(path).Equals(UrlExtension, StringComparison.CurrentCultureIgnoreCase) || Path.GetExtension(path).Equals(LnkExtension, StringComparison.CurrentCultureIgnoreCase))
|
||||
|
||||
// Using OrdinalIgnoreCase since we're comparing extensions
|
||||
if (Path.GetExtension(path).Equals(UrlExtension, StringComparison.OrdinalIgnoreCase) || Path.GetExtension(path).Equals(LnkExtension, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
// When a url or lnk app is installed, multiple created and changed events are triggered.
|
||||
// To prevent the code from acting on the first such event (which may still be during app installation), the events are added a common queue and dequeued by a background task at regular intervals - https://github.com/microsoft/PowerToys/issues/6429.
|
||||
|
||||
Reference in New Issue
Block a user