Files
PowerToys/src/modules/launcher/Plugins/Microsoft.Plugin.WindowWalker/Components/FuzzyMatching.cs

148 lines
5.4 KiB
C#
Raw Normal View History

2020-08-17 10:00:56 -07:00
// 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.
// Code forked from Betsegaw Tadele's https://github.com/betsegaw/windowwalker/
Adding FxCop to Microsoft.Plugin.WindowWalker (#6260) * Adding FxCop to Microsoft.Plugin.WindowWalker * Delete WindowResult.cs -- Fix for CA1812 WindowResult is an internal class that is apparently never instantiated. If so, remove the code from the assembly. If this class is intended to contain only static members, make it static (Shared in Visual Basic). * Fix for CA1806 UpdateOpenWindowsList calls EnumWindows but does not use the HRESULT or error code that the method returns. This could lead to unexpected behavior in error conditions or low-resource situations. Use the result in a conditional statement, assign the result to a variable, or pass it as an argument to another method. * Fix for: CA1066 Type Microsoft.Plugin.WindowWalker.Components.InteropAndHelpers.RECT should implement IEquatable<T> because it overrides Equals * Fix for: CA1052 Type 'FuzzyMatching' is a static holder type but is neither static nor NotInheritable * Suppress for CA1069 - These values are defined in https://docs.microsoft.com/en-us/windows/win32/winmsg/extended-window-styles. CA1069 The enum member 'WS_EX_LTRREADING' has the same constant value '0' as member 'WS_EX_LEFT' CA1069 The enum member 'WS_EX_RIGHTSCROLLBAR' has the same constant value '0' as member 'WS_EX_LEFT' * Supress CA1069 Code Description CA1069 The enum member 'SWP_NOREPOSITION' has the same constant value '512' as member 'SWP_NOOWNERZORDER' CA1069 The enum member 'SWP_FRAMECHANGED' has the same constant value '32' as member 'SWP_DRAWFRAME' * Suprress CA1069 for ShowWindow values. See https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-showwindow CA1069 The enum member 'ShowMaximized' has the same constant value '3' as member 'Maximize' * Fix code formatting error * Fix for CA2235: Making POINT serializable CA2235 Field MinPosition is a member of type WINDOWPLACEMENT which is serializable but is of type Microsoft.Plugin.WindowWalker.Components.InteropAndHelpers.POINT which is not serializable CA2235 Field MaxPosition is a member of type WINDOWPLACEMENT which is serializable but is of type Microsoft.Plugin.WindowWalker.Components.InteropAndHelpers.POINT which is not serializable * Fix CA2235 Making RECT serializable CA2235 Field NormalPosition is a member of type WINDOWPLACEMENT which is serializable but is of type Microsoft.Plugin.WindowWalker.Components.InteropAndHelpers.RECT which is not serializable * Fixes for CA2101 Specify marshaling for P/Invoke string arguments. * Fixes for CA2007 Consider calling ConfigureAwait on the awaited task * Fixes for the following (CA1822 / CA1801): CA1822 Member 'OnOpenWindowsUpdate' does not access instance data and can be marked as static Code Description CA1801 Parameter value of method add_OnOpenWindowsUpdate is never used. Remove the parameter or use it in the method body. CA1801 Parameter value of method remove_OnOpenWindowsUpdate is never used. Remove the parameter or use it in the method body. * Fix: CA1710 Rename OpenWindowsUpdateHandler to end in 'EventHandler' * Fix CA1822 Member 'GetProcessIDFromWindowHandle' does not access instance data and can be marked as static * Fix CA1062 In externally visible method 'List<int> FuzzyMatching.FindBestFuzzyMatch(string text, string searchText)', validate parameter 'searchText' is non-null before using it. If appropriate, throw an ArgumentNullException when the argument is null or add a Code Contract precondition asserting non-null argument. * Fixes for CA1304 The behavior of 'string.ToLower()' could vary based on the current user's locale settings. CA1304 The behavior of 'string.ToLower()' could vary based on the current user's locale settings. Replace this call in 'FuzzyMatching.FindBestFuzzyMatch(string, string)' with a call to 'string.ToLower(CultureInfo)'. Code Description CA1304 The behavior of 'string.ToLower()' could vary based on the current user's locale settings. Replace this call in 'FuzzyMatching.FindBestFuzzyMatch(string, string)' with a call to 'string.ToLower(CultureInfo)'. * Supressing warning for CA1814: Prefer jagged arrays over multidimensional however this might be something to consider if needing to optimize the window walker search. * Fix: CA1062 In externally visible method 'List<List<int>> FuzzyMatching.GetAllMatchIndexes(bool[,] matches)', validate parameter 'matches' is non-null before using it. If appropriate, throw an ArgumentNullException when the argument is null or add a Code Contract precondition asserting non-null argument. * Fix for CA1062 In externally visible method 'int FuzzyMatching.CalculateScoreForMatches(List<int> matches)', validate parameter 'matches' is non-null before using it. If appropriate, throw an ArgumentNullException when the argument is null or add a Code Contract precondition asserting non-null argument. * Fixes for CA1806 Calls x... but does not use the HRESULT or error code that the method returns. This could lead to unexpected behavior in error conditions or low-resource situations. Use the result in a conditional statement, assign the result to a variable, or pass it as an argument to another method. Using discard for methods that return void, and checking the hresult before returning parameters. * Fix for CA1820 Test for empty strings using 'string.Length' property or 'string.IsNullOrEmpty' method instead of an Equality check * Supress CA1031 Modify 'get_WindowIcon' to catch a more specific allowed exception type, or rethrow the exception * Code Description CA1062 In externally visible method 'List<Result> Main.Query(Query query)', validate parameter 'query' is non-null before using it. If appropriate, throw an ArgumentNullException when the argument is null or add a Code Contract precondition asserting non-null argument. * Fixes For CA1304 The behavior of 'string.ToUpper()' could vary based on the current user's locale settings. CA1304 The behavior of 'string.ToLower()' could vary based on the current user's locale settings. Replace this call in 'SearchController.SearchText.set' with a call to 'string.ToLower(CultureInfo)'. CA1304 The behavior of 'string.ToLower()' could vary based on the current user's locale settings. Replace this call in 'Window.ProcessName.get' with a call to 'string.ToLower(CultureInfo)'. CA1304 The behavior of 'string.ToLower()' could vary based on the current user's locale settings. Replace this call in 'Window.SwitchToWindow()' with a call to 'string.ToLower(CultureInfo)'. CA1304 The behavior of 'string.ToUpper()' could vary based on the current user's locale settings. Replace this call in 'Window.ToString()' with a call to 'string.ToUpper(CultureInfo)'. CA1307 The behavior of 'string.Equals(string?)' could vary based on the current user's locale settings. Replace this call in 'Microsoft.Plugin.WindowWalker.Components.Window.SwitchToWindow()' with a call to 'string.Equals(string?, System.StringComparison)'. * Fix: CA1710 Rename SearchResultUpdateHandler to end in 'EventHandler' * Fix CA1060 Move pinvokes to native methods class * Fix: CS0067 The event 'OpenWindows.OnOpenWindowsUpdateEventHandler' is never used 1) Remove SearchController::OpenWindowsUpdateHandler(object sender, SearchResultUpdateEventArgs e) as it wasn't being called and was redundant with Update Search Text. 2) In Main.cs calling UpdateOpenWindowsList before UpdateSearchText so that the latest enumerated windows will be called. 3) Removing unused OnOpenWindowsUpdateEventHandler and related code. * Revert "Fixes for CA2101 Specify marshaling for P/Invoke string arguments." This reverts commit b3dfe07915dc37618881d348130a7b3c0cd5c59d. * Fixing CA2101 by turning off best fit mapping for methods that require ANSI marshalling. See: https://docs.microsoft.com/en-us/visualstudio/code-quality/ca2101?view=vs-2019 * Previous fix for CA1806 misunderstood int result as hresult. The actual return value is number of characters written. NativeMethods.GetWindowText(hwnd, titleBuffer, sizeOfTitle); * Previous fix for CA1806 misunderstood int result as hresult. The actual return value is number of characters written. NativeMethods.GetClassName(Hwnd, windowClassName, windowClassName.MaxCapacity); * Removing unused window code. This was done instead of validating fxcop changes in WindowIcon. * Fixing typos in Window.cs (charachter -> character)
2020-09-10 09:44:22 -07:00
using System;
2020-08-17 10:00:56 -07:00
using System.Collections.Generic;
Adding FxCop to Microsoft.Plugin.WindowWalker (#6260) * Adding FxCop to Microsoft.Plugin.WindowWalker * Delete WindowResult.cs -- Fix for CA1812 WindowResult is an internal class that is apparently never instantiated. If so, remove the code from the assembly. If this class is intended to contain only static members, make it static (Shared in Visual Basic). * Fix for CA1806 UpdateOpenWindowsList calls EnumWindows but does not use the HRESULT or error code that the method returns. This could lead to unexpected behavior in error conditions or low-resource situations. Use the result in a conditional statement, assign the result to a variable, or pass it as an argument to another method. * Fix for: CA1066 Type Microsoft.Plugin.WindowWalker.Components.InteropAndHelpers.RECT should implement IEquatable<T> because it overrides Equals * Fix for: CA1052 Type 'FuzzyMatching' is a static holder type but is neither static nor NotInheritable * Suppress for CA1069 - These values are defined in https://docs.microsoft.com/en-us/windows/win32/winmsg/extended-window-styles. CA1069 The enum member 'WS_EX_LTRREADING' has the same constant value '0' as member 'WS_EX_LEFT' CA1069 The enum member 'WS_EX_RIGHTSCROLLBAR' has the same constant value '0' as member 'WS_EX_LEFT' * Supress CA1069 Code Description CA1069 The enum member 'SWP_NOREPOSITION' has the same constant value '512' as member 'SWP_NOOWNERZORDER' CA1069 The enum member 'SWP_FRAMECHANGED' has the same constant value '32' as member 'SWP_DRAWFRAME' * Suprress CA1069 for ShowWindow values. See https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-showwindow CA1069 The enum member 'ShowMaximized' has the same constant value '3' as member 'Maximize' * Fix code formatting error * Fix for CA2235: Making POINT serializable CA2235 Field MinPosition is a member of type WINDOWPLACEMENT which is serializable but is of type Microsoft.Plugin.WindowWalker.Components.InteropAndHelpers.POINT which is not serializable CA2235 Field MaxPosition is a member of type WINDOWPLACEMENT which is serializable but is of type Microsoft.Plugin.WindowWalker.Components.InteropAndHelpers.POINT which is not serializable * Fix CA2235 Making RECT serializable CA2235 Field NormalPosition is a member of type WINDOWPLACEMENT which is serializable but is of type Microsoft.Plugin.WindowWalker.Components.InteropAndHelpers.RECT which is not serializable * Fixes for CA2101 Specify marshaling for P/Invoke string arguments. * Fixes for CA2007 Consider calling ConfigureAwait on the awaited task * Fixes for the following (CA1822 / CA1801): CA1822 Member 'OnOpenWindowsUpdate' does not access instance data and can be marked as static Code Description CA1801 Parameter value of method add_OnOpenWindowsUpdate is never used. Remove the parameter or use it in the method body. CA1801 Parameter value of method remove_OnOpenWindowsUpdate is never used. Remove the parameter or use it in the method body. * Fix: CA1710 Rename OpenWindowsUpdateHandler to end in 'EventHandler' * Fix CA1822 Member 'GetProcessIDFromWindowHandle' does not access instance data and can be marked as static * Fix CA1062 In externally visible method 'List<int> FuzzyMatching.FindBestFuzzyMatch(string text, string searchText)', validate parameter 'searchText' is non-null before using it. If appropriate, throw an ArgumentNullException when the argument is null or add a Code Contract precondition asserting non-null argument. * Fixes for CA1304 The behavior of 'string.ToLower()' could vary based on the current user's locale settings. CA1304 The behavior of 'string.ToLower()' could vary based on the current user's locale settings. Replace this call in 'FuzzyMatching.FindBestFuzzyMatch(string, string)' with a call to 'string.ToLower(CultureInfo)'. Code Description CA1304 The behavior of 'string.ToLower()' could vary based on the current user's locale settings. Replace this call in 'FuzzyMatching.FindBestFuzzyMatch(string, string)' with a call to 'string.ToLower(CultureInfo)'. * Supressing warning for CA1814: Prefer jagged arrays over multidimensional however this might be something to consider if needing to optimize the window walker search. * Fix: CA1062 In externally visible method 'List<List<int>> FuzzyMatching.GetAllMatchIndexes(bool[,] matches)', validate parameter 'matches' is non-null before using it. If appropriate, throw an ArgumentNullException when the argument is null or add a Code Contract precondition asserting non-null argument. * Fix for CA1062 In externally visible method 'int FuzzyMatching.CalculateScoreForMatches(List<int> matches)', validate parameter 'matches' is non-null before using it. If appropriate, throw an ArgumentNullException when the argument is null or add a Code Contract precondition asserting non-null argument. * Fixes for CA1806 Calls x... but does not use the HRESULT or error code that the method returns. This could lead to unexpected behavior in error conditions or low-resource situations. Use the result in a conditional statement, assign the result to a variable, or pass it as an argument to another method. Using discard for methods that return void, and checking the hresult before returning parameters. * Fix for CA1820 Test for empty strings using 'string.Length' property or 'string.IsNullOrEmpty' method instead of an Equality check * Supress CA1031 Modify 'get_WindowIcon' to catch a more specific allowed exception type, or rethrow the exception * Code Description CA1062 In externally visible method 'List<Result> Main.Query(Query query)', validate parameter 'query' is non-null before using it. If appropriate, throw an ArgumentNullException when the argument is null or add a Code Contract precondition asserting non-null argument. * Fixes For CA1304 The behavior of 'string.ToUpper()' could vary based on the current user's locale settings. CA1304 The behavior of 'string.ToLower()' could vary based on the current user's locale settings. Replace this call in 'SearchController.SearchText.set' with a call to 'string.ToLower(CultureInfo)'. CA1304 The behavior of 'string.ToLower()' could vary based on the current user's locale settings. Replace this call in 'Window.ProcessName.get' with a call to 'string.ToLower(CultureInfo)'. CA1304 The behavior of 'string.ToLower()' could vary based on the current user's locale settings. Replace this call in 'Window.SwitchToWindow()' with a call to 'string.ToLower(CultureInfo)'. CA1304 The behavior of 'string.ToUpper()' could vary based on the current user's locale settings. Replace this call in 'Window.ToString()' with a call to 'string.ToUpper(CultureInfo)'. CA1307 The behavior of 'string.Equals(string?)' could vary based on the current user's locale settings. Replace this call in 'Microsoft.Plugin.WindowWalker.Components.Window.SwitchToWindow()' with a call to 'string.Equals(string?, System.StringComparison)'. * Fix: CA1710 Rename SearchResultUpdateHandler to end in 'EventHandler' * Fix CA1060 Move pinvokes to native methods class * Fix: CS0067 The event 'OpenWindows.OnOpenWindowsUpdateEventHandler' is never used 1) Remove SearchController::OpenWindowsUpdateHandler(object sender, SearchResultUpdateEventArgs e) as it wasn't being called and was redundant with Update Search Text. 2) In Main.cs calling UpdateOpenWindowsList before UpdateSearchText so that the latest enumerated windows will be called. 3) Removing unused OnOpenWindowsUpdateEventHandler and related code. * Revert "Fixes for CA2101 Specify marshaling for P/Invoke string arguments." This reverts commit b3dfe07915dc37618881d348130a7b3c0cd5c59d. * Fixing CA2101 by turning off best fit mapping for methods that require ANSI marshalling. See: https://docs.microsoft.com/en-us/visualstudio/code-quality/ca2101?view=vs-2019 * Previous fix for CA1806 misunderstood int result as hresult. The actual return value is number of characters written. NativeMethods.GetWindowText(hwnd, titleBuffer, sizeOfTitle); * Previous fix for CA1806 misunderstood int result as hresult. The actual return value is number of characters written. NativeMethods.GetClassName(Hwnd, windowClassName, windowClassName.MaxCapacity); * Removing unused window code. This was done instead of validating fxcop changes in WindowIcon. * Fixing typos in Window.cs (charachter -> character)
2020-09-10 09:44:22 -07:00
using System.Globalization;
2020-08-17 10:00:56 -07:00
using System.Linq;
namespace Microsoft.Plugin.WindowWalker.Components
{
/// <summary>
/// Class housing fuzzy matching methods
/// </summary>
internal static class FuzzyMatching
2020-08-17 10:00:56 -07:00
{
/// <summary>
/// Finds the best match (the one with the most
/// number of letters adjacent to each other) and
/// returns the index location of each of the letters
/// of the matches
/// </summary>
/// <param name="text">The text to search inside of</param>
/// <param name="searchText">the text to search for</param>
/// <returns>returns the index location of each of the letters of the matches</returns>
internal static List<int> FindBestFuzzyMatch(string text, string searchText)
2020-08-17 10:00:56 -07:00
{
Adding FxCop to Microsoft.Plugin.WindowWalker (#6260) * Adding FxCop to Microsoft.Plugin.WindowWalker * Delete WindowResult.cs -- Fix for CA1812 WindowResult is an internal class that is apparently never instantiated. If so, remove the code from the assembly. If this class is intended to contain only static members, make it static (Shared in Visual Basic). * Fix for CA1806 UpdateOpenWindowsList calls EnumWindows but does not use the HRESULT or error code that the method returns. This could lead to unexpected behavior in error conditions or low-resource situations. Use the result in a conditional statement, assign the result to a variable, or pass it as an argument to another method. * Fix for: CA1066 Type Microsoft.Plugin.WindowWalker.Components.InteropAndHelpers.RECT should implement IEquatable<T> because it overrides Equals * Fix for: CA1052 Type 'FuzzyMatching' is a static holder type but is neither static nor NotInheritable * Suppress for CA1069 - These values are defined in https://docs.microsoft.com/en-us/windows/win32/winmsg/extended-window-styles. CA1069 The enum member 'WS_EX_LTRREADING' has the same constant value '0' as member 'WS_EX_LEFT' CA1069 The enum member 'WS_EX_RIGHTSCROLLBAR' has the same constant value '0' as member 'WS_EX_LEFT' * Supress CA1069 Code Description CA1069 The enum member 'SWP_NOREPOSITION' has the same constant value '512' as member 'SWP_NOOWNERZORDER' CA1069 The enum member 'SWP_FRAMECHANGED' has the same constant value '32' as member 'SWP_DRAWFRAME' * Suprress CA1069 for ShowWindow values. See https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-showwindow CA1069 The enum member 'ShowMaximized' has the same constant value '3' as member 'Maximize' * Fix code formatting error * Fix for CA2235: Making POINT serializable CA2235 Field MinPosition is a member of type WINDOWPLACEMENT which is serializable but is of type Microsoft.Plugin.WindowWalker.Components.InteropAndHelpers.POINT which is not serializable CA2235 Field MaxPosition is a member of type WINDOWPLACEMENT which is serializable but is of type Microsoft.Plugin.WindowWalker.Components.InteropAndHelpers.POINT which is not serializable * Fix CA2235 Making RECT serializable CA2235 Field NormalPosition is a member of type WINDOWPLACEMENT which is serializable but is of type Microsoft.Plugin.WindowWalker.Components.InteropAndHelpers.RECT which is not serializable * Fixes for CA2101 Specify marshaling for P/Invoke string arguments. * Fixes for CA2007 Consider calling ConfigureAwait on the awaited task * Fixes for the following (CA1822 / CA1801): CA1822 Member 'OnOpenWindowsUpdate' does not access instance data and can be marked as static Code Description CA1801 Parameter value of method add_OnOpenWindowsUpdate is never used. Remove the parameter or use it in the method body. CA1801 Parameter value of method remove_OnOpenWindowsUpdate is never used. Remove the parameter or use it in the method body. * Fix: CA1710 Rename OpenWindowsUpdateHandler to end in 'EventHandler' * Fix CA1822 Member 'GetProcessIDFromWindowHandle' does not access instance data and can be marked as static * Fix CA1062 In externally visible method 'List<int> FuzzyMatching.FindBestFuzzyMatch(string text, string searchText)', validate parameter 'searchText' is non-null before using it. If appropriate, throw an ArgumentNullException when the argument is null or add a Code Contract precondition asserting non-null argument. * Fixes for CA1304 The behavior of 'string.ToLower()' could vary based on the current user's locale settings. CA1304 The behavior of 'string.ToLower()' could vary based on the current user's locale settings. Replace this call in 'FuzzyMatching.FindBestFuzzyMatch(string, string)' with a call to 'string.ToLower(CultureInfo)'. Code Description CA1304 The behavior of 'string.ToLower()' could vary based on the current user's locale settings. Replace this call in 'FuzzyMatching.FindBestFuzzyMatch(string, string)' with a call to 'string.ToLower(CultureInfo)'. * Supressing warning for CA1814: Prefer jagged arrays over multidimensional however this might be something to consider if needing to optimize the window walker search. * Fix: CA1062 In externally visible method 'List<List<int>> FuzzyMatching.GetAllMatchIndexes(bool[,] matches)', validate parameter 'matches' is non-null before using it. If appropriate, throw an ArgumentNullException when the argument is null or add a Code Contract precondition asserting non-null argument. * Fix for CA1062 In externally visible method 'int FuzzyMatching.CalculateScoreForMatches(List<int> matches)', validate parameter 'matches' is non-null before using it. If appropriate, throw an ArgumentNullException when the argument is null or add a Code Contract precondition asserting non-null argument. * Fixes for CA1806 Calls x... but does not use the HRESULT or error code that the method returns. This could lead to unexpected behavior in error conditions or low-resource situations. Use the result in a conditional statement, assign the result to a variable, or pass it as an argument to another method. Using discard for methods that return void, and checking the hresult before returning parameters. * Fix for CA1820 Test for empty strings using 'string.Length' property or 'string.IsNullOrEmpty' method instead of an Equality check * Supress CA1031 Modify 'get_WindowIcon' to catch a more specific allowed exception type, or rethrow the exception * Code Description CA1062 In externally visible method 'List<Result> Main.Query(Query query)', validate parameter 'query' is non-null before using it. If appropriate, throw an ArgumentNullException when the argument is null or add a Code Contract precondition asserting non-null argument. * Fixes For CA1304 The behavior of 'string.ToUpper()' could vary based on the current user's locale settings. CA1304 The behavior of 'string.ToLower()' could vary based on the current user's locale settings. Replace this call in 'SearchController.SearchText.set' with a call to 'string.ToLower(CultureInfo)'. CA1304 The behavior of 'string.ToLower()' could vary based on the current user's locale settings. Replace this call in 'Window.ProcessName.get' with a call to 'string.ToLower(CultureInfo)'. CA1304 The behavior of 'string.ToLower()' could vary based on the current user's locale settings. Replace this call in 'Window.SwitchToWindow()' with a call to 'string.ToLower(CultureInfo)'. CA1304 The behavior of 'string.ToUpper()' could vary based on the current user's locale settings. Replace this call in 'Window.ToString()' with a call to 'string.ToUpper(CultureInfo)'. CA1307 The behavior of 'string.Equals(string?)' could vary based on the current user's locale settings. Replace this call in 'Microsoft.Plugin.WindowWalker.Components.Window.SwitchToWindow()' with a call to 'string.Equals(string?, System.StringComparison)'. * Fix: CA1710 Rename SearchResultUpdateHandler to end in 'EventHandler' * Fix CA1060 Move pinvokes to native methods class * Fix: CS0067 The event 'OpenWindows.OnOpenWindowsUpdateEventHandler' is never used 1) Remove SearchController::OpenWindowsUpdateHandler(object sender, SearchResultUpdateEventArgs e) as it wasn't being called and was redundant with Update Search Text. 2) In Main.cs calling UpdateOpenWindowsList before UpdateSearchText so that the latest enumerated windows will be called. 3) Removing unused OnOpenWindowsUpdateEventHandler and related code. * Revert "Fixes for CA2101 Specify marshaling for P/Invoke string arguments." This reverts commit b3dfe07915dc37618881d348130a7b3c0cd5c59d. * Fixing CA2101 by turning off best fit mapping for methods that require ANSI marshalling. See: https://docs.microsoft.com/en-us/visualstudio/code-quality/ca2101?view=vs-2019 * Previous fix for CA1806 misunderstood int result as hresult. The actual return value is number of characters written. NativeMethods.GetWindowText(hwnd, titleBuffer, sizeOfTitle); * Previous fix for CA1806 misunderstood int result as hresult. The actual return value is number of characters written. NativeMethods.GetClassName(Hwnd, windowClassName, windowClassName.MaxCapacity); * Removing unused window code. This was done instead of validating fxcop changes in WindowIcon. * Fixing typos in Window.cs (charachter -> character)
2020-09-10 09:44:22 -07:00
if (searchText == null)
{
throw new ArgumentNullException(nameof(searchText));
}
if (text == null)
{
throw new ArgumentNullException(nameof(text));
}
// Using CurrentCulture since this is user facing
Adding FxCop to Microsoft.Plugin.WindowWalker (#6260) * Adding FxCop to Microsoft.Plugin.WindowWalker * Delete WindowResult.cs -- Fix for CA1812 WindowResult is an internal class that is apparently never instantiated. If so, remove the code from the assembly. If this class is intended to contain only static members, make it static (Shared in Visual Basic). * Fix for CA1806 UpdateOpenWindowsList calls EnumWindows but does not use the HRESULT or error code that the method returns. This could lead to unexpected behavior in error conditions or low-resource situations. Use the result in a conditional statement, assign the result to a variable, or pass it as an argument to another method. * Fix for: CA1066 Type Microsoft.Plugin.WindowWalker.Components.InteropAndHelpers.RECT should implement IEquatable<T> because it overrides Equals * Fix for: CA1052 Type 'FuzzyMatching' is a static holder type but is neither static nor NotInheritable * Suppress for CA1069 - These values are defined in https://docs.microsoft.com/en-us/windows/win32/winmsg/extended-window-styles. CA1069 The enum member 'WS_EX_LTRREADING' has the same constant value '0' as member 'WS_EX_LEFT' CA1069 The enum member 'WS_EX_RIGHTSCROLLBAR' has the same constant value '0' as member 'WS_EX_LEFT' * Supress CA1069 Code Description CA1069 The enum member 'SWP_NOREPOSITION' has the same constant value '512' as member 'SWP_NOOWNERZORDER' CA1069 The enum member 'SWP_FRAMECHANGED' has the same constant value '32' as member 'SWP_DRAWFRAME' * Suprress CA1069 for ShowWindow values. See https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-showwindow CA1069 The enum member 'ShowMaximized' has the same constant value '3' as member 'Maximize' * Fix code formatting error * Fix for CA2235: Making POINT serializable CA2235 Field MinPosition is a member of type WINDOWPLACEMENT which is serializable but is of type Microsoft.Plugin.WindowWalker.Components.InteropAndHelpers.POINT which is not serializable CA2235 Field MaxPosition is a member of type WINDOWPLACEMENT which is serializable but is of type Microsoft.Plugin.WindowWalker.Components.InteropAndHelpers.POINT which is not serializable * Fix CA2235 Making RECT serializable CA2235 Field NormalPosition is a member of type WINDOWPLACEMENT which is serializable but is of type Microsoft.Plugin.WindowWalker.Components.InteropAndHelpers.RECT which is not serializable * Fixes for CA2101 Specify marshaling for P/Invoke string arguments. * Fixes for CA2007 Consider calling ConfigureAwait on the awaited task * Fixes for the following (CA1822 / CA1801): CA1822 Member 'OnOpenWindowsUpdate' does not access instance data and can be marked as static Code Description CA1801 Parameter value of method add_OnOpenWindowsUpdate is never used. Remove the parameter or use it in the method body. CA1801 Parameter value of method remove_OnOpenWindowsUpdate is never used. Remove the parameter or use it in the method body. * Fix: CA1710 Rename OpenWindowsUpdateHandler to end in 'EventHandler' * Fix CA1822 Member 'GetProcessIDFromWindowHandle' does not access instance data and can be marked as static * Fix CA1062 In externally visible method 'List<int> FuzzyMatching.FindBestFuzzyMatch(string text, string searchText)', validate parameter 'searchText' is non-null before using it. If appropriate, throw an ArgumentNullException when the argument is null or add a Code Contract precondition asserting non-null argument. * Fixes for CA1304 The behavior of 'string.ToLower()' could vary based on the current user's locale settings. CA1304 The behavior of 'string.ToLower()' could vary based on the current user's locale settings. Replace this call in 'FuzzyMatching.FindBestFuzzyMatch(string, string)' with a call to 'string.ToLower(CultureInfo)'. Code Description CA1304 The behavior of 'string.ToLower()' could vary based on the current user's locale settings. Replace this call in 'FuzzyMatching.FindBestFuzzyMatch(string, string)' with a call to 'string.ToLower(CultureInfo)'. * Supressing warning for CA1814: Prefer jagged arrays over multidimensional however this might be something to consider if needing to optimize the window walker search. * Fix: CA1062 In externally visible method 'List<List<int>> FuzzyMatching.GetAllMatchIndexes(bool[,] matches)', validate parameter 'matches' is non-null before using it. If appropriate, throw an ArgumentNullException when the argument is null or add a Code Contract precondition asserting non-null argument. * Fix for CA1062 In externally visible method 'int FuzzyMatching.CalculateScoreForMatches(List<int> matches)', validate parameter 'matches' is non-null before using it. If appropriate, throw an ArgumentNullException when the argument is null or add a Code Contract precondition asserting non-null argument. * Fixes for CA1806 Calls x... but does not use the HRESULT or error code that the method returns. This could lead to unexpected behavior in error conditions or low-resource situations. Use the result in a conditional statement, assign the result to a variable, or pass it as an argument to another method. Using discard for methods that return void, and checking the hresult before returning parameters. * Fix for CA1820 Test for empty strings using 'string.Length' property or 'string.IsNullOrEmpty' method instead of an Equality check * Supress CA1031 Modify 'get_WindowIcon' to catch a more specific allowed exception type, or rethrow the exception * Code Description CA1062 In externally visible method 'List<Result> Main.Query(Query query)', validate parameter 'query' is non-null before using it. If appropriate, throw an ArgumentNullException when the argument is null or add a Code Contract precondition asserting non-null argument. * Fixes For CA1304 The behavior of 'string.ToUpper()' could vary based on the current user's locale settings. CA1304 The behavior of 'string.ToLower()' could vary based on the current user's locale settings. Replace this call in 'SearchController.SearchText.set' with a call to 'string.ToLower(CultureInfo)'. CA1304 The behavior of 'string.ToLower()' could vary based on the current user's locale settings. Replace this call in 'Window.ProcessName.get' with a call to 'string.ToLower(CultureInfo)'. CA1304 The behavior of 'string.ToLower()' could vary based on the current user's locale settings. Replace this call in 'Window.SwitchToWindow()' with a call to 'string.ToLower(CultureInfo)'. CA1304 The behavior of 'string.ToUpper()' could vary based on the current user's locale settings. Replace this call in 'Window.ToString()' with a call to 'string.ToUpper(CultureInfo)'. CA1307 The behavior of 'string.Equals(string?)' could vary based on the current user's locale settings. Replace this call in 'Microsoft.Plugin.WindowWalker.Components.Window.SwitchToWindow()' with a call to 'string.Equals(string?, System.StringComparison)'. * Fix: CA1710 Rename SearchResultUpdateHandler to end in 'EventHandler' * Fix CA1060 Move pinvokes to native methods class * Fix: CS0067 The event 'OpenWindows.OnOpenWindowsUpdateEventHandler' is never used 1) Remove SearchController::OpenWindowsUpdateHandler(object sender, SearchResultUpdateEventArgs e) as it wasn't being called and was redundant with Update Search Text. 2) In Main.cs calling UpdateOpenWindowsList before UpdateSearchText so that the latest enumerated windows will be called. 3) Removing unused OnOpenWindowsUpdateEventHandler and related code. * Revert "Fixes for CA2101 Specify marshaling for P/Invoke string arguments." This reverts commit b3dfe07915dc37618881d348130a7b3c0cd5c59d. * Fixing CA2101 by turning off best fit mapping for methods that require ANSI marshalling. See: https://docs.microsoft.com/en-us/visualstudio/code-quality/ca2101?view=vs-2019 * Previous fix for CA1806 misunderstood int result as hresult. The actual return value is number of characters written. NativeMethods.GetWindowText(hwnd, titleBuffer, sizeOfTitle); * Previous fix for CA1806 misunderstood int result as hresult. The actual return value is number of characters written. NativeMethods.GetClassName(Hwnd, windowClassName, windowClassName.MaxCapacity); * Removing unused window code. This was done instead of validating fxcop changes in WindowIcon. * Fixing typos in Window.cs (charachter -> character)
2020-09-10 09:44:22 -07:00
searchText = searchText.ToLower(CultureInfo.CurrentCulture);
text = text.ToLower(CultureInfo.CurrentCulture);
2020-08-17 10:00:56 -07:00
// Create a grid to march matches like
// eg.
// a b c a d e c f g
// a x x
// c x x
bool[,] matches = new bool[text.Length, searchText.Length];
for (int firstIndex = 0; firstIndex < text.Length; firstIndex++)
{
for (int secondIndex = 0; secondIndex < searchText.Length; secondIndex++)
{
matches[firstIndex, secondIndex] =
searchText[secondIndex] == text[firstIndex] ?
true :
false;
}
}
// use this table to get all the possible matches
List<List<int>> allMatches = GetAllMatchIndexes(matches);
// return the score that is the max
int maxScore = allMatches.Count > 0 ? CalculateScoreForMatches(allMatches[0]) : 0;
List<int> bestMatch = allMatches.Count > 0 ? allMatches[0] : new List<int>();
foreach (var match in allMatches)
{
int score = CalculateScoreForMatches(match);
if (score > maxScore)
{
bestMatch = match;
maxScore = score;
}
}
return bestMatch;
}
/// <summary>
/// Gets all the possible matches to the search string with in the text
/// </summary>
/// <param name="matches"> a table showing the matches as generated by
/// a two dimensional array with the first dimension the text and the second
/// one the search string and each cell marked as an intersection between the two</param>
/// <returns>a list of the possible combinations that match the search text</returns>
internal static List<List<int>> GetAllMatchIndexes(bool[,] matches)
2020-08-17 10:00:56 -07:00
{
Adding FxCop to Microsoft.Plugin.WindowWalker (#6260) * Adding FxCop to Microsoft.Plugin.WindowWalker * Delete WindowResult.cs -- Fix for CA1812 WindowResult is an internal class that is apparently never instantiated. If so, remove the code from the assembly. If this class is intended to contain only static members, make it static (Shared in Visual Basic). * Fix for CA1806 UpdateOpenWindowsList calls EnumWindows but does not use the HRESULT or error code that the method returns. This could lead to unexpected behavior in error conditions or low-resource situations. Use the result in a conditional statement, assign the result to a variable, or pass it as an argument to another method. * Fix for: CA1066 Type Microsoft.Plugin.WindowWalker.Components.InteropAndHelpers.RECT should implement IEquatable<T> because it overrides Equals * Fix for: CA1052 Type 'FuzzyMatching' is a static holder type but is neither static nor NotInheritable * Suppress for CA1069 - These values are defined in https://docs.microsoft.com/en-us/windows/win32/winmsg/extended-window-styles. CA1069 The enum member 'WS_EX_LTRREADING' has the same constant value '0' as member 'WS_EX_LEFT' CA1069 The enum member 'WS_EX_RIGHTSCROLLBAR' has the same constant value '0' as member 'WS_EX_LEFT' * Supress CA1069 Code Description CA1069 The enum member 'SWP_NOREPOSITION' has the same constant value '512' as member 'SWP_NOOWNERZORDER' CA1069 The enum member 'SWP_FRAMECHANGED' has the same constant value '32' as member 'SWP_DRAWFRAME' * Suprress CA1069 for ShowWindow values. See https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-showwindow CA1069 The enum member 'ShowMaximized' has the same constant value '3' as member 'Maximize' * Fix code formatting error * Fix for CA2235: Making POINT serializable CA2235 Field MinPosition is a member of type WINDOWPLACEMENT which is serializable but is of type Microsoft.Plugin.WindowWalker.Components.InteropAndHelpers.POINT which is not serializable CA2235 Field MaxPosition is a member of type WINDOWPLACEMENT which is serializable but is of type Microsoft.Plugin.WindowWalker.Components.InteropAndHelpers.POINT which is not serializable * Fix CA2235 Making RECT serializable CA2235 Field NormalPosition is a member of type WINDOWPLACEMENT which is serializable but is of type Microsoft.Plugin.WindowWalker.Components.InteropAndHelpers.RECT which is not serializable * Fixes for CA2101 Specify marshaling for P/Invoke string arguments. * Fixes for CA2007 Consider calling ConfigureAwait on the awaited task * Fixes for the following (CA1822 / CA1801): CA1822 Member 'OnOpenWindowsUpdate' does not access instance data and can be marked as static Code Description CA1801 Parameter value of method add_OnOpenWindowsUpdate is never used. Remove the parameter or use it in the method body. CA1801 Parameter value of method remove_OnOpenWindowsUpdate is never used. Remove the parameter or use it in the method body. * Fix: CA1710 Rename OpenWindowsUpdateHandler to end in 'EventHandler' * Fix CA1822 Member 'GetProcessIDFromWindowHandle' does not access instance data and can be marked as static * Fix CA1062 In externally visible method 'List<int> FuzzyMatching.FindBestFuzzyMatch(string text, string searchText)', validate parameter 'searchText' is non-null before using it. If appropriate, throw an ArgumentNullException when the argument is null or add a Code Contract precondition asserting non-null argument. * Fixes for CA1304 The behavior of 'string.ToLower()' could vary based on the current user's locale settings. CA1304 The behavior of 'string.ToLower()' could vary based on the current user's locale settings. Replace this call in 'FuzzyMatching.FindBestFuzzyMatch(string, string)' with a call to 'string.ToLower(CultureInfo)'. Code Description CA1304 The behavior of 'string.ToLower()' could vary based on the current user's locale settings. Replace this call in 'FuzzyMatching.FindBestFuzzyMatch(string, string)' with a call to 'string.ToLower(CultureInfo)'. * Supressing warning for CA1814: Prefer jagged arrays over multidimensional however this might be something to consider if needing to optimize the window walker search. * Fix: CA1062 In externally visible method 'List<List<int>> FuzzyMatching.GetAllMatchIndexes(bool[,] matches)', validate parameter 'matches' is non-null before using it. If appropriate, throw an ArgumentNullException when the argument is null or add a Code Contract precondition asserting non-null argument. * Fix for CA1062 In externally visible method 'int FuzzyMatching.CalculateScoreForMatches(List<int> matches)', validate parameter 'matches' is non-null before using it. If appropriate, throw an ArgumentNullException when the argument is null or add a Code Contract precondition asserting non-null argument. * Fixes for CA1806 Calls x... but does not use the HRESULT or error code that the method returns. This could lead to unexpected behavior in error conditions or low-resource situations. Use the result in a conditional statement, assign the result to a variable, or pass it as an argument to another method. Using discard for methods that return void, and checking the hresult before returning parameters. * Fix for CA1820 Test for empty strings using 'string.Length' property or 'string.IsNullOrEmpty' method instead of an Equality check * Supress CA1031 Modify 'get_WindowIcon' to catch a more specific allowed exception type, or rethrow the exception * Code Description CA1062 In externally visible method 'List<Result> Main.Query(Query query)', validate parameter 'query' is non-null before using it. If appropriate, throw an ArgumentNullException when the argument is null or add a Code Contract precondition asserting non-null argument. * Fixes For CA1304 The behavior of 'string.ToUpper()' could vary based on the current user's locale settings. CA1304 The behavior of 'string.ToLower()' could vary based on the current user's locale settings. Replace this call in 'SearchController.SearchText.set' with a call to 'string.ToLower(CultureInfo)'. CA1304 The behavior of 'string.ToLower()' could vary based on the current user's locale settings. Replace this call in 'Window.ProcessName.get' with a call to 'string.ToLower(CultureInfo)'. CA1304 The behavior of 'string.ToLower()' could vary based on the current user's locale settings. Replace this call in 'Window.SwitchToWindow()' with a call to 'string.ToLower(CultureInfo)'. CA1304 The behavior of 'string.ToUpper()' could vary based on the current user's locale settings. Replace this call in 'Window.ToString()' with a call to 'string.ToUpper(CultureInfo)'. CA1307 The behavior of 'string.Equals(string?)' could vary based on the current user's locale settings. Replace this call in 'Microsoft.Plugin.WindowWalker.Components.Window.SwitchToWindow()' with a call to 'string.Equals(string?, System.StringComparison)'. * Fix: CA1710 Rename SearchResultUpdateHandler to end in 'EventHandler' * Fix CA1060 Move pinvokes to native methods class * Fix: CS0067 The event 'OpenWindows.OnOpenWindowsUpdateEventHandler' is never used 1) Remove SearchController::OpenWindowsUpdateHandler(object sender, SearchResultUpdateEventArgs e) as it wasn't being called and was redundant with Update Search Text. 2) In Main.cs calling UpdateOpenWindowsList before UpdateSearchText so that the latest enumerated windows will be called. 3) Removing unused OnOpenWindowsUpdateEventHandler and related code. * Revert "Fixes for CA2101 Specify marshaling for P/Invoke string arguments." This reverts commit b3dfe07915dc37618881d348130a7b3c0cd5c59d. * Fixing CA2101 by turning off best fit mapping for methods that require ANSI marshalling. See: https://docs.microsoft.com/en-us/visualstudio/code-quality/ca2101?view=vs-2019 * Previous fix for CA1806 misunderstood int result as hresult. The actual return value is number of characters written. NativeMethods.GetWindowText(hwnd, titleBuffer, sizeOfTitle); * Previous fix for CA1806 misunderstood int result as hresult. The actual return value is number of characters written. NativeMethods.GetClassName(Hwnd, windowClassName, windowClassName.MaxCapacity); * Removing unused window code. This was done instead of validating fxcop changes in WindowIcon. * Fixing typos in Window.cs (charachter -> character)
2020-09-10 09:44:22 -07:00
if (matches == null)
{
throw new ArgumentNullException(nameof(matches));
}
2020-08-17 10:00:56 -07:00
List<List<int>> results = new List<List<int>>();
for (int secondIndex = 0; secondIndex < matches.GetLength(1); secondIndex++)
{
for (int firstIndex = 0; firstIndex < matches.GetLength(0); firstIndex++)
{
if (secondIndex == 0 && matches[firstIndex, secondIndex])
{
results.Add(new List<int> { firstIndex });
}
else if (matches[firstIndex, secondIndex])
{
var tempList = results.Where(x => x.Count == secondIndex && x[x.Count - 1] < firstIndex).Select(x => x.ToList()).ToList();
foreach (var pathSofar in tempList)
{
pathSofar.Add(firstIndex);
}
results.AddRange(tempList);
}
}
results = results.Where(x => x.Count == secondIndex + 1).ToList();
}
return results.Where(x => x.Count == matches.GetLength(1)).ToList();
}
/// <summary>
/// Calculates the score for a string
/// </summary>
/// <param name="matches">the index of the matches</param>
/// <returns>an integer representing the score</returns>
internal static int CalculateScoreForMatches(List<int> matches)
2020-08-17 10:00:56 -07:00
{
Adding FxCop to Microsoft.Plugin.WindowWalker (#6260) * Adding FxCop to Microsoft.Plugin.WindowWalker * Delete WindowResult.cs -- Fix for CA1812 WindowResult is an internal class that is apparently never instantiated. If so, remove the code from the assembly. If this class is intended to contain only static members, make it static (Shared in Visual Basic). * Fix for CA1806 UpdateOpenWindowsList calls EnumWindows but does not use the HRESULT or error code that the method returns. This could lead to unexpected behavior in error conditions or low-resource situations. Use the result in a conditional statement, assign the result to a variable, or pass it as an argument to another method. * Fix for: CA1066 Type Microsoft.Plugin.WindowWalker.Components.InteropAndHelpers.RECT should implement IEquatable<T> because it overrides Equals * Fix for: CA1052 Type 'FuzzyMatching' is a static holder type but is neither static nor NotInheritable * Suppress for CA1069 - These values are defined in https://docs.microsoft.com/en-us/windows/win32/winmsg/extended-window-styles. CA1069 The enum member 'WS_EX_LTRREADING' has the same constant value '0' as member 'WS_EX_LEFT' CA1069 The enum member 'WS_EX_RIGHTSCROLLBAR' has the same constant value '0' as member 'WS_EX_LEFT' * Supress CA1069 Code Description CA1069 The enum member 'SWP_NOREPOSITION' has the same constant value '512' as member 'SWP_NOOWNERZORDER' CA1069 The enum member 'SWP_FRAMECHANGED' has the same constant value '32' as member 'SWP_DRAWFRAME' * Suprress CA1069 for ShowWindow values. See https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-showwindow CA1069 The enum member 'ShowMaximized' has the same constant value '3' as member 'Maximize' * Fix code formatting error * Fix for CA2235: Making POINT serializable CA2235 Field MinPosition is a member of type WINDOWPLACEMENT which is serializable but is of type Microsoft.Plugin.WindowWalker.Components.InteropAndHelpers.POINT which is not serializable CA2235 Field MaxPosition is a member of type WINDOWPLACEMENT which is serializable but is of type Microsoft.Plugin.WindowWalker.Components.InteropAndHelpers.POINT which is not serializable * Fix CA2235 Making RECT serializable CA2235 Field NormalPosition is a member of type WINDOWPLACEMENT which is serializable but is of type Microsoft.Plugin.WindowWalker.Components.InteropAndHelpers.RECT which is not serializable * Fixes for CA2101 Specify marshaling for P/Invoke string arguments. * Fixes for CA2007 Consider calling ConfigureAwait on the awaited task * Fixes for the following (CA1822 / CA1801): CA1822 Member 'OnOpenWindowsUpdate' does not access instance data and can be marked as static Code Description CA1801 Parameter value of method add_OnOpenWindowsUpdate is never used. Remove the parameter or use it in the method body. CA1801 Parameter value of method remove_OnOpenWindowsUpdate is never used. Remove the parameter or use it in the method body. * Fix: CA1710 Rename OpenWindowsUpdateHandler to end in 'EventHandler' * Fix CA1822 Member 'GetProcessIDFromWindowHandle' does not access instance data and can be marked as static * Fix CA1062 In externally visible method 'List<int> FuzzyMatching.FindBestFuzzyMatch(string text, string searchText)', validate parameter 'searchText' is non-null before using it. If appropriate, throw an ArgumentNullException when the argument is null or add a Code Contract precondition asserting non-null argument. * Fixes for CA1304 The behavior of 'string.ToLower()' could vary based on the current user's locale settings. CA1304 The behavior of 'string.ToLower()' could vary based on the current user's locale settings. Replace this call in 'FuzzyMatching.FindBestFuzzyMatch(string, string)' with a call to 'string.ToLower(CultureInfo)'. Code Description CA1304 The behavior of 'string.ToLower()' could vary based on the current user's locale settings. Replace this call in 'FuzzyMatching.FindBestFuzzyMatch(string, string)' with a call to 'string.ToLower(CultureInfo)'. * Supressing warning for CA1814: Prefer jagged arrays over multidimensional however this might be something to consider if needing to optimize the window walker search. * Fix: CA1062 In externally visible method 'List<List<int>> FuzzyMatching.GetAllMatchIndexes(bool[,] matches)', validate parameter 'matches' is non-null before using it. If appropriate, throw an ArgumentNullException when the argument is null or add a Code Contract precondition asserting non-null argument. * Fix for CA1062 In externally visible method 'int FuzzyMatching.CalculateScoreForMatches(List<int> matches)', validate parameter 'matches' is non-null before using it. If appropriate, throw an ArgumentNullException when the argument is null or add a Code Contract precondition asserting non-null argument. * Fixes for CA1806 Calls x... but does not use the HRESULT or error code that the method returns. This could lead to unexpected behavior in error conditions or low-resource situations. Use the result in a conditional statement, assign the result to a variable, or pass it as an argument to another method. Using discard for methods that return void, and checking the hresult before returning parameters. * Fix for CA1820 Test for empty strings using 'string.Length' property or 'string.IsNullOrEmpty' method instead of an Equality check * Supress CA1031 Modify 'get_WindowIcon' to catch a more specific allowed exception type, or rethrow the exception * Code Description CA1062 In externally visible method 'List<Result> Main.Query(Query query)', validate parameter 'query' is non-null before using it. If appropriate, throw an ArgumentNullException when the argument is null or add a Code Contract precondition asserting non-null argument. * Fixes For CA1304 The behavior of 'string.ToUpper()' could vary based on the current user's locale settings. CA1304 The behavior of 'string.ToLower()' could vary based on the current user's locale settings. Replace this call in 'SearchController.SearchText.set' with a call to 'string.ToLower(CultureInfo)'. CA1304 The behavior of 'string.ToLower()' could vary based on the current user's locale settings. Replace this call in 'Window.ProcessName.get' with a call to 'string.ToLower(CultureInfo)'. CA1304 The behavior of 'string.ToLower()' could vary based on the current user's locale settings. Replace this call in 'Window.SwitchToWindow()' with a call to 'string.ToLower(CultureInfo)'. CA1304 The behavior of 'string.ToUpper()' could vary based on the current user's locale settings. Replace this call in 'Window.ToString()' with a call to 'string.ToUpper(CultureInfo)'. CA1307 The behavior of 'string.Equals(string?)' could vary based on the current user's locale settings. Replace this call in 'Microsoft.Plugin.WindowWalker.Components.Window.SwitchToWindow()' with a call to 'string.Equals(string?, System.StringComparison)'. * Fix: CA1710 Rename SearchResultUpdateHandler to end in 'EventHandler' * Fix CA1060 Move pinvokes to native methods class * Fix: CS0067 The event 'OpenWindows.OnOpenWindowsUpdateEventHandler' is never used 1) Remove SearchController::OpenWindowsUpdateHandler(object sender, SearchResultUpdateEventArgs e) as it wasn't being called and was redundant with Update Search Text. 2) In Main.cs calling UpdateOpenWindowsList before UpdateSearchText so that the latest enumerated windows will be called. 3) Removing unused OnOpenWindowsUpdateEventHandler and related code. * Revert "Fixes for CA2101 Specify marshaling for P/Invoke string arguments." This reverts commit b3dfe07915dc37618881d348130a7b3c0cd5c59d. * Fixing CA2101 by turning off best fit mapping for methods that require ANSI marshalling. See: https://docs.microsoft.com/en-us/visualstudio/code-quality/ca2101?view=vs-2019 * Previous fix for CA1806 misunderstood int result as hresult. The actual return value is number of characters written. NativeMethods.GetWindowText(hwnd, titleBuffer, sizeOfTitle); * Previous fix for CA1806 misunderstood int result as hresult. The actual return value is number of characters written. NativeMethods.GetClassName(Hwnd, windowClassName, windowClassName.MaxCapacity); * Removing unused window code. This was done instead of validating fxcop changes in WindowIcon. * Fixing typos in Window.cs (charachter -> character)
2020-09-10 09:44:22 -07:00
if (matches == null)
{
throw new ArgumentNullException(nameof(matches));
}
2020-08-17 10:00:56 -07:00
var score = 0;
for (int currentIndex = 1; currentIndex < matches.Count; currentIndex++)
{
var previousIndex = currentIndex - 1;
score -= matches[currentIndex] - matches[previousIndex];
}
return score == 0 ? -10000 : score;
}
}
}