.NET 8 Upgrade Silenced Errors Fix (#30469)

* [Dev][Build] .NET 8 Upgrade Silenced errors first fix.

* [Dev][Build] .NET 8 Upgrade Silenced errors. CA1859

* [Dev][Build] .NET 8 Upgrade Silenced errors. CA1854.

* [Dev][Build] .NET 8 Upgrade Silenced errors. CA1860

* [Dev][Build] .NET 8 Upgrade Silenced errors. CA1861

* [Dev][Build] .NET 8 Upgrade Silenced errors. CA1862

* [Dev][Build] .NET 8 Upgrade Silenced errors. CA1863

* [Dev][Build] .NET 8 Upgrade Silenced errors. CA1864

* [Dev][Build] .NET 8 Upgrade Silenced errors. CA1865

* [Dev][Build] .NET 8 Upgrade Silenced errors. CA2208

* [Dev][Build] .NET 8 Upgrade Silenced errors. CS9191

* [Dev][Build] .NET 8 Upgrade Silenced errors. Spell check

* [Dev][Build] .NET 8 Upgrade Silenced errors. Spell check

* [Dev][Build] .NET 8 Upgrade Silenced errors.
- CompositeFormat variables used more than once in the same file were assigned to a single variable.
- GetProcessesByName logic fix.
- String comparion fix.
- ArgumentOutOfRangeException message change.

* [Dev][Build] .NET 8 Upgrade Silenced errors.
- Null check added.
- static readonly CompositeFormat added for all fields.
This commit is contained in:
gokcekantarci
2023-12-28 13:37:13 +03:00
committed by GitHub
parent cd57659ef6
commit a94b3eec39
112 changed files with 429 additions and 291 deletions

View File

@@ -11,6 +11,7 @@ namespace Community.PowerToys.Run.Plugin.UnitConverter.UnitTest
[TestClass]
public class InputInterpreterTests
{
#pragma warning disable CA1861 // Avoid constant arrays as arguments
[DataTestMethod]
[DataRow(new string[] { "1,5'" }, new string[] { "1,5", "'" })]
[DataRow(new string[] { "1.5'" }, new string[] { "1.5", "'" })]
@@ -58,6 +59,7 @@ namespace Community.PowerToys.Run.Plugin.UnitConverter.UnitTest
[DataRow(new string[] { "5", "f", "in", "celsius" }, new string[] { "5", "°f", "in", "DegreeCelsius" })]
[DataRow(new string[] { "5", "c", "in", "f" }, new string[] { "5", "°c", "in", "°f" })]
[DataRow(new string[] { "5", "f", "in", "c" }, new string[] { "5", "°f", "in", "°c" })]
#pragma warning restore CA1861 // Avoid constant arrays as arguments
public void PrefixesDegrees(string[] input, string[] expectedResult)
{
InputInterpreter.DegreePrefixer(ref input);

View File

@@ -2,6 +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;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
@@ -157,12 +158,12 @@ namespace Community.PowerToys.Run.Plugin.UnitConverter
/// </summary>
public static void FeetToFt(ref string[] split)
{
if (split[1].ToLowerInvariant() == "feet")
if (string.Equals(split[1], "feet", StringComparison.OrdinalIgnoreCase))
{
split[1] = "ft";
}
if (split[3].ToLowerInvariant() == "feet")
if (string.Equals(split[3], "feet", StringComparison.OrdinalIgnoreCase))
{
split[3] = "ft";
}
@@ -183,7 +184,8 @@ namespace Community.PowerToys.Run.Plugin.UnitConverter
public static void GallonHandler(ref string[] split, CultureInfo culture)
{
HashSet<string> britishCultureNames = new HashSet<string>() { "en-AI", "en-VG", "en-GB", "en-KY", "en-MS", "en-AG", "en-DM", "en-GD", "en-KN", "en-LC", "en-VC", "en-IE", "en-GY", "en-AE" };
if (split[1].ToLowerInvariant() == "gal" || split[1].ToLowerInvariant() == "gallon")
if (string.Equals(split[1], "gal", StringComparison.OrdinalIgnoreCase) ||
string.Equals(split[1], "gallon", StringComparison.OrdinalIgnoreCase))
{
if (britishCultureNames.Contains(culture.Name))
{
@@ -195,7 +197,8 @@ namespace Community.PowerToys.Run.Plugin.UnitConverter
}
}
if (split[3].ToLowerInvariant() == "gal" || split[3].ToLowerInvariant() == "gallon")
if (string.Equals(split[3], "gal", StringComparison.OrdinalIgnoreCase) ||
string.Equals(split[3], "gallon", StringComparison.OrdinalIgnoreCase))
{
if (britishCultureNames.Contains(culture.Name))
{

View File

@@ -7,6 +7,7 @@ using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Windows;
using System.Windows.Input;
@@ -27,6 +28,8 @@ namespace Community.PowerToys.Run.Plugin.UnitConverter
private static string _icon_path;
private bool _disposed;
private static readonly CompositeFormat CopyToClipboard = System.Text.CompositeFormat.Parse(Properties.Resources.copy_to_clipboard);
public void Init(PluginInitContext context)
{
ArgumentNullException.ThrowIfNull(context);
@@ -61,7 +64,7 @@ namespace Community.PowerToys.Run.Plugin.UnitConverter
Title = result.ToString(null),
IcoPath = _icon_path,
Score = 300,
SubTitle = string.Format(CultureInfo.CurrentCulture, Properties.Resources.copy_to_clipboard, result.QuantityInfo.Name),
SubTitle = string.Format(CultureInfo.CurrentCulture, CopyToClipboard, result.QuantityInfo.Name),
Action = c =>
{
var ret = false;

View File

@@ -36,7 +36,8 @@ namespace Community.PowerToys.Run.Plugin.UnitConverter
private static Enum GetUnitEnum(string unit, QuantityInfo unitInfo)
{
UnitInfo first = Array.Find(unitInfo.UnitInfos, info =>
unit.ToLowerInvariant() == info.Name.ToLowerInvariant() || unit.ToLowerInvariant() == info.PluralName.ToLowerInvariant());
string.Equals(unit, info.Name, StringComparison.OrdinalIgnoreCase) ||
string.Equals(unit, info.PluralName, StringComparison.OrdinalIgnoreCase));
if (first != null)
{

View File

@@ -138,7 +138,7 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces
});
}
results = results.Where(a => a.Title.ToLowerInvariant().Contains(query.Search.ToLowerInvariant())).ToList();
results = results.Where(a => a.Title.Contains(query.Search, StringComparison.InvariantCultureIgnoreCase)).ToList();
results.ForEach(x =>
{

View File

@@ -14,6 +14,12 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.RemoteMachinesHelper
{
public class VSCodeRemoteMachinesApi
{
private static readonly JsonSerializerOptions _serializerOptions = new JsonSerializerOptions
{
AllowTrailingCommas = true,
ReadCommentHandling = JsonCommentHandling.Skip,
};
public VSCodeRemoteMachinesApi()
{
}
@@ -35,7 +41,7 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.RemoteMachinesHelper
try
{
JsonElement vscodeSettingsFile = JsonSerializer.Deserialize<JsonElement>(fileContent, new JsonSerializerOptions() { AllowTrailingCommas = true, ReadCommentHandling = JsonCommentHandling.Skip });
JsonElement vscodeSettingsFile = JsonSerializer.Deserialize<JsonElement>(fileContent, _serializerOptions);
if (vscodeSettingsFile.TryGetProperty("remote.SSH.configFile", out var pathElement))
{
var path = pathElement.GetString();

View File

@@ -26,7 +26,7 @@ namespace Community.PowerToys.Run.Plugin.ValueGenerator
string command = query.Terms[0];
if (command.ToLower(null) == "md5")
if (command.Equals("md5", StringComparison.OrdinalIgnoreCase))
{
int commandIndex = query.RawUserQuery.IndexOf(command, StringComparison.InvariantCultureIgnoreCase);
string content = query.RawUserQuery.Substring(commandIndex + command.Length).Trim();
@@ -115,13 +115,13 @@ namespace Community.PowerToys.Run.Plugin.ValueGenerator
request = new GUIDRequest(version);
}
}
else if (command.ToLower(null) == "base64")
else if (command.Equals("base64", StringComparison.OrdinalIgnoreCase))
{
int commandIndex = query.RawUserQuery.IndexOf(command, StringComparison.InvariantCultureIgnoreCase);
string content = query.RawUserQuery.Substring(commandIndex + command.Length).Trim();
request = new Base64Request(Encoding.UTF8.GetBytes(content));
}
else if (command.ToLower(null) == "base64d")
else if (command.Equals("base64d", StringComparison.OrdinalIgnoreCase))
{
int commandIndex = query.RawUserQuery.IndexOf(command, StringComparison.InvariantCultureIgnoreCase);
string content = query.RawUserQuery.Substring(commandIndex + command.Length).Trim();

View File

@@ -6,6 +6,7 @@ using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using ManagedCommon;
using Microsoft.PowerToys.Settings.UI.Library;
@@ -38,6 +39,10 @@ namespace Community.PowerToys.Run.Plugin.WebSearch
public static string PluginID => "9F1B49201C3F4BF781CAAD5CD88EA4DC";
private static readonly CompositeFormat PluginInBrowserName = System.Text.CompositeFormat.Parse(Properties.Resources.plugin_in_browser_name);
private static readonly CompositeFormat PluginOpen = System.Text.CompositeFormat.Parse(Properties.Resources.plugin_open);
private static readonly CompositeFormat PluginSearchFailed = System.Text.CompositeFormat.Parse(Properties.Resources.plugin_search_failed);
public IEnumerable<PluginAdditionalOption> AdditionalOptions => new List<PluginAdditionalOption>()
{
new PluginAdditionalOption()
@@ -66,7 +71,7 @@ namespace Community.PowerToys.Run.Plugin.WebSearch
results.Add(new Result
{
Title = Properties.Resources.plugin_description.Remove(Description.Length - 1, 1),
SubTitle = string.Format(CultureInfo.CurrentCulture, Properties.Resources.plugin_in_browser_name, BrowserInfo.Name ?? BrowserInfo.MSEdgeName),
SubTitle = string.Format(CultureInfo.CurrentCulture, PluginInBrowserName, BrowserInfo.Name ?? BrowserInfo.MSEdgeName),
QueryTextDisplay = string.Empty,
IcoPath = _iconPath,
ProgramArguments = arguments,
@@ -98,7 +103,7 @@ namespace Community.PowerToys.Run.Plugin.WebSearch
var result = new Result
{
Title = searchTerm,
SubTitle = string.Format(CultureInfo.CurrentCulture, Properties.Resources.plugin_open, BrowserInfo.Name ?? BrowserInfo.MSEdgeName),
SubTitle = string.Format(CultureInfo.CurrentCulture, PluginOpen, BrowserInfo.Name ?? BrowserInfo.MSEdgeName),
QueryTextDisplay = searchTerm,
IcoPath = _iconPath,
};
@@ -170,7 +175,7 @@ namespace Community.PowerToys.Run.Plugin.WebSearch
onPluginError = () =>
{
string errorMsgString = string.Format(CultureInfo.CurrentCulture, Properties.Resources.plugin_search_failed, BrowserInfo.Name ?? BrowserInfo.MSEdgeName);
string errorMsgString = string.Format(CultureInfo.CurrentCulture, PluginSearchFailed, BrowserInfo.Name ?? BrowserInfo.MSEdgeName);
Log.Error(errorMsgString, this.GetType());
_context.API.ShowMsg(

View File

@@ -15,6 +15,8 @@ namespace Microsoft.Plugin.Folder.UnitTests
[TestClass]
public class DriveOrSharedFolderTests
{
private static readonly string[] DriverNames = new[] { "c:", "d:" };
[DataTestMethod]
[DataRow(@"\\test-server\testdir", true)]
[DataRow(@"c:", true)]
@@ -33,7 +35,7 @@ namespace Microsoft.Plugin.Folder.UnitTests
var driveInformationMock = new Mock<IDriveInformation>();
driveInformationMock.Setup(r => r.GetDriveNames())
.Returns(() => new[] { "c:", "d:" });
.Returns(() => DriverNames);
var folderLinksMock = new Mock<IFolderLinks>();
var folderHelper = new FolderHelper(driveInformationMock.Object, folderLinksMock.Object);

View File

@@ -14,7 +14,7 @@ namespace Microsoft.Plugin.Folder.UnitTests
[TestClass]
public class QueryEnvironmentVariableTests
{
private static IQueryEnvironmentVariable _queryEnvironmentVariable;
private static QueryEnvironmentVariable _queryEnvironmentVariable;
private static MockFileSystem _fileSystem;
[TestInitialize]

View File

@@ -37,7 +37,7 @@ namespace Microsoft.Plugin.Folder
};
private static PluginInitContext _context;
private IContextMenu _contextMenuLoader;
private ContextMenuLoader _contextMenuLoader;
private bool _disposed;
public string Name => Properties.Resources.wox_plugin_folder_plugin_name;

View File

@@ -75,7 +75,7 @@ namespace Microsoft.Plugin.Folder.Sources
{
// folder exist, add \ at the end of doesn't exist
// Using Ordinal since this is internal and is used for a symbol
if (!search.EndsWith(@"\", StringComparison.Ordinal))
if (!search.EndsWith('\\'))
{
search += @"\";
}

View File

@@ -4,6 +4,7 @@
using System.Globalization;
using System.IO;
using System.Text;
using Wox.Plugin;
namespace Microsoft.Plugin.Folder.Sources.Result
@@ -12,6 +13,8 @@ namespace Microsoft.Plugin.Folder.Sources.Result
{
private readonly IShellAction _shellAction;
private static readonly CompositeFormat WoxPluginFolderSelectFolderFirstResultTitle = System.Text.CompositeFormat.Parse(Properties.Resources.wox_plugin_folder_select_folder_first_result_title);
public string Search { get; set; }
public CreateOpenCurrentFolderResult(string search)
@@ -29,10 +32,10 @@ namespace Microsoft.Plugin.Folder.Sources.Result
{
return new Wox.Plugin.Result
{
Title = string.Format(CultureInfo.InvariantCulture, Properties.Resources.wox_plugin_folder_select_folder_first_result_title, new DirectoryInfo(Search).Name),
Title = string.Format(CultureInfo.InvariantCulture, WoxPluginFolderSelectFolderFirstResultTitle, new DirectoryInfo(Search).Name),
QueryTextDisplay = Search,
SubTitle = Properties.Resources.wox_plugin_folder_select_folder_first_result_subtitle,
ToolTipData = new ToolTipData(string.Format(CultureInfo.InvariantCulture, Properties.Resources.wox_plugin_folder_select_folder_first_result_title, new DirectoryInfo(Search).Name), Properties.Resources.wox_plugin_folder_select_folder_first_result_subtitle),
ToolTipData = new ToolTipData(string.Format(CultureInfo.InvariantCulture, WoxPluginFolderSelectFolderFirstResultTitle, new DirectoryInfo(Search).Name), Properties.Resources.wox_plugin_folder_select_folder_first_result_subtitle),
IcoPath = Search,
Score = 500,
Action = c => _shellAction.ExecuteSanitized(Search, contextApi),

View File

@@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.
using System.Globalization;
using System.Text;
using Wox.Infrastructure;
using Wox.Plugin;
@@ -10,7 +11,9 @@ namespace Microsoft.Plugin.Folder.Sources.Result
{
public class EnvironmentVariableResult : IItemResult
{
private readonly IShellAction _shellAction = new ShellAction();
private readonly ShellAction _shellAction = new ShellAction();
private static readonly CompositeFormat WoxPluginFolderSelectFolderResultSubtitle = System.Text.CompositeFormat.Parse(Properties.Resources.wox_plugin_folder_select_folder_result_subtitle);
public string Search { get; set; }
@@ -35,8 +38,8 @@ namespace Microsoft.Plugin.Folder.Sources.Result
IcoPath = Path,
// Using CurrentCulture since this is user facing
SubTitle = string.Format(CultureInfo.CurrentCulture, Properties.Resources.wox_plugin_folder_select_folder_result_subtitle, Path),
ToolTipData = new ToolTipData(Title, string.Format(CultureInfo.CurrentCulture, Properties.Resources.wox_plugin_folder_select_folder_result_subtitle, Path)),
SubTitle = string.Format(CultureInfo.CurrentCulture, WoxPluginFolderSelectFolderResultSubtitle, Path),
ToolTipData = new ToolTipData(Title, string.Format(CultureInfo.CurrentCulture, WoxPluginFolderSelectFolderResultSubtitle, Path)),
QueryTextDisplay = Path,
ContextData = new SearchResult { Type = ResultType.Folder, Path = Path },
Action = c => _shellAction.Execute(Path, contextApi),

View File

@@ -4,6 +4,7 @@
using System.Globalization;
using System.IO.Abstractions;
using System.Text;
using Wox.Infrastructure;
using Wox.Plugin;
@@ -11,7 +12,9 @@ namespace Microsoft.Plugin.Folder.Sources.Result
{
public class FileItemResult : IItemResult
{
private static readonly IShellAction ShellAction = new ShellAction();
private static readonly ShellAction ShellAction = new ShellAction();
private static readonly CompositeFormat WoxPluginFolderSelectFileResultSubtitle = System.Text.CompositeFormat.Parse(Properties.Resources.wox_plugin_folder_select_file_result_subtitle);
private readonly IPath _path;
@@ -38,8 +41,8 @@ namespace Microsoft.Plugin.Folder.Sources.Result
Title = Title,
// Using CurrentCulture since this is user facing
SubTitle = string.Format(CultureInfo.CurrentCulture, Properties.Resources.wox_plugin_folder_select_file_result_subtitle, FilePath),
ToolTipData = new ToolTipData(Title, string.Format(CultureInfo.CurrentCulture, Properties.Resources.wox_plugin_folder_select_file_result_subtitle, FilePath)),
SubTitle = string.Format(CultureInfo.CurrentCulture, WoxPluginFolderSelectFileResultSubtitle, FilePath),
ToolTipData = new ToolTipData(Title, string.Format(CultureInfo.CurrentCulture, WoxPluginFolderSelectFileResultSubtitle, FilePath)),
IcoPath = FilePath,
Action = c => ShellAction.Execute(FilePath, contextApi),
ContextData = new SearchResult { Type = ResultType.File, Path = FilePath },

View File

@@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.
using System.Globalization;
using System.Text;
using Wox.Infrastructure;
using Wox.Plugin;
@@ -10,7 +11,9 @@ namespace Microsoft.Plugin.Folder.Sources.Result
{
public class FolderItemResult : IItemResult
{
private static readonly IShellAction ShellAction = new ShellAction();
private static readonly ShellAction ShellAction = new ShellAction();
private static readonly CompositeFormat WoxPluginFolderSelectFolderResultSubtitle = System.Text.CompositeFormat.Parse(Properties.Resources.wox_plugin_folder_select_folder_result_subtitle);
public FolderItemResult()
{
@@ -39,8 +42,8 @@ namespace Microsoft.Plugin.Folder.Sources.Result
IcoPath = Path,
// Using CurrentCulture since this is user facing
SubTitle = string.Format(CultureInfo.CurrentCulture, Properties.Resources.wox_plugin_folder_select_folder_result_subtitle, Subtitle),
ToolTipData = new ToolTipData(Title, string.Format(CultureInfo.CurrentCulture, Properties.Resources.wox_plugin_folder_select_folder_result_subtitle, Subtitle)),
SubTitle = string.Format(CultureInfo.CurrentCulture, WoxPluginFolderSelectFolderResultSubtitle, Subtitle),
ToolTipData = new ToolTipData(Title, string.Format(CultureInfo.CurrentCulture, WoxPluginFolderSelectFolderResultSubtitle, Subtitle)),
QueryTextDisplay = Path,
ContextData = new SearchResult { Type = ResultType.Folder, Path = Path },
Action = c => ShellAction.Execute(Path, contextApi),

View File

@@ -3,12 +3,15 @@
// See the LICENSE file in the project root for more information.
using System.Globalization;
using System.Text;
using Wox.Plugin;
namespace Microsoft.Plugin.Folder.Sources.Result
{
public class TruncatedItemResult : IItemResult
{
private static readonly CompositeFormat MicrosoftPluginFolderTruncationWarningSubtitle = System.Text.CompositeFormat.Parse(Properties.Resources.Microsoft_plugin_folder_truncation_warning_subtitle);
public int PreTruncationCount { get; set; }
public int PostTruncationCount { get; set; }
@@ -25,8 +28,8 @@ namespace Microsoft.Plugin.Folder.Sources.Result
QueryTextDisplay = Search,
// Using CurrentCulture since this is user facing
SubTitle = string.Format(CultureInfo.CurrentCulture, Properties.Resources.Microsoft_plugin_folder_truncation_warning_subtitle, PostTruncationCount, PreTruncationCount),
ToolTipData = new ToolTipData(Properties.Resources.Microsoft_plugin_folder_truncation_warning_title, string.Format(CultureInfo.CurrentCulture, Properties.Resources.Microsoft_plugin_folder_truncation_warning_subtitle, PostTruncationCount, PreTruncationCount)),
SubTitle = string.Format(CultureInfo.CurrentCulture, MicrosoftPluginFolderTruncationWarningSubtitle, PostTruncationCount, PreTruncationCount),
ToolTipData = new ToolTipData(Properties.Resources.Microsoft_plugin_folder_truncation_warning_title, string.Format(CultureInfo.CurrentCulture, MicrosoftPluginFolderTruncationWarningSubtitle, PostTruncationCount, PreTruncationCount)),
IcoPath = WarningIconPath,
};
}

View File

@@ -32,7 +32,7 @@ namespace Microsoft.Plugin.Folder.Sources
// A network path must start with \\
// Using Ordinal since this is internal and used with a symbol
if (!sanitizedPath.StartsWith("\\", StringComparison.Ordinal))
if (!sanitizedPath.StartsWith('\\'))
{
return sanitizedPath;
}

View File

@@ -24,7 +24,7 @@ namespace Microsoft.Plugin.Folder
.Select(item => CreateFolderResult(item.Nickname, item.Path, item.Path, search));
}
private static IItemResult CreateFolderResult(string title, string subtitle, string path, string search)
private static UserFolderResult CreateFolderResult(string title, string subtitle, string path, string search)
{
return new UserFolderResult
{

View File

@@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.
using System.Globalization;
using System.Text;
using Microsoft.Plugin.Folder.Sources;
using Microsoft.Plugin.Folder.Sources.Result;
using Wox.Infrastructure;
@@ -12,7 +13,7 @@ namespace Microsoft.Plugin.Folder
{
public class UserFolderResult : IItemResult
{
private readonly IShellAction _shellAction = new ShellAction();
private readonly ShellAction _shellAction = new ShellAction();
public string Search { get; set; }
@@ -22,6 +23,8 @@ namespace Microsoft.Plugin.Folder
public string Subtitle { get; set; }
private static readonly CompositeFormat WoxPluginFolderSelectFolderResultSubtitle = System.Text.CompositeFormat.Parse(Properties.Resources.wox_plugin_folder_select_folder_result_subtitle);
public Result Create(IPublicAPI contextApi)
{
return new Result(StringMatcher.FuzzySearch(Search, Title).MatchData)
@@ -30,7 +33,7 @@ namespace Microsoft.Plugin.Folder
IcoPath = Path,
// Using CurrentCulture since this is user facing
SubTitle = string.Format(CultureInfo.CurrentCulture, Properties.Resources.wox_plugin_folder_select_folder_result_subtitle, Subtitle),
SubTitle = string.Format(CultureInfo.CurrentCulture, WoxPluginFolderSelectFolderResultSubtitle, Subtitle),
QueryTextDisplay = Path,
ContextData = new SearchResult { Type = ResultType.Folder, Path = Path },
Action = c => _shellAction.Execute(Path, contextApi),

View File

@@ -63,7 +63,7 @@ namespace Microsoft.Plugin.Indexer
},
};
private IContextMenu _contextMenuLoader;
private ContextMenuLoader _contextMenuLoader;
private bool disposedValue;
// To save the configurations of plugins

View File

@@ -16,7 +16,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
{
// Arrange
var itemName = "originalItem1";
IRepository<string> repository = new ListRepository<string>() { itemName };
ListRepository<string> repository = new ListRepository<string>() { itemName };
// Act
var result = repository.Contains(itemName);
@@ -29,7 +29,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
public void ContainsShouldReturnTrueWhenListIsUpdatedWithAdd()
{
// Arrange
IRepository<string> repository = new ListRepository<string>();
ListRepository<string> repository = new ListRepository<string>();
// Act
var itemName = "newItem";
@@ -45,7 +45,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
{
// Arrange
var itemName = "originalItem1";
IRepository<string> repository = new ListRepository<string>() { itemName };
ListRepository<string> repository = new ListRepository<string>() { itemName };
// Act
repository.Remove(itemName);

View File

@@ -25,6 +25,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
private List<IFileSystemWatcherWrapper> _fileSystemWatchers;
private List<Mock<IFileSystemWatcherWrapper>> _fileSystemMocks;
private static readonly string[] Path = new string[] { "URL=steam://rungameid/1258080", "IconFile=iconFile" };
[TestInitialize]
public void SetFileSystemWatchers()
@@ -219,7 +220,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
// File.ReadAllLines must be mocked for url applications
var mockFile = new Mock<IFile>();
mockFile.Setup(m => m.ReadAllLines(It.IsAny<string>())).Returns(new string[] { "URL=steam://rungameid/1258080", "IconFile=iconFile" });
mockFile.Setup(m => m.ReadAllLines(It.IsAny<string>())).Returns(Path);
Win32Program.FileWrapper = mockFile.Object;
// Act
@@ -268,7 +269,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
// File.ReadAllLines must be mocked for url applications
var mockFile = new Mock<IFile>();
mockFile.Setup(m => m.ReadLines(It.IsAny<string>())).Returns(new string[] { "URL=steam://rungameid/1258080", "IconFile=iconFile" });
mockFile.Setup(m => m.ReadLines(It.IsAny<string>())).Returns(Path);
Win32Program.FileWrapper = mockFile.Object;
string fullPath = directory + "\\" + path;
@@ -292,7 +293,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
// File.ReadAllLines must be mocked for url applications
var mockFile = new Mock<IFile>();
mockFile.Setup(m => m.ReadLines(It.IsAny<string>())).Returns(new string[] { "URL=steam://rungameid/1258080", "IconFile=iconFile" });
mockFile.Setup(m => m.ReadLines(It.IsAny<string>())).Returns(Path);
Win32Program.FileWrapper = mockFile.Object;
string oldFullPath = directory + "\\" + oldpath;

View File

@@ -91,7 +91,7 @@ namespace Microsoft.Plugin.Program
.Where(r => r?.Score > 0)
.ToArray();
if (result.Any())
if (result.Length != 0)
{
var maxScore = result.Max(x => x.Score);
return result

View File

@@ -308,7 +308,7 @@ namespace Microsoft.Plugin.Program.Programs
{
parsed = prefix + key;
}
else if (key.StartsWith("/", StringComparison.Ordinal))
else if (key.StartsWith('/'))
{
parsed = prefix + "//" + key;
}

View File

@@ -761,7 +761,7 @@ namespace Microsoft.Plugin.Program.Programs
.ToList() ?? Enumerable.Empty<string>();
// Function to obtain the list of applications, the locations of which have been added to the env variable PATH
private static IEnumerable<string> PathEnvironmentProgramPaths(IList<string> suffixes)
private static List<string> PathEnvironmentProgramPaths(IList<string> suffixes)
{
// To get all the locations stored in the PATH env variable
var pathEnvVariable = Environment.GetEnvironmentVariable("PATH");
@@ -788,7 +788,7 @@ namespace Microsoft.Plugin.Program.Programs
.SelectMany(indexLocation => ProgramPaths(indexLocation, suffixes))
.ToList();
private static IEnumerable<string> StartMenuProgramPaths(IList<string> suffixes)
private static List<string> StartMenuProgramPaths(IList<string> suffixes)
{
var directory1 = Environment.GetFolderPath(Environment.SpecialFolder.StartMenu);
var directory2 = Environment.GetFolderPath(Environment.SpecialFolder.CommonStartMenu);
@@ -797,7 +797,7 @@ namespace Microsoft.Plugin.Program.Programs
return IndexPath(suffixes, indexLocation);
}
private static IEnumerable<string> DesktopProgramPaths(IList<string> suffixes)
private static List<string> DesktopProgramPaths(IList<string> suffixes)
{
var directory1 = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
var directory2 = Environment.GetFolderPath(Environment.SpecialFolder.CommonDesktopDirectory);
@@ -807,7 +807,7 @@ namespace Microsoft.Plugin.Program.Programs
return IndexPath(suffixes, indexLocation);
}
private static IEnumerable<string> RegistryAppProgramPaths(IList<string> suffixes)
private static List<string> RegistryAppProgramPaths(IList<string> suffixes)
{
// https://msdn.microsoft.com/library/windows/desktop/ee872121
const string appPaths = @"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths";

View File

@@ -11,6 +11,7 @@ using System.IO;
using System.IO.Abstractions;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Windows.Input;
using ManagedCommon;
using Microsoft.Plugin.Shell.Properties;
@@ -33,6 +34,8 @@ namespace Microsoft.Plugin.Shell
private readonly ShellPluginSettings _settings;
private readonly PluginJsonStorage<ShellPluginSettings> _storage;
private static readonly CompositeFormat WoxPluginCmdCmdHasBeenExecutedTimes = System.Text.CompositeFormat.Parse(Properties.Resources.wox_plugin_cmd_cmd_has_been_executed_times);
private string IconPath { get; set; }
public string Name => Properties.Resources.wox_plugin_cmd_plugin_name;
@@ -71,6 +74,7 @@ namespace Microsoft.Plugin.Shell
};
private PluginInitContext _context;
private static readonly char[] Separator = new[] { ' ' };
public Main()
{
@@ -123,7 +127,7 @@ namespace Microsoft.Plugin.Shell
if (m.Key == cmd)
{
// Using CurrentCulture since this is user facing
result.SubTitle = Properties.Resources.wox_plugin_cmd_plugin_name + ": " + string.Format(CultureInfo.CurrentCulture, Properties.Resources.wox_plugin_cmd_cmd_has_been_executed_times, m.Value);
result.SubTitle = Properties.Resources.wox_plugin_cmd_plugin_name + ": " + string.Format(CultureInfo.CurrentCulture, WoxPluginCmdCmdHasBeenExecutedTimes, m.Value);
return null;
}
@@ -132,7 +136,7 @@ namespace Microsoft.Plugin.Shell
Title = m.Key,
// Using CurrentCulture since this is user facing
SubTitle = Properties.Resources.wox_plugin_cmd_plugin_name + ": " + string.Format(CultureInfo.CurrentCulture, Properties.Resources.wox_plugin_cmd_cmd_has_been_executed_times, m.Value),
SubTitle = Properties.Resources.wox_plugin_cmd_plugin_name + ": " + string.Format(CultureInfo.CurrentCulture, WoxPluginCmdCmdHasBeenExecutedTimes, m.Value),
IcoPath = IconPath,
Action = c =>
{
@@ -171,7 +175,7 @@ namespace Microsoft.Plugin.Shell
Title = m.Key,
// Using CurrentCulture since this is user facing
SubTitle = Properties.Resources.wox_plugin_cmd_plugin_name + ": " + string.Format(CultureInfo.CurrentCulture, Properties.Resources.wox_plugin_cmd_cmd_has_been_executed_times, m.Value),
SubTitle = Properties.Resources.wox_plugin_cmd_plugin_name + ": " + string.Format(CultureInfo.CurrentCulture, WoxPluginCmdCmdHasBeenExecutedTimes, m.Value),
IcoPath = IconPath,
Action = c =>
{
@@ -285,7 +289,7 @@ namespace Microsoft.Plugin.Shell
}
else
{
var parts = command.Split(new[] { ' ' }, 2);
var parts = command.Split(Separator, 2);
if (parts.Length == 2)
{
var filename = parts[0];

View File

@@ -25,13 +25,13 @@ namespace Microsoft.Plugin.Shell
public void AddCmdHistory(string cmdName)
{
if (Count.ContainsKey(cmdName))
if (Count.TryGetValue(cmdName, out int currentCount))
{
Count[cmdName] += 1;
Count[cmdName] = currentCount + 1;
}
else
{
Count.Add(cmdName, 1);
Count[cmdName] = 1;
}
}
}

View File

@@ -51,8 +51,8 @@ namespace Microsoft.Plugin.WindowWalker.Components
// Hide menu if Explorer.exe is the shell process or the process name is ApplicationFrameHost.exe
// In the first case we would crash the windows ui and in the second case we would kill the generic process for uwp apps.
if (!windowData.Process.IsShellProcess && !(windowData.Process.IsUwpApp & windowData.Process.Name.ToLower(System.Globalization.CultureInfo.InvariantCulture) == "applicationframehost.exe")
&& !(windowData.Process.IsFullAccessDenied & WindowWalkerSettings.Instance.HideKillProcessOnElevatedProcesses))
if (!windowData.Process.IsShellProcess && !(windowData.Process.IsUwpApp && string.Equals(windowData.Process.Name, "ApplicationFrameHost.exe", StringComparison.OrdinalIgnoreCase))
&& !(windowData.Process.IsFullAccessDenied && WindowWalkerSettings.Instance.HideKillProcessOnElevatedProcesses))
{
contextMenu.Add(new ContextMenuResult
{

View File

@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic;
using Microsoft.Plugin.WindowWalker.Properties;
using Wox.Infrastructure;
@@ -26,7 +27,7 @@ namespace Microsoft.Plugin.WindowWalker.Components
foreach (SearchResult x in searchControllerResults)
{
if (x.Result.Process.Name.ToLower(System.Globalization.CultureInfo.InvariantCulture) == "explorer.exe" && x.Result.Process.IsShellProcess)
if (string.Equals(x.Result.Process.Name, "explorer.exe", StringComparison.OrdinalIgnoreCase) && x.Result.Process.IsShellProcess)
{
addExplorerInfo = true;
}

View File

@@ -378,7 +378,7 @@ namespace Microsoft.Plugin.WindowWalker.Components
// Correct the process data if the window belongs to a uwp app hosted by 'ApplicationFrameHost.exe'
// (This only works if the window isn't minimized. For minimized windows the required child window isn't assigned.)
if (_handlesToProcessCache[hWindow].Name.ToUpperInvariant() == "APPLICATIONFRAMEHOST.EXE")
if (string.Equals(_handlesToProcessCache[hWindow].Name, "ApplicationFrameHost.exe", StringComparison.OrdinalIgnoreCase))
{
new Task(() =>
{

View File

@@ -113,7 +113,7 @@ namespace Microsoft.Plugin.WindowWalker.Components
internal WindowProcess(uint pid, uint tid, string name)
{
UpdateProcessInfo(pid, tid, name);
_isUwpApp = Name.ToUpperInvariant().Equals("APPLICATIONFRAMEHOST.EXE", StringComparison.Ordinal);
_isUwpApp = string.Equals(Name, "ApplicationFrameHost.exe", StringComparison.OrdinalIgnoreCase);
}
/// <summary>

View File

@@ -45,12 +45,12 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator
continue;
default:
{
throw new ArgumentOutOfRangeException(nameof(direction), direction, "Can't process value");
throw new ArgumentOutOfRangeException($"Can't process value (Parameter direction: {direction})");
}
}
}
return !trailTest.Any();
return trailTest.Count == 0;
}
private static (TrailDirection Direction, TrailType Type) BracketTrail(char @char)

View File

@@ -34,6 +34,9 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator
private bool _disposed;
private static readonly CompositeFormat WoxPluginCalculatorInEnFormatDescription = System.Text.CompositeFormat.Parse(Properties.Resources.wox_plugin_calculator_in_en_format_description);
private static readonly CompositeFormat WoxPluginCalculatorOutEnFormatDescription = System.Text.CompositeFormat.Parse(Properties.Resources.wox_plugin_calculator_out_en_format_description);
public IEnumerable<PluginAdditionalOption> AdditionalOptions => new List<PluginAdditionalOption>()
{
// The number examples has to be created at runtime to prevent translation.
@@ -41,14 +44,14 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator
{
Key = "InputUseEnglishFormat",
DisplayLabel = Resources.wox_plugin_calculator_in_en_format,
DisplayDescription = string.Format(CultureInfo.CurrentCulture, Resources.wox_plugin_calculator_in_en_format_description, 1000.55.ToString("N2", new CultureInfo("en-us"))),
DisplayDescription = string.Format(CultureInfo.CurrentCulture, WoxPluginCalculatorInEnFormatDescription, 1000.55.ToString("N2", new CultureInfo("en-us"))),
Value = false,
},
new PluginAdditionalOption()
{
Key = "OutputUseEnglishFormat",
DisplayLabel = Resources.wox_plugin_calculator_out_en_format,
DisplayDescription = string.Format(CultureInfo.CurrentCulture, Resources.wox_plugin_calculator_out_en_format_description, 1000.55.ToString("G", new CultureInfo("en-us"))),
DisplayDescription = string.Format(CultureInfo.CurrentCulture, WoxPluginCalculatorOutEnFormatDescription, 1000.55.ToString("G", new CultureInfo("en-us"))),
Value = false,
},
};

View File

@@ -152,7 +152,7 @@ namespace Microsoft.PowerToys.Run.Plugin.Registry.Helper
/// <param name="parentKey">The parent-key, also the root to start the search</param>
/// <param name="searchSubKey">The sub-key to find</param>
/// <returns>A list with all found registry sub-keys</returns>
private static ICollection<RegistryEntry> FindSubKey(in RegistryKey parentKey, in string searchSubKey)
private static Collection<RegistryEntry> FindSubKey(in RegistryKey parentKey, in string searchSubKey)
{
var list = new Collection<RegistryEntry>();
@@ -204,7 +204,7 @@ namespace Microsoft.PowerToys.Run.Plugin.Registry.Helper
/// <param name="parentKey">The registry parent-key</param>
/// <param name="maxCount">(optional) The maximum count of the results</param>
/// <returns>A list with all found registry sub-keys</returns>
private static ICollection<RegistryEntry> GetAllSubKeys(in RegistryKey parentKey, in int maxCount = 50)
private static Collection<RegistryEntry> GetAllSubKeys(in RegistryKey parentKey, in int maxCount = 50)
{
var list = new Collection<RegistryEntry>();

View File

@@ -80,7 +80,7 @@ namespace Microsoft.PowerToys.Run.Plugin.Registry.Helper
return new List<Result>(0);
}
ICollection<KeyValuePair<string, object>> valueList = new List<KeyValuePair<string, object>>(key.ValueCount);
List<KeyValuePair<string, object>> valueList = new List<KeyValuePair<string, object>>(key.ValueCount);
var resultList = new List<Result>();

View File

@@ -10,6 +10,7 @@ using System.Linq;
using System.Net;
using System.Net.NetworkInformation;
using System.Net.Sockets;
using System.Text;
using Microsoft.PowerToys.Run.Plugin.System.Properties;
namespace Microsoft.PowerToys.Run.Plugin.System.Components
@@ -114,6 +115,9 @@ namespace Microsoft.PowerToys.Run.Plugin.System.Components
/// </summary>
internal IPAddressCollection WinsServers { get; private set; }
private static readonly CompositeFormat MicrosoftPluginSysGbps = CompositeFormat.Parse(Properties.Resources.Microsoft_plugin_sys_Gbps);
private static readonly CompositeFormat MicrosoftPluginSysMbps = CompositeFormat.Parse(Properties.Resources.Microsoft_plugin_sys_Mbps);
/// <summary>
/// Initializes a new instance of the <see cref="NetworkConnectionProperties"/> class.
/// This private constructor is used when we crete the list of adapter (properties) by calling <see cref="NetworkConnectionProperties.GetList()"/>.
@@ -286,7 +290,7 @@ namespace Microsoft.PowerToys.Run.Plugin.System.Components
/// <returns>A formatted string like `100 MB/s`</returns>
private static string GetFormattedSpeedValue(long speed)
{
return (speed >= 1000000000) ? string.Format(CultureInfo.InvariantCulture, Resources.Microsoft_plugin_sys_Gbps, speed / 1000000000) : string.Format(CultureInfo.InvariantCulture, Resources.Microsoft_plugin_sys_Mbps, speed / 1000000);
return (speed >= 1000000000) ? string.Format(CultureInfo.InvariantCulture, MicrosoftPluginSysGbps, speed / 1000000000) : string.Format(CultureInfo.InvariantCulture, MicrosoftPluginSysMbps, speed / 1000000);
}
/// <summary>

View File

@@ -5,6 +5,7 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using System.Windows.Controls;
using System.Windows.Input;
using ManagedCommon;
@@ -27,6 +28,8 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate
public static string PluginID => "5D69806A5A474115821C3E4C56B9C793";
private static readonly CompositeFormat MicrosoftPluginTimedatePluginDescription = System.Text.CompositeFormat.Parse(Properties.Resources.Microsoft_plugin_timedate_plugin_description);
public IEnumerable<PluginAdditionalOption> AdditionalOptions
{
get
@@ -93,7 +96,7 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate
string timeExample = Resources.Microsoft_plugin_timedate_plugin_description_example_time + "::" + DateTime.Now.ToString("T", CultureInfo.CurrentCulture);
string dayExample = Resources.Microsoft_plugin_timedate_plugin_description_example_day + "::" + DateTime.Now.ToString("d", CultureInfo.CurrentCulture);
string calendarWeekExample = Resources.Microsoft_plugin_timedate_plugin_description_example_calendarWeek + "::" + DateTime.Now.ToString("d", CultureInfo.CurrentCulture);
return string.Format(CultureInfo.CurrentCulture, Resources.Microsoft_plugin_timedate_plugin_description, Resources.Microsoft_plugin_timedate_plugin_description_example_day, dayExample, timeExample, calendarWeekExample);
return string.Format(CultureInfo.CurrentCulture, MicrosoftPluginTimedatePluginDescription, Resources.Microsoft_plugin_timedate_plugin_description_example_day, dayExample, timeExample, calendarWeekExample);
}
public string GetTranslatedPluginTitle()

View File

@@ -22,6 +22,10 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsSettings.Helper
/// </summary>
private const string _settingsFile = "WindowsSettings.json";
private static readonly JsonSerializerOptions _serializerOptions = new JsonSerializerOptions
{
};
/// <summary>
/// Read all possible Windows settings.
/// </summary>
@@ -42,7 +46,7 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsSettings.Helper
throw new ArgumentNullException(nameof(stream), "stream is null");
}
var options = new JsonSerializerOptions();
var options = _serializerOptions;
options.Converters.Add(new JsonStringEnumConverter());
using var reader = new StreamReader(stream);

View File

@@ -23,7 +23,7 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsTerminal
private const string OpenNewTab = nameof(OpenNewTab);
private const string OpenQuake = nameof(OpenQuake);
private const string ShowHiddenProfiles = nameof(ShowHiddenProfiles);
private readonly ITerminalQuery _terminalQuery = new TerminalQuery();
private readonly TerminalQuery _terminalQuery = new TerminalQuery();
private PluginInitContext _context;
private bool _openNewTab;
private bool _openQuake;
@@ -199,7 +199,7 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsTerminal
_showHiddenProfiles = showHiddenProfiles;
}
private ImageSource GetLogo(TerminalPackage terminal)
private BitmapImage GetLogo(TerminalPackage terminal)
{
var aumid = terminal.AppUserModelId;

View File

@@ -20,7 +20,7 @@ namespace PowerLauncher.Converters
var highlightData = values[1] as List<int>;
var selected = values[2] as bool? == true;
if (highlightData == null || !highlightData.Any())
if (highlightData == null || highlightData.Count == 0)
{
// No highlight data, just return the text
return new Run(text);

View File

@@ -92,7 +92,7 @@ namespace PowerLauncher.Helper
/// Gets command line args - for ClickOnce deployed applications, command line args may not be passed directly, they have to be retrieved.
/// </summary>
/// <returns>List of command line arg strings.</returns>
private static IList<string> GetCommandLineArgs(string uniqueApplicationName)
private static List<string> GetCommandLineArgs(string uniqueApplicationName)
{
string[] args = null;
@@ -116,7 +116,7 @@ namespace PowerLauncher.Helper
{
try
{
using (TextReader reader = new StreamReader(cmdLinePath, Encoding.Unicode))
using (StreamReader reader = new StreamReader(cmdLinePath, Encoding.Unicode))
{
args = NativeMethods.CommandLineToArgvW(reader.ReadToEnd());
}

View File

@@ -10,6 +10,7 @@ using System.Globalization;
using System.IO.Abstractions;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using global::PowerToys.GPOWrapper;
@@ -29,6 +30,8 @@ namespace PowerLauncher.Plugin
private static readonly IDirectory Directory = FileSystem.Directory;
private static readonly object AllPluginsLock = new object();
private static readonly CompositeFormat FailedToInitializePluginsTitle = System.Text.CompositeFormat.Parse(Properties.Resources.FailedToInitializePluginsTitle);
private static IEnumerable<PluginPair> _contextMenuPlugins = new List<PluginPair>();
private static List<PluginPair> _allPlugins;
@@ -53,7 +56,7 @@ namespace PowerLauncher.Plugin
if (_allPlugins == null)
{
_allPlugins = PluginConfig.Parse(Directories)
.Where(x => x.Language.ToUpperInvariant() == AllowedLanguage.CSharp)
.Where(x => string.Equals(x.Language, AllowedLanguage.CSharp, StringComparison.OrdinalIgnoreCase))
.GroupBy(x => x.ID) // Deduplicates plugins by ID, choosing for each ID the highest DLL product version. This fixes issues such as https://github.com/microsoft/PowerToys/issues/14701
.Select(g => g.OrderByDescending(x => // , where an upgrade didn't remove older versions of the plugins.
{
@@ -178,10 +181,10 @@ namespace PowerLauncher.Plugin
_contextMenuPlugins = GetPluginsForInterface<IContextMenu>();
if (failedPlugins.Any())
if (!failedPlugins.IsEmpty)
{
var failed = string.Join(",", failedPlugins.Select(x => x.Metadata.Name));
var description = string.Format(CultureInfo.CurrentCulture, Resources.FailedToInitializePluginsDescription, failed);
var description = string.Format(CultureInfo.CurrentCulture, FailedToInitializePluginsTitle, failed);
Application.Current.Dispatcher.InvokeAsync(() => API.ShowMsg(Resources.FailedToInitializePluginsTitle, description, string.Empty, false));
}
}

View File

@@ -24,7 +24,7 @@ namespace PowerLauncher
// Watch for /Local/Microsoft/PowerToys/Launcher/Settings.json changes
public class SettingsReader : BaseModel
{
private readonly ISettingsUtils _settingsUtils;
private readonly SettingsUtils _settingsUtils;
private const int MaxRetries = 10;
private static readonly object _readSyncObject = new object();
@@ -286,7 +286,7 @@ namespace PowerLauncher
settings.Plugins = defaultPlugins.Values.ToList();
}
private static IEnumerable<PluginAdditionalOption> CombineAdditionalOptions(IEnumerable<PluginAdditionalOption> defaultAdditionalOptions, IEnumerable<PluginAdditionalOption> additionalOptions)
private static Dictionary<string, PluginAdditionalOption>.ValueCollection CombineAdditionalOptions(IEnumerable<PluginAdditionalOption> defaultAdditionalOptions, IEnumerable<PluginAdditionalOption> additionalOptions)
{
var defaultOptions = defaultAdditionalOptions.ToDictionary(x => x.Key);
foreach (var option in additionalOptions)

View File

@@ -8,6 +8,7 @@ using System.Collections.ObjectModel;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
@@ -63,6 +64,8 @@ namespace PowerLauncher.ViewModel
internal HotkeyManager HotkeyManager { get; private set; }
private static readonly CompositeFormat RegisterHotkeyFailed = System.Text.CompositeFormat.Parse(Properties.Resources.registerHotkeyFailed);
public MainViewModel(PowerToysRunSettings settings, CancellationToken nativeThreadCancelToken)
{
_saved = false;
@@ -897,7 +900,7 @@ namespace PowerLauncher.ViewModel
}
catch (Exception)
{
string errorMsg = string.Format(CultureInfo.InvariantCulture, Properties.Resources.registerHotkeyFailed, hotkeyStr);
string errorMsg = string.Format(CultureInfo.InvariantCulture, RegisterHotkeyFailed, hotkeyStr);
MessageBox.Show(errorMsg);
}
}

View File

@@ -127,7 +127,7 @@ namespace Wox.Infrastructure.Exception
foreach (string versionKeyName in ndpKey.GetSubKeyNames())
{
// Using InvariantCulture since this is internal and involves version key
if (versionKeyName.StartsWith("v", StringComparison.InvariantCulture))
if (versionKeyName.StartsWith('v'))
{
RegistryKey versionKey = ndpKey.OpenSubKey(versionKeyName);
string name = (string)versionKey.GetValue("Version", string.Empty);

View File

@@ -21,6 +21,15 @@ namespace Wox.Infrastructure
private static readonly IFileInfoFactory FileInfo = FileSystem.FileInfo;
private static readonly IDirectory Directory = FileSystem.Directory;
private static readonly JsonSerializerOptions _serializerOptions = new JsonSerializerOptions
{
WriteIndented = true,
Converters =
{
new JsonStringEnumConverter(),
},
};
/// <summary>
/// http://www.yinwang.org/blog-cn/2015/11/21/programming-philosophy
/// </summary>
@@ -81,14 +90,7 @@ namespace Wox.Infrastructure
public static string Formatted<T>(this T t)
{
var formatted = JsonSerializer.Serialize(t, new JsonSerializerOptions
{
WriteIndented = true,
Converters =
{
new JsonStringEnumConverter(),
},
});
var formatted = JsonSerializer.Serialize(t, _serializerOptions);
return formatted;
}

View File

@@ -29,7 +29,7 @@ namespace Wox.Infrastructure.Image
private static readonly ImageCache ImageCache = new ImageCache();
private static readonly ConcurrentDictionary<string, string> GuidToKey = new ConcurrentDictionary<string, string>();
private static IImageHashGenerator _hashGenerator;
private static ImageHashGenerator _hashGenerator;
public static string ErrorIconPath { get; set; } = Constant.LightThemedErrorIcon;

View File

@@ -44,7 +44,7 @@ namespace Wox.Infrastructure.Storage
public bool Any()
{
return _items.Any();
return !_items.IsEmpty;
}
public void Add(T insertedItem)

View File

@@ -29,6 +29,8 @@ namespace Wox.Infrastructure
public static StringMatcher Instance { get; internal set; }
private static readonly char[] Separator = new[] { ' ' };
[Obsolete("This method is obsolete and should not be used. Please use the static function StringMatcher.FuzzySearch")]
public static int Score(string source, string target)
{
@@ -104,7 +106,7 @@ namespace Wox.Infrastructure
var fullStringToCompareWithoutCase = opt.IgnoreCase ? stringToCompare.ToUpper(CultureInfo.InvariantCulture) : stringToCompare;
var queryWithoutCase = opt.IgnoreCase ? query.ToUpper(CultureInfo.InvariantCulture) : query;
var querySubstrings = queryWithoutCase.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
var querySubstrings = queryWithoutCase.Split(Separator, StringSplitOptions.RemoveEmptyEntries);
int currentQuerySubstringIndex = 0;
var currentQuerySubstring = querySubstrings[currentQuerySubstringIndex];
var currentQuerySubstringCharacterIndex = 0;

View File

@@ -24,8 +24,10 @@ namespace Wox.Plugin
ArgumentNullException.ThrowIfNull(language);
// Using InvariantCulture since this is a command line arg
return language.ToUpper(CultureInfo.InvariantCulture) == CSharp.ToUpper(CultureInfo.InvariantCulture)
|| language.ToUpper(CultureInfo.InvariantCulture) == Executable.ToUpper(CultureInfo.InvariantCulture);
var upperLanguage = language.ToUpper(CultureInfo.InvariantCulture);
return string.Equals(upperLanguage, CSharp.ToUpper(CultureInfo.InvariantCulture), StringComparison.Ordinal)
|| string.Equals(upperLanguage, Executable.ToUpper(CultureInfo.InvariantCulture), StringComparison.Ordinal);
}
}
}

View File

@@ -85,7 +85,7 @@ namespace Wox.Plugin.Common
if (appName != null)
{
// Handle indirect strings:
if (appName.StartsWith("@", StringComparison.Ordinal))
if (appName.StartsWith('@'))
{
appName = GetIndirectString(appName);
}

View File

@@ -6,6 +6,7 @@ using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text;
using Common.UI;
using Microsoft.Win32;
using Wox.Plugin.Common.VirtualDesktop.Interop;
@@ -54,6 +55,8 @@ namespace Wox.Plugin.Common.VirtualDesktop.Helper
/// </summary>
private Guid _currentDesktop;
private static readonly CompositeFormat VirtualDesktopHelperDesktop = System.Text.CompositeFormat.Parse(Properties.Resources.VirtualDesktopHelper_Desktop);
/// <summary>
/// Initializes a new instance of the <see cref="VirtualDesktopHelper"/> class.
/// </summary>
@@ -260,7 +263,7 @@ namespace Wox.Plugin.Common.VirtualDesktop.Helper
}
// If the desktop name was not changed by the user, it isn't saved to the registry. Then we need the default name for the desktop.
var defaultName = string.Format(System.Globalization.CultureInfo.InvariantCulture, Resources.VirtualDesktopHelper_Desktop, GetDesktopNumber(desktop));
var defaultName = string.Format(System.Globalization.CultureInfo.InvariantCulture, VirtualDesktopHelperDesktop, GetDesktopNumber(desktop));
string registryPath = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\VirtualDesktops\\Desktops\\{" + desktop.ToString().ToUpper(System.Globalization.CultureInfo.InvariantCulture) + "}";
using RegistryKey deskSubKey = Registry.CurrentUser.OpenSubKey(registryPath, false);