mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-02-23 19:49:43 +01:00
and another one
This commit is contained in:
@@ -2,10 +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.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
|
||||
namespace Microsoft.CommandPalette.Extensions.Toolkit;
|
||||
|
||||
@@ -25,9 +22,9 @@ public static partial class ClipboardHelper
|
||||
return _internalClipboard ?? string.Empty;
|
||||
}
|
||||
|
||||
var tool = string.Empty;
|
||||
var args = string.Empty;
|
||||
var clipboardText = string.Empty;
|
||||
string tool = string.Empty;
|
||||
string args = string.Empty;
|
||||
string? clipboardText = string.Empty;
|
||||
|
||||
ExecuteOnStaThread(() => GetTextImpl(out clipboardText));
|
||||
return clipboardText;
|
||||
@@ -41,8 +38,8 @@ public static partial class ClipboardHelper
|
||||
return;
|
||||
}
|
||||
|
||||
var tool = string.Empty;
|
||||
var args = string.Empty;
|
||||
string tool = string.Empty;
|
||||
string args = string.Empty;
|
||||
ExecuteOnStaThread(() => SetClipboardData(Tuple.Create(text, CF_UNICODETEXT)));
|
||||
return;
|
||||
}
|
||||
@@ -123,7 +120,7 @@ public static partial class ClipboardHelper
|
||||
{
|
||||
if (OpenClipboard(IntPtr.Zero))
|
||||
{
|
||||
var data = GetClipboardData(CF_UNICODETEXT);
|
||||
nint data = GetClipboardData(CF_UNICODETEXT);
|
||||
if (data != IntPtr.Zero)
|
||||
{
|
||||
data = GlobalLock(data);
|
||||
@@ -137,7 +134,7 @@ public static partial class ClipboardHelper
|
||||
{
|
||||
if (OpenClipboard(IntPtr.Zero))
|
||||
{
|
||||
var data = GetClipboardData(CF_TEXT);
|
||||
nint data = GetClipboardData(CF_TEXT);
|
||||
if (data != IntPtr.Zero)
|
||||
{
|
||||
data = GlobalLock(data);
|
||||
@@ -172,7 +169,7 @@ public static partial class ClipboardHelper
|
||||
|
||||
EmptyClipboard();
|
||||
|
||||
foreach (var d in data)
|
||||
foreach (Tuple<string, uint> d in data)
|
||||
{
|
||||
if (!SetSingleClipboardData(d.Item1, d.Item2))
|
||||
{
|
||||
@@ -190,8 +187,8 @@ public static partial class ClipboardHelper
|
||||
|
||||
private static bool SetSingleClipboardData(string text, uint format)
|
||||
{
|
||||
var hGlobal = IntPtr.Zero;
|
||||
var data = IntPtr.Zero;
|
||||
nint hGlobal = IntPtr.Zero;
|
||||
nint data = IntPtr.Zero;
|
||||
|
||||
try
|
||||
{
|
||||
@@ -217,13 +214,13 @@ public static partial class ClipboardHelper
|
||||
return false;
|
||||
}
|
||||
|
||||
hGlobal = GlobalAlloc(GHND, (UIntPtr)bytes);
|
||||
hGlobal = GlobalAlloc(GHND, bytes);
|
||||
if (hGlobal == IntPtr.Zero)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var dataCopy = GlobalLock(hGlobal);
|
||||
nint dataCopy = GlobalLock(hGlobal);
|
||||
if (dataCopy == IntPtr.Zero)
|
||||
{
|
||||
return false;
|
||||
@@ -261,7 +258,7 @@ public static partial class ClipboardHelper
|
||||
private static void ExecuteOnStaThread(Func<bool> action)
|
||||
{
|
||||
const int RetryCount = 5;
|
||||
var tries = 0;
|
||||
int tries = 0;
|
||||
|
||||
if (Thread.CurrentThread.GetApartmentState() == ApartmentState.STA)
|
||||
{
|
||||
@@ -274,7 +271,7 @@ public static partial class ClipboardHelper
|
||||
}
|
||||
|
||||
Exception? exception = null;
|
||||
var thread = new Thread(() =>
|
||||
Thread thread = new Thread(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
@@ -22,7 +22,7 @@ public partial class CommandContextItem : CommandItem, ICommandContextItem
|
||||
Action? action = null,
|
||||
ICommandResult? result = null)
|
||||
{
|
||||
var c = new AnonymousCommand(action);
|
||||
AnonymousCommand c = new AnonymousCommand(action);
|
||||
if (!string.IsNullOrEmpty(name))
|
||||
{
|
||||
c.Name = name;
|
||||
|
||||
@@ -92,7 +92,7 @@ public partial class CommandItem : BaseObservable, ICommandItem
|
||||
Action? action = null,
|
||||
ICommandResult? result = null)
|
||||
{
|
||||
var c = new AnonymousCommand(action);
|
||||
AnonymousCommand c = new AnonymousCommand(action);
|
||||
if (!string.IsNullOrEmpty(name))
|
||||
{
|
||||
c.Name = name;
|
||||
|
||||
@@ -21,7 +21,7 @@ public partial class DetailsLink : IDetailsLink
|
||||
|
||||
public DetailsLink(string url, string text)
|
||||
{
|
||||
if (Uri.TryCreate(url, default(UriCreationOptions), out var newUri))
|
||||
if (Uri.TryCreate(url, default(UriCreationOptions), out Uri? newUri))
|
||||
{
|
||||
Link = newUri;
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ public abstract class DynamicListPage : ListPage, IDynamicListPage
|
||||
get => base.SearchText;
|
||||
set
|
||||
{
|
||||
var oldSearch = base.SearchText;
|
||||
string oldSearch = base.SearchText;
|
||||
base.SearchText = value;
|
||||
UpdateSearchText(oldSearch, value);
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ public static partial class ExtensionHost
|
||||
|
||||
public static void LogMessage(string message)
|
||||
{
|
||||
var logMessage = new LogMessage() { Message = message };
|
||||
LogMessage logMessage = new LogMessage() { Message = message };
|
||||
LogMessage(logMessage);
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ internal sealed partial class ExtensionInstanceManager : IClassFactory
|
||||
|
||||
// Known constant ignored by win32metadata and cswin32 projections.
|
||||
// https://github.com/microsoft/win32metadata/blob/main/generation/WinSDK/RecompiledIdlHeaders/um/processthreadsapi.h
|
||||
private static readonly HANDLE CURRENT_THREAD_PSEUDO_HANDLE = (HANDLE)(IntPtr)(-6);
|
||||
private static readonly HANDLE CURRENT_THREAD_PSEUDO_HANDLE = (HANDLE)(-6);
|
||||
|
||||
private static readonly Guid IID_IUnknown = Guid.Parse("00000000-0000-0000-C000-000000000046");
|
||||
|
||||
@@ -63,8 +63,8 @@ internal sealed partial class ExtensionInstanceManager : IClassFactory
|
||||
if (riid == _clsid || riid == IID_IUnknown)
|
||||
{
|
||||
// Create the instance of the .NET object
|
||||
var managed = _createExtension();
|
||||
var ins = MarshalInspectable<object>.FromManaged(managed);
|
||||
IExtension managed = _createExtension();
|
||||
nint ins = MarshalInspectable<object>.FromManaged(managed);
|
||||
ppvObject = ins;
|
||||
}
|
||||
else
|
||||
@@ -92,7 +92,7 @@ internal sealed partial class ExtensionInstanceManager : IClassFactory
|
||||
return false;
|
||||
}
|
||||
|
||||
var value = new char[buffer];
|
||||
char[] value = new char[buffer];
|
||||
fixed (char* p = value)
|
||||
{
|
||||
if (PInvoke.GetPackageFamilyNameFromToken(CURRENT_THREAD_PSEUDO_HANDLE, &buffer, p) != 0)
|
||||
@@ -106,7 +106,7 @@ internal sealed partial class ExtensionInstanceManager : IClassFactory
|
||||
return false;
|
||||
}
|
||||
|
||||
var valueStr = new string(value);
|
||||
string valueStr = new string(value);
|
||||
return valueStr switch
|
||||
{
|
||||
"Microsoft.Windows.CmdPal_8wekyb3d8bbwe\0" or "Microsoft.Windows.CmdPal.Canary_8wekyb3d8bbwe\0" or "Microsoft.Windows.CmdPal.Dev_8wekyb3d8bbwe\0" or "Microsoft.Windows.DevHome_8wekyb3d8bbwe\0" or "Microsoft.Windows.DevHome.Canary_8wekyb3d8bbwe\0" or "Microsoft.Windows.DevHome.Dev_8wekyb3d8bbwe\0" or "Microsoft.WindowsTerminal\0" or "Microsoft.WindowsTerminal_8wekyb3d8bbwe\0" or "WindowsTerminalDev_8wekyb3d8bbwe\0" or "Microsoft.WindowsTerminalPreview_8wekyb3d8bbwe\0" => true,
|
||||
|
||||
@@ -34,7 +34,7 @@ public partial class IconInfo : IIconInfo
|
||||
|
||||
public static IconInfo FromStream(IRandomAccessStream stream)
|
||||
{
|
||||
var data = new IconData(RandomAccessStreamReference.CreateFromStream(stream));
|
||||
IconData data = new IconData(RandomAccessStreamReference.CreateFromStream(stream));
|
||||
return new IconInfo(data, data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using Windows.Foundation;
|
||||
|
||||
namespace Microsoft.CommandPalette.Extensions.Toolkit;
|
||||
|
||||
public partial class ItemsChangedEventArgs : IItemsChangedEventArgs
|
||||
|
||||
@@ -25,7 +25,7 @@ public abstract class JsonSettingsManager
|
||||
throw new InvalidOperationException($"You must set a valid {nameof(FilePath)} before calling {nameof(LoadSettings)}");
|
||||
}
|
||||
|
||||
var filePath = FilePath;
|
||||
string filePath = FilePath;
|
||||
if (!File.Exists(filePath))
|
||||
{
|
||||
ExtensionHost.LogMessage(new LogMessage() { Message = "The provided settings file does not exist" });
|
||||
@@ -35,7 +35,7 @@ public abstract class JsonSettingsManager
|
||||
try
|
||||
{
|
||||
// Read the JSON content from the file
|
||||
var jsonContent = File.ReadAllText(filePath);
|
||||
string jsonContent = File.ReadAllText(filePath);
|
||||
|
||||
// Is it valid JSON?
|
||||
if (JsonNode.Parse(jsonContent) is JsonObject savedSettings)
|
||||
@@ -63,23 +63,23 @@ public abstract class JsonSettingsManager
|
||||
try
|
||||
{
|
||||
// Serialize the main dictionary to JSON and save it to the file
|
||||
var settingsJson = Settings.ToJson();
|
||||
string settingsJson = Settings.ToJson();
|
||||
|
||||
// Is it valid JSON?
|
||||
if (JsonNode.Parse(settingsJson) is JsonObject newSettings)
|
||||
{
|
||||
// Now, read the existing content from the file
|
||||
var oldContent = File.Exists(FilePath) ? File.ReadAllText(FilePath) : "{}";
|
||||
string oldContent = File.Exists(FilePath) ? File.ReadAllText(FilePath) : "{}";
|
||||
|
||||
// Is it valid JSON?
|
||||
if (JsonNode.Parse(oldContent) is JsonObject savedSettings)
|
||||
{
|
||||
foreach (var item in newSettings)
|
||||
foreach (KeyValuePair<string, JsonNode?> item in newSettings)
|
||||
{
|
||||
savedSettings[item.Key] = item.Value?.DeepClone();
|
||||
}
|
||||
|
||||
var serialized = savedSettings.ToJsonString(_serializerOptions);
|
||||
string serialized = savedSettings.ToJsonString(_serializerOptions);
|
||||
File.WriteAllText(FilePath, serialized);
|
||||
}
|
||||
else
|
||||
|
||||
@@ -16,7 +16,7 @@ public static partial class KeyChordHelpers
|
||||
int vkey = 0,
|
||||
int scanCode = 0)
|
||||
{
|
||||
var modifiers = (ctrl ? VirtualKeyModifiers.Control : VirtualKeyModifiers.None)
|
||||
VirtualKeyModifiers modifiers = (ctrl ? VirtualKeyModifiers.Control : VirtualKeyModifiers.None)
|
||||
| (alt ? VirtualKeyModifiers.Menu : VirtualKeyModifiers.None)
|
||||
| (shift ? VirtualKeyModifiers.Shift : VirtualKeyModifiers.None)
|
||||
| (win ? VirtualKeyModifiers.Windows : VirtualKeyModifiers.None)
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Microsoft.CommandPalette.Extensions.Toolkit;
|
||||
|
||||
public partial class MatchOption
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
// 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.CompilerServices;
|
||||
|
||||
namespace Microsoft.CommandPalette.Extensions.Toolkit;
|
||||
|
||||
public partial class MatchResult
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using Windows.Foundation;
|
||||
|
||||
namespace Microsoft.CommandPalette.Extensions.Toolkit;
|
||||
|
||||
public partial class PropChangedEventArgs : IPropChangedEventArgs
|
||||
|
||||
@@ -35,19 +35,19 @@ public sealed partial class Settings : ICommandSettings
|
||||
|
||||
internal string ToFormJson()
|
||||
{
|
||||
var settings = _settings
|
||||
IEnumerable<ISettingsForm> settings = _settings
|
||||
.Values
|
||||
.Where(s => s is ISettingsForm)
|
||||
.Select(s => s as ISettingsForm)
|
||||
.Where(s => s != null)
|
||||
.Select(s => s!);
|
||||
|
||||
var bodies = string.Join(",", settings
|
||||
string bodies = string.Join(",", settings
|
||||
.Select(s => JsonSerializer.Serialize(s.ToDictionary(), JsonSerializationContext.Default.Dictionary)));
|
||||
|
||||
var datas = string.Join(",", settings.Select(s => s.ToDataIdentifier()));
|
||||
string datas = string.Join(",", settings.Select(s => s.ToDataIdentifier()));
|
||||
|
||||
var json = $$"""
|
||||
string json = $$"""
|
||||
{
|
||||
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
|
||||
"type": "AdaptiveCard",
|
||||
@@ -71,27 +71,27 @@ public sealed partial class Settings : ICommandSettings
|
||||
|
||||
public string ToJson()
|
||||
{
|
||||
var settings = _settings
|
||||
IEnumerable<ISettingsForm> settings = _settings
|
||||
.Values
|
||||
.Where(s => s is ISettingsForm)
|
||||
.Select(s => s as ISettingsForm)
|
||||
.Where(s => s != null)
|
||||
.Select(s => s!);
|
||||
var content = string.Join(",\n", settings.Select(s => s.ToState()));
|
||||
string content = string.Join(",\n", settings.Select(s => s.ToState()));
|
||||
return $"{{\n{content}\n}}";
|
||||
}
|
||||
|
||||
public void Update(string data)
|
||||
{
|
||||
var formInput = JsonNode.Parse(data)?.AsObject();
|
||||
JsonObject? formInput = JsonNode.Parse(data)?.AsObject();
|
||||
if (formInput == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var key in _settings.Keys)
|
||||
foreach (string key in _settings.Keys)
|
||||
{
|
||||
var value = _settings[key];
|
||||
object value = _settings[key];
|
||||
if (value is ISettingsForm f)
|
||||
{
|
||||
f.Update(formInput);
|
||||
@@ -101,7 +101,7 @@ public sealed partial class Settings : ICommandSettings
|
||||
|
||||
internal void RaiseSettingsChanged()
|
||||
{
|
||||
var handlers = SettingsChanged;
|
||||
TypedEventHandler<object, Settings>? handlers = SettingsChanged;
|
||||
handlers?.Invoke(this, this);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ public partial class SettingsForm : FormContent
|
||||
|
||||
public override ICommandResult SubmitForm(string inputs, string data)
|
||||
{
|
||||
var formInput = JsonNode.Parse(inputs)?.AsObject();
|
||||
JsonObject? formInput = JsonNode.Parse(inputs)?.AsObject();
|
||||
if (formInput == null)
|
||||
{
|
||||
return CommandResult.KeepOpen();
|
||||
|
||||
@@ -25,7 +25,7 @@ public static class ShellHelpers
|
||||
|
||||
public static bool OpenInShell(string? path, string? arguments = null, string? workingDir = null, ShellRunAsType runAs = ShellRunAsType.None, bool runWithHiddenWindow = false)
|
||||
{
|
||||
using var process = new Process();
|
||||
using Process process = new Process();
|
||||
process.StartInfo.FileName = path;
|
||||
process.StartInfo.WorkingDirectory = string.IsNullOrWhiteSpace(workingDir) ? string.Empty : workingDir;
|
||||
process.StartInfo.Arguments = string.IsNullOrWhiteSpace(arguments) ? string.Empty : arguments;
|
||||
|
||||
@@ -26,7 +26,7 @@ public partial class ShowFileInFolderCommand : InvokableCommand
|
||||
{
|
||||
try
|
||||
{
|
||||
var argument = "/select, \"" + _path + "\"";
|
||||
string argument = "/select, \"" + _path + "\"";
|
||||
Process.Start("explorer.exe", argument);
|
||||
}
|
||||
catch (Exception)
|
||||
|
||||
@@ -68,9 +68,9 @@ public partial class StringMatcher
|
||||
return new MatchResult(false, UserSettingSearchPrecision);
|
||||
}
|
||||
|
||||
var bestResult = new MatchResult(false, UserSettingSearchPrecision);
|
||||
MatchResult bestResult = new MatchResult(false, UserSettingSearchPrecision);
|
||||
|
||||
for (var startIndex = 0; startIndex < stringToCompare.Length; startIndex++)
|
||||
for (int startIndex = 0; startIndex < stringToCompare.Length; startIndex++)
|
||||
{
|
||||
MatchResult result = FuzzyMatch(query, stringToCompare, opt, startIndex);
|
||||
if (result.Success && (!bestResult.Success || result.Score > bestResult.Score))
|
||||
@@ -100,25 +100,25 @@ public partial class StringMatcher
|
||||
// }
|
||||
|
||||
// Using InvariantCulture since this is internal
|
||||
var fullStringToCompareWithoutCase = opt.IgnoreCase ? stringToCompare.ToUpper(CultureInfo.InvariantCulture) : stringToCompare;
|
||||
var queryWithoutCase = opt.IgnoreCase ? query.ToUpper(CultureInfo.InvariantCulture) : query;
|
||||
string fullStringToCompareWithoutCase = opt.IgnoreCase ? stringToCompare.ToUpper(CultureInfo.InvariantCulture) : stringToCompare;
|
||||
string queryWithoutCase = opt.IgnoreCase ? query.ToUpper(CultureInfo.InvariantCulture) : query;
|
||||
|
||||
var querySubstrings = queryWithoutCase.Split(Separator, StringSplitOptions.RemoveEmptyEntries);
|
||||
var currentQuerySubstringIndex = 0;
|
||||
var currentQuerySubstring = querySubstrings[currentQuerySubstringIndex];
|
||||
var currentQuerySubstringCharacterIndex = 0;
|
||||
string[] querySubstrings = queryWithoutCase.Split(Separator, StringSplitOptions.RemoveEmptyEntries);
|
||||
int currentQuerySubstringIndex = 0;
|
||||
string currentQuerySubstring = querySubstrings[currentQuerySubstringIndex];
|
||||
int currentQuerySubstringCharacterIndex = 0;
|
||||
|
||||
var firstMatchIndex = -1;
|
||||
var firstMatchIndexInWord = -1;
|
||||
var lastMatchIndex = 0;
|
||||
var allQuerySubstringsMatched = false;
|
||||
var matchFoundInPreviousLoop = false;
|
||||
var allSubstringsContainedInCompareString = true;
|
||||
int firstMatchIndex = -1;
|
||||
int firstMatchIndexInWord = -1;
|
||||
int lastMatchIndex = 0;
|
||||
bool allQuerySubstringsMatched = false;
|
||||
bool matchFoundInPreviousLoop = false;
|
||||
bool allSubstringsContainedInCompareString = true;
|
||||
|
||||
var indexList = new List<int>();
|
||||
List<int> indexList = new List<int>();
|
||||
List<int> spaceIndices = new List<int>();
|
||||
|
||||
for (var compareStringIndex = startIndex; compareStringIndex < fullStringToCompareWithoutCase.Length; compareStringIndex++)
|
||||
for (int compareStringIndex = startIndex; compareStringIndex < fullStringToCompareWithoutCase.Length; compareStringIndex++)
|
||||
{
|
||||
// To maintain a list of indices which correspond to spaces in the string to compare
|
||||
// To populate the list only for the first query substring
|
||||
@@ -130,8 +130,8 @@ public partial class StringMatcher
|
||||
bool compareResult;
|
||||
if (opt.IgnoreCase)
|
||||
{
|
||||
var fullStringToCompare = fullStringToCompareWithoutCase[compareStringIndex].ToString();
|
||||
var querySubstring = currentQuerySubstring[currentQuerySubstringCharacterIndex].ToString();
|
||||
string fullStringToCompare = fullStringToCompareWithoutCase[compareStringIndex].ToString();
|
||||
string querySubstring = currentQuerySubstring[currentQuerySubstringCharacterIndex].ToString();
|
||||
#pragma warning disable CA1309 // Use ordinal string comparison (We are looking for a fuzzy match here)
|
||||
compareResult = string.Compare(fullStringToCompare, querySubstring, CultureInfo.CurrentCulture, CompareOptions.IgnoreCase | CompareOptions.IgnoreNonSpace) != 0;
|
||||
#pragma warning restore CA1309 // Use ordinal string comparison
|
||||
@@ -163,7 +163,7 @@ public partial class StringMatcher
|
||||
{
|
||||
// we want to verify that there is not a better match if this is not a full word
|
||||
// in order to do so we need to verify all previous chars are part of the pattern
|
||||
var startIndexToVerify = compareStringIndex - currentQuerySubstringCharacterIndex;
|
||||
int startIndexToVerify = compareStringIndex - currentQuerySubstringCharacterIndex;
|
||||
|
||||
if (AllPreviousCharsMatched(startIndexToVerify, currentQuerySubstringCharacterIndex, fullStringToCompareWithoutCase, currentQuerySubstring))
|
||||
{
|
||||
@@ -204,8 +204,8 @@ public partial class StringMatcher
|
||||
// proceed to calculate score if every char or substring without whitespaces matched
|
||||
if (allQuerySubstringsMatched)
|
||||
{
|
||||
var nearestSpaceIndex = CalculateClosestSpaceIndex(spaceIndices, firstMatchIndex);
|
||||
var score = CalculateSearchScore(query, stringToCompare, firstMatchIndex - nearestSpaceIndex - 1, lastMatchIndex - firstMatchIndex, allSubstringsContainedInCompareString);
|
||||
int nearestSpaceIndex = CalculateClosestSpaceIndex(spaceIndices, firstMatchIndex);
|
||||
int score = CalculateSearchScore(query, stringToCompare, firstMatchIndex - nearestSpaceIndex - 1, lastMatchIndex - firstMatchIndex, allSubstringsContainedInCompareString);
|
||||
|
||||
return new MatchResult(true, UserSettingSearchPrecision, indexList, score);
|
||||
}
|
||||
@@ -222,14 +222,14 @@ public partial class StringMatcher
|
||||
}
|
||||
else
|
||||
{
|
||||
return spaceIndices.OrderBy(item => (firstMatchIndex - item)).Where(item => firstMatchIndex > item).FirstOrDefault(-1);
|
||||
return spaceIndices.OrderBy(item => firstMatchIndex - item).Where(item => firstMatchIndex > item).FirstOrDefault(-1);
|
||||
}
|
||||
}
|
||||
|
||||
private static bool AllPreviousCharsMatched(int startIndexToVerify, int currentQuerySubstringCharacterIndex, string fullStringToCompareWithoutCase, string currentQuerySubstring)
|
||||
{
|
||||
var allMatch = true;
|
||||
for (var indexToCheck = 0; indexToCheck < currentQuerySubstringCharacterIndex; indexToCheck++)
|
||||
bool allMatch = true;
|
||||
for (int indexToCheck = 0; indexToCheck < currentQuerySubstringCharacterIndex; indexToCheck++)
|
||||
{
|
||||
if (fullStringToCompareWithoutCase[startIndexToVerify + indexToCheck] !=
|
||||
currentQuerySubstring[indexToCheck])
|
||||
@@ -243,13 +243,13 @@ public partial class StringMatcher
|
||||
|
||||
private static List<int> GetUpdatedIndexList(int startIndexToVerify, int currentQuerySubstringCharacterIndex, int firstMatchIndexInWord, List<int> indexList)
|
||||
{
|
||||
var updatedList = new List<int>();
|
||||
List<int> updatedList = new List<int>();
|
||||
|
||||
indexList.RemoveAll(x => x >= firstMatchIndexInWord);
|
||||
|
||||
updatedList.AddRange(indexList);
|
||||
|
||||
for (var indexToCheck = 0; indexToCheck < currentQuerySubstringCharacterIndex; indexToCheck++)
|
||||
for (int indexToCheck = 0; indexToCheck < currentQuerySubstringCharacterIndex; indexToCheck++)
|
||||
{
|
||||
updatedList.Add(startIndexToVerify + indexToCheck);
|
||||
}
|
||||
@@ -272,7 +272,7 @@ public partial class StringMatcher
|
||||
// I.e. the length is more important than the location where a match is found.
|
||||
const int matchLenWeightFactor = 2;
|
||||
|
||||
var score = 100 * (query.Length + 1) * matchLenWeightFactor / ((1 + firstIndex) + (matchLenWeightFactor * (matchLen + 1)));
|
||||
int score = 100 * (query.Length + 1) * matchLenWeightFactor / (1 + firstIndex + (matchLenWeightFactor * (matchLen + 1)));
|
||||
|
||||
// A match with less characters assigning more weights
|
||||
if (stringToCompare.Length - query.Length < 5)
|
||||
@@ -286,8 +286,8 @@ public partial class StringMatcher
|
||||
|
||||
if (allSubstringsContainedInCompareString)
|
||||
{
|
||||
var count = query.Count(c => !char.IsWhiteSpace(c));
|
||||
var threshold = 4;
|
||||
int count = query.Count(c => !char.IsWhiteSpace(c));
|
||||
int threshold = 4;
|
||||
if (count <= threshold)
|
||||
{
|
||||
score += count * 10;
|
||||
@@ -301,7 +301,7 @@ public partial class StringMatcher
|
||||
#pragma warning disable CA1309 // Use ordinal string comparison (Using CurrentCultureIgnoreCase since this relates to queries input by user)
|
||||
if (string.Equals(query, stringToCompare, StringComparison.CurrentCultureIgnoreCase))
|
||||
{
|
||||
var bonusForExactMatch = 10;
|
||||
int bonusForExactMatch = 10;
|
||||
score += bonusForExactMatch;
|
||||
}
|
||||
#pragma warning restore CA1309 // Use ordinal string comparison
|
||||
|
||||
@@ -26,7 +26,7 @@ public static class ThumbnailHelper
|
||||
|
||||
public static Task<IRandomAccessStream?> GetThumbnail(string path, bool jumbo = false)
|
||||
{
|
||||
var extension = Path.GetExtension(path).ToLower(CultureInfo.InvariantCulture);
|
||||
string extension = Path.GetExtension(path).ToLower(CultureInfo.InvariantCulture);
|
||||
try
|
||||
{
|
||||
return ImageExtensions.Contains(extension) ? GetImageThumbnailAsync(path) : GetFileIconStream(path, jumbo);
|
||||
@@ -53,10 +53,10 @@ public static class ThumbnailHelper
|
||||
// Duplicate it if you need it again after this.
|
||||
private static MemoryStream GetMemoryStreamFromIcon(IntPtr hIcon)
|
||||
{
|
||||
var memoryStream = new MemoryStream();
|
||||
MemoryStream memoryStream = new MemoryStream();
|
||||
|
||||
// Ensure disposing the icon before freeing the handle
|
||||
using (var icon = Icon.FromHandle(hIcon))
|
||||
using (Icon icon = Icon.FromHandle(hIcon))
|
||||
{
|
||||
icon.ToBitmap().Save(memoryStream, System.Drawing.Imaging.ImageFormat.Png);
|
||||
}
|
||||
@@ -82,9 +82,9 @@ public static class ThumbnailHelper
|
||||
// the normal icon lookup
|
||||
if (hIcon == 0)
|
||||
{
|
||||
var shinfo = default(NativeMethods.SHFILEINFO);
|
||||
NativeMethods.SHFILEINFO shinfo = default(NativeMethods.SHFILEINFO);
|
||||
|
||||
var hr = NativeMethods.SHGetFileInfo(filePath, 0, ref shinfo, (uint)Marshal.SizeOf(shinfo), SHGFI_ICON | SHGFI_SHELLICONSIZE);
|
||||
nint hr = NativeMethods.SHGetFileInfo(filePath, 0, ref shinfo, (uint)Marshal.SizeOf(shinfo), SHGFI_ICON | SHGFI_SHELLICONSIZE);
|
||||
|
||||
if (hr == 0 || shinfo.hIcon == 0)
|
||||
{
|
||||
@@ -99,11 +99,11 @@ public static class ThumbnailHelper
|
||||
return null;
|
||||
}
|
||||
|
||||
var stream = new InMemoryRandomAccessStream();
|
||||
InMemoryRandomAccessStream stream = new InMemoryRandomAccessStream();
|
||||
|
||||
using var memoryStream = GetMemoryStreamFromIcon(hIcon); // this will DestroyIcon hIcon
|
||||
using var outputStream = stream.GetOutputStreamAt(0);
|
||||
using (var dataWriter = new DataWriter(outputStream))
|
||||
using MemoryStream memoryStream = GetMemoryStreamFromIcon(hIcon); // this will DestroyIcon hIcon
|
||||
using IOutputStream outputStream = stream.GetOutputStreamAt(0);
|
||||
using (DataWriter dataWriter = new DataWriter(outputStream))
|
||||
{
|
||||
dataWriter.WriteBytes(memoryStream.ToArray());
|
||||
await dataWriter.StoreAsync();
|
||||
@@ -115,18 +115,18 @@ public static class ThumbnailHelper
|
||||
|
||||
private static async Task<IRandomAccessStream?> GetImageThumbnailAsync(string filePath)
|
||||
{
|
||||
var file = await StorageFile.GetFileFromPathAsync(filePath);
|
||||
var thumbnail = await file.GetThumbnailAsync(ThumbnailMode.PicturesView);
|
||||
StorageFile file = await StorageFile.GetFileFromPathAsync(filePath);
|
||||
StorageItemThumbnail thumbnail = await file.GetThumbnailAsync(ThumbnailMode.PicturesView);
|
||||
return thumbnail;
|
||||
}
|
||||
|
||||
private static nint GetLargestIcon(string path)
|
||||
{
|
||||
var shinfo = default(NativeMethods.SHFILEINFO);
|
||||
NativeMethods.SHFILEINFO shinfo = default(NativeMethods.SHFILEINFO);
|
||||
NativeMethods.SHGetFileInfo(path, 0, ref shinfo, (uint)Marshal.SizeOf(shinfo), SHGFI_SYSICONINDEX);
|
||||
|
||||
var hIcon = IntPtr.Zero;
|
||||
var iID_IImageList = new Guid("46EB5926-582E-4017-9FDF-E8998DAA0950");
|
||||
nint hIcon = IntPtr.Zero;
|
||||
Guid iID_IImageList = new Guid("46EB5926-582E-4017-9FDF-E8998DAA0950");
|
||||
|
||||
if (NativeMethods.SHGetImageList(SHIL_JUMBO, ref iID_IImageList, out nint imageListPtr) == 0 && imageListPtr != IntPtr.Zero)
|
||||
{
|
||||
|
||||
@@ -46,15 +46,15 @@ public sealed class ToggleSetting : Setting<bool>
|
||||
if (payload[Key] != null)
|
||||
{
|
||||
// Adaptive cards returns boolean values as a string "true"/"false", cause of course.
|
||||
var strFromJson = payload[Key]?.GetValue<string>() ?? string.Empty;
|
||||
var val = strFromJson switch { "true" => true, "false" => false, _ => false };
|
||||
string strFromJson = payload[Key]?.GetValue<string>() ?? string.Empty;
|
||||
bool val = strFromJson switch { "true" => true, "false" => false, _ => false };
|
||||
Value = val;
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToState()
|
||||
{
|
||||
var adaptiveCardsUsesStringsForBools = Value ? "true" : "false";
|
||||
string adaptiveCardsUsesStringsForBools = Value ? "true" : "false";
|
||||
return $"\"{Key}\": \"{adaptiveCardsUsesStringsForBools}\"";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,16 +34,16 @@ public static class Utilities
|
||||
// KF_FLAG_FORCE_APP_DATA_REDIRECTION, when engaged, causes SHGet... to return
|
||||
// the new AppModel paths (Packages/xxx/RoamingState, etc.) for standard path requests.
|
||||
// Using this flag allows us to avoid Windows.Storage.ApplicationData completely.
|
||||
var FOLDERID_LocalAppData = new Guid("F1B32785-6FBA-4FCF-9D55-7B8E7F157091");
|
||||
var hr = PInvoke.SHGetKnownFolderPath(
|
||||
Guid FOLDERID_LocalAppData = new Guid("F1B32785-6FBA-4FCF-9D55-7B8E7F157091");
|
||||
HRESULT hr = PInvoke.SHGetKnownFolderPath(
|
||||
FOLDERID_LocalAppData,
|
||||
KNOWN_FOLDER_FLAG.KF_FLAG_FORCE_APP_DATA_REDIRECTION,
|
||||
null,
|
||||
out var localAppDataFolder);
|
||||
out PWSTR localAppDataFolder);
|
||||
|
||||
if (hr.Succeeded)
|
||||
{
|
||||
var basePath = new string(localAppDataFolder.ToString());
|
||||
string basePath = new string(localAppDataFolder.ToString());
|
||||
if (!IsPackaged())
|
||||
{
|
||||
basePath = Path.Combine(basePath, settingsFolderName);
|
||||
@@ -64,10 +64,10 @@ public static class Utilities
|
||||
public static bool IsPackaged()
|
||||
{
|
||||
uint bufferSize = 0;
|
||||
var bytes = Array.Empty<byte>();
|
||||
byte[] bytes = Array.Empty<byte>();
|
||||
|
||||
// CsWinRT apparently won't generate this constant
|
||||
var APPMODEL_ERROR_NO_PACKAGE = (WIN32_ERROR)15700;
|
||||
WIN32_ERROR APPMODEL_ERROR_NO_PACKAGE = (WIN32_ERROR)15700;
|
||||
unsafe
|
||||
{
|
||||
fixed (byte* p = bytes)
|
||||
@@ -75,7 +75,7 @@ public static class Utilities
|
||||
// We don't actually need the package ID. We just need to know
|
||||
// if we have a package or not, and APPMODEL_ERROR_NO_PACKAGE
|
||||
// is a quick way to find out.
|
||||
var win32Error = PInvoke.GetCurrentPackageId(ref bufferSize, p);
|
||||
WIN32_ERROR win32Error = PInvoke.GetCurrentPackageId(ref bufferSize, p);
|
||||
return win32Error != APPMODEL_ERROR_NO_PACKAGE;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user