From 2c49df4be3ee4e0951365500c36b358b6d96be80 Mon Sep 17 00:00:00 2001 From: Clint Rutkas Date: Tue, 11 Aug 2020 13:40:26 -0700 Subject: [PATCH] more fixes for getting styleCop up, this will need one more push to get another 15 that will require renaming of vars (#5875) --- .../launcher/Wox.Infrastructure/Alphabet.cs | 34 +++--- .../Exception/ExceptionFormatter.cs | 43 +++++-- .../FileVersionInfoWrapper.cs | 4 +- .../FileSystemHelper/FileWrapper.cs | 7 +- .../launcher/Wox.Infrastructure/Helper.cs | 11 +- .../Wox.Infrastructure/Hotkey/HotkeyModel.cs | 4 +- .../Wox.Infrastructure/Hotkey/KeyEvent.cs | 2 +- .../launcher/Wox.Infrastructure/Http/Http.cs | 2 +- .../Image/ImageHashGenerator.cs | 1 - .../Wox.Infrastructure/Image/ImageLoader.cs | 13 +-- .../Image/WindowsThumbnailProvider.cs | 27 +++-- .../launcher/Wox.Infrastructure/Logger/Log.cs | 3 +- .../Wox.Infrastructure/MatchOption.cs | 28 +++++ .../Wox.Infrastructure/MatchResult.cs | 77 +++++++++++++ .../Storage/BinaryStorage`1.cs | 4 +- .../Storage/FileSystemWatcherWrapper.cs | 4 +- .../Storage/JsonStorage`1.cs | 2 +- .../Storage/ListRepository`1.cs | 5 +- .../Storage/PluginJsonStorage`1.cs | 3 +- .../Storage/StoragePowerToysVersionInfo.cs | 14 +-- .../Storage/WoxJsonStorage`1.cs | 3 +- .../Wox.Infrastructure/StringMatcher.cs | 105 +++--------------- .../UserSettings/PluginSettings.cs | 2 +- .../UserSettings/Settings.cs | 38 ++++--- 24 files changed, 255 insertions(+), 181 deletions(-) create mode 100644 src/modules/launcher/Wox.Infrastructure/MatchOption.cs create mode 100644 src/modules/launcher/Wox.Infrastructure/MatchResult.cs diff --git a/src/modules/launcher/Wox.Infrastructure/Alphabet.cs b/src/modules/launcher/Wox.Infrastructure/Alphabet.cs index 0f7d694f15..d8b503a0cc 100644 --- a/src/modules/launcher/Wox.Infrastructure/Alphabet.cs +++ b/src/modules/launcher/Wox.Infrastructure/Alphabet.cs @@ -18,8 +18,8 @@ namespace Wox.Infrastructure { public class Alphabet : IAlphabet { - private readonly HanyuPinyinOutputFormat Format = new HanyuPinyinOutputFormat(); - private ConcurrentDictionary PinyinCache; + private readonly HanyuPinyinOutputFormat _pinyinFormat = new HanyuPinyinOutputFormat(); + private ConcurrentDictionary _pinyinCache; private BinaryStorage> _pinyinStorage; private Settings _settings; @@ -31,7 +31,7 @@ namespace Wox.Infrastructure private void InitializePinyinHelpers() { - Format.setToneType(HanyuPinyinToneType.WITHOUT_TONE); + _pinyinFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE); Stopwatch.Normal("|Wox.Infrastructure.Alphabet.Initialize|Preload pinyin cache", () => { @@ -39,9 +39,9 @@ namespace Wox.Infrastructure SetPinyinCacheAsDictionary(_pinyinStorage.TryLoad(new Dictionary())); // force pinyin library static constructor initialize - PinyinHelper.toHanyuPinyinStringArray('T', Format); + PinyinHelper.toHanyuPinyinStringArray('T', _pinyinFormat); }); - Log.Info($"|Wox.Infrastructure.Alphabet.Initialize|Number of preload pinyin combination<{PinyinCache.Count}>"); + Log.Info($"|Wox.Infrastructure.Alphabet.Initialize|Number of preload pinyin combination<{_pinyinCache.Count}>"); } public string Translate(string str) @@ -52,17 +52,23 @@ namespace Wox.Infrastructure public string ConvertChineseCharactersToPinyin(string source) { if (!_settings.ShouldUsePinyin) + { return source; + } if (string.IsNullOrEmpty(source)) + { return source; + } if (!ContainsChinese(source)) + { return source; + } var combination = PinyinCombination(source); - var pinyinArray = combination.Select(x => string.Join("", x)); + var pinyinArray = combination.Select(x => string.Join(string.Empty, x)); var acronymArray = combination.Select(Acronym).Distinct(); var joinedSingleStringCombination = new StringBuilder(); @@ -85,11 +91,11 @@ namespace Wox.Infrastructure private static string[] EmptyStringArray = new string[0]; private static string[][] Empty2DStringArray = new string[0][]; - [Obsolete("Not accurate, eg 音乐 will not return yinyue but returns yinle ")] /// /// replace chinese character with pinyin, non chinese character won't be modified /// should be word or sentence, instead of single character. e.g. 微软 /// + [Obsolete("Not accurate, eg 音乐 will not return yinyue but returns yinle ")] public string[] Pinyin(string word) { if (!_settings.ShouldUsePinyin) @@ -119,12 +125,12 @@ namespace Wox.Infrastructure return Empty2DStringArray; } - if (!PinyinCache.ContainsKey(characters)) + if (!_pinyinCache.ContainsKey(characters)) { var allPinyins = new List(); foreach (var c in characters) { - var pinyins = PinyinHelper.toHanyuPinyinStringArray(c, Format); + var pinyins = PinyinHelper.toHanyuPinyinStringArray(c, _pinyinFormat); if (pinyins != null) { var r = pinyins.Distinct().ToArray(); @@ -138,18 +144,18 @@ namespace Wox.Infrastructure } var combination = allPinyins.Aggregate(Combination).Select(c => c.Split(';')).ToArray(); - PinyinCache[characters] = combination; + _pinyinCache[characters] = combination; return combination; } else { - return PinyinCache[characters]; + return _pinyinCache[characters]; } } public string Acronym(string[] pinyin) { - var acronym = string.Join("", pinyin.Select(p => p[0])); + var acronym = string.Join(string.Empty, pinyin.Select(p => p[0])); return acronym; } @@ -188,12 +194,12 @@ namespace Wox.Infrastructure private Dictionary GetPinyinCacheAsDictionary() { - return new Dictionary(PinyinCache); + return new Dictionary(_pinyinCache); } private void SetPinyinCacheAsDictionary(Dictionary usage) { - PinyinCache = new ConcurrentDictionary(usage); + _pinyinCache = new ConcurrentDictionary(usage); } } } diff --git a/src/modules/launcher/Wox.Infrastructure/Exception/ExceptionFormatter.cs b/src/modules/launcher/Wox.Infrastructure/Exception/ExceptionFormatter.cs index 79a7ebd83f..caeeb29178 100644 --- a/src/modules/launcher/Wox.Infrastructure/Exception/ExceptionFormatter.cs +++ b/src/modules/launcher/Wox.Infrastructure/Exception/ExceptionFormatter.cs @@ -121,16 +121,22 @@ namespace Wox.Infrastructure.Exception if (versionKeyName.StartsWith("v")) { RegistryKey versionKey = ndpKey.OpenSubKey(versionKeyName); - string name = (string)versionKey.GetValue("Version", ""); - string sp = versionKey.GetValue("SP", "").ToString(); - string install = versionKey.GetValue("Install", "").ToString(); - if (install != "") - if (sp != "" && install == "1") + string name = (string)versionKey.GetValue("Version", string.Empty); + string sp = versionKey.GetValue("SP", string.Empty).ToString(); + string install = versionKey.GetValue("Install", string.Empty).ToString(); + if (install != string.Empty) + { + if (sp != string.Empty && install == "1") + { result.Add(string.Format("{0} {1} SP{2}", versionKeyName, name, sp)); + } else + { result.Add(string.Format("{0} {1}", versionKeyName, name)); + } + } - if (name != "") + if (name != string.Empty) { continue; } @@ -138,16 +144,23 @@ namespace Wox.Infrastructure.Exception foreach (string subKeyName in versionKey.GetSubKeyNames()) { RegistryKey subKey = versionKey.OpenSubKey(subKeyName); - name = (string)subKey.GetValue("Version", ""); - if (name != "") - sp = subKey.GetValue("SP", "").ToString(); - install = subKey.GetValue("Install", "").ToString(); - if (install != "") + name = (string)subKey.GetValue("Version", string.Empty); + if (name != string.Empty) { - if (sp != "" && install == "1") + sp = subKey.GetValue("SP", string.Empty).ToString(); + } + + install = subKey.GetValue("Install", string.Empty).ToString(); + if (install != string.Empty) + { + if (sp != string.Empty && install == "1") + { result.Add(string.Format("{0} {1} {2} SP{3}", versionKeyName, subKeyName, name, sp)); + } else if (install == "1") + { result.Add(string.Format("{0} {1} {2}", versionKeyName, subKeyName, name)); + } } } } @@ -159,13 +172,19 @@ namespace Wox.Infrastructure.Exception int releaseKey = (int)ndpKey.GetValue("Release"); { if (releaseKey == 378389) + { result.Add("v4.5"); + } if (releaseKey == 378675) + { result.Add("v4.5.1 installed with Windows 8.1"); + } if (releaseKey == 378758) + { result.Add("4.5.1 installed on Windows 8, Windows 7 SP1, or Windows Vista SP2"); + } } } diff --git a/src/modules/launcher/Wox.Infrastructure/FileSystemHelper/FileVersionInfoWrapper.cs b/src/modules/launcher/Wox.Infrastructure/FileSystemHelper/FileVersionInfoWrapper.cs index 3aca7fbee3..3266f52da1 100644 --- a/src/modules/launcher/Wox.Infrastructure/FileSystemHelper/FileVersionInfoWrapper.cs +++ b/src/modules/launcher/Wox.Infrastructure/FileSystemHelper/FileVersionInfoWrapper.cs @@ -9,7 +9,9 @@ namespace Wox.Infrastructure.FileSystemHelper { public class FileVersionInfoWrapper : IFileVersionInfoWrapper { - public FileVersionInfoWrapper() { } + public FileVersionInfoWrapper() + { + } public FileVersionInfo GetVersionInfo(string path) { diff --git a/src/modules/launcher/Wox.Infrastructure/FileSystemHelper/FileWrapper.cs b/src/modules/launcher/Wox.Infrastructure/FileSystemHelper/FileWrapper.cs index b2c56f9bb9..244a8a77e7 100644 --- a/src/modules/launcher/Wox.Infrastructure/FileSystemHelper/FileWrapper.cs +++ b/src/modules/launcher/Wox.Infrastructure/FileSystemHelper/FileWrapper.cs @@ -2,7 +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.IO; using Wox.Infrastructure.Logger; @@ -10,7 +9,9 @@ namespace Wox.Infrastructure.FileSystemHelper { public class FileWrapper : IFileWrapper { - public FileWrapper() { } + public FileWrapper() + { + } public string[] ReadAllLines(string path) { @@ -21,7 +22,7 @@ namespace Wox.Infrastructure.FileSystemHelper catch (IOException ex) { Log.Info($"File {path} is being accessed by another process| {ex.Message}"); - return new string[] { String.Empty }; + return new string[] { string.Empty }; } } } diff --git a/src/modules/launcher/Wox.Infrastructure/Helper.cs b/src/modules/launcher/Wox.Infrastructure/Helper.cs index 51e1b0404d..9da3e31b75 100644 --- a/src/modules/launcher/Wox.Infrastructure/Helper.cs +++ b/src/modules/launcher/Wox.Infrastructure/Helper.cs @@ -73,11 +73,8 @@ namespace Wox.Infrastructure public static string Formatted(this T t) { - var formatted = JsonConvert.SerializeObject( - t, - Formatting.Indented, - new StringEnumConverter() - ); + var formatted = JsonConvert.SerializeObject(t, Formatting.Indented, new StringEnumConverter()); + return formatted; } @@ -89,7 +86,7 @@ namespace Wox.Infrastructure FileName = path, WorkingDirectory = Path.GetDirectoryName(path), Verb = "runas", - UseShellExecute = true + UseShellExecute = true, }; try @@ -107,7 +104,7 @@ namespace Wox.Infrastructure var processStartInfo = new ProcessStartInfo { WorkingDirectory = path, - FileName = "cmd.exe" + FileName = "cmd.exe", }; return Process.Start(processStartInfo); diff --git a/src/modules/launcher/Wox.Infrastructure/Hotkey/HotkeyModel.cs b/src/modules/launcher/Wox.Infrastructure/Hotkey/HotkeyModel.cs index ee91809cdd..7a4f8abba2 100644 --- a/src/modules/launcher/Wox.Infrastructure/Hotkey/HotkeyModel.cs +++ b/src/modules/launcher/Wox.Infrastructure/Hotkey/HotkeyModel.cs @@ -24,7 +24,7 @@ namespace Wox.Infrastructure.Hotkey Dictionary specialSymbolDictionary = new Dictionary { { Key.Space, "Space" }, - { Key.Oem3, "~" } + { Key.Oem3, "~" }, }; public ModifierKeys ModifierKeys @@ -81,7 +81,7 @@ namespace Wox.Infrastructure.Hotkey return; } - List keys = hotkeyString.Replace(" ", "").Split('+').ToList(); + List keys = hotkeyString.Replace(" ", string.Empty).Split('+').ToList(); if (keys.Contains("Alt")) { Alt = true; diff --git a/src/modules/launcher/Wox.Infrastructure/Hotkey/KeyEvent.cs b/src/modules/launcher/Wox.Infrastructure/Hotkey/KeyEvent.cs index 5ea5c1c423..e1e2d4416d 100644 --- a/src/modules/launcher/Wox.Infrastructure/Hotkey/KeyEvent.cs +++ b/src/modules/launcher/Wox.Infrastructure/Hotkey/KeyEvent.cs @@ -24,6 +24,6 @@ namespace Wox.Infrastructure.Hotkey /// /// System key down /// - WM_SYSKEYDOWN = 260 + WM_SYSKEYDOWN = 260, } } diff --git a/src/modules/launcher/Wox.Infrastructure/Http/Http.cs b/src/modules/launcher/Wox.Infrastructure/Http/Http.cs index d765fcbf3f..cdff6125d0 100644 --- a/src/modules/launcher/Wox.Infrastructure/Http/Http.cs +++ b/src/modules/launcher/Wox.Infrastructure/Http/Http.cs @@ -41,7 +41,7 @@ namespace Wox.Infrastructure.Http { var webProxy = new WebProxy(Proxy.Server, Proxy.Port) { - Credentials = new NetworkCredential(Proxy.UserName, Proxy.Password) + Credentials = new NetworkCredential(Proxy.UserName, Proxy.Password), }; return webProxy; } diff --git a/src/modules/launcher/Wox.Infrastructure/Image/ImageHashGenerator.cs b/src/modules/launcher/Wox.Infrastructure/Image/ImageHashGenerator.cs index a2510b0d0f..5530dec8ab 100644 --- a/src/modules/launcher/Wox.Infrastructure/Image/ImageHashGenerator.cs +++ b/src/modules/launcher/Wox.Infrastructure/Image/ImageHashGenerator.cs @@ -25,7 +25,6 @@ namespace Wox.Infrastructure.Image { // PngBitmapEncoder enc2 = new PngBitmapEncoder(); // enc2.Frames.Add(BitmapFrame.Create(tt)); - var enc = new JpegBitmapEncoder(); var bitmapFrame = BitmapFrame.Create(image); bitmapFrame.Freeze(); diff --git a/src/modules/launcher/Wox.Infrastructure/Image/ImageLoader.cs b/src/modules/launcher/Wox.Infrastructure/Image/ImageLoader.cs index d631f1a787..07177eedc3 100644 --- a/src/modules/launcher/Wox.Infrastructure/Image/ImageLoader.cs +++ b/src/modules/launcher/Wox.Infrastructure/Image/ImageLoader.cs @@ -33,7 +33,7 @@ namespace Wox.Infrastructure.Image ".gif", ".bmp", ".tiff", - ".ico" + ".ico", }; public static void Initialize(Theme theme) @@ -104,7 +104,7 @@ namespace Wox.Infrastructure.Image Data, ImageFile, Error, - Cache + Cache, } private static ImageResult LoadInternal(string path, bool loadFullImage = false) @@ -144,8 +144,7 @@ namespace Wox.Infrastructure.Image * - Solution: just load the icon */ type = ImageType.Folder; - image = WindowsThumbnailProvider.GetThumbnail(path, Constant.ThumbnailSize, - Constant.ThumbnailSize, ThumbnailOptions.IconOnly); + image = WindowsThumbnailProvider.GetThumbnail(path, Constant.ThumbnailSize, Constant.ThumbnailSize, ThumbnailOptions.IconOnly); } else if (File.Exists(path)) { @@ -164,15 +163,13 @@ namespace Wox.Infrastructure.Image * be the case in many situations while testing. * - Solution: explicitly pass the ThumbnailOnly flag */ - image = WindowsThumbnailProvider.GetThumbnail(path, Constant.ThumbnailSize, - Constant.ThumbnailSize, ThumbnailOptions.ThumbnailOnly); + image = WindowsThumbnailProvider.GetThumbnail(path, Constant.ThumbnailSize, Constant.ThumbnailSize, ThumbnailOptions.ThumbnailOnly); } } else { type = ImageType.File; - image = WindowsThumbnailProvider.GetThumbnail(path, Constant.ThumbnailSize, - Constant.ThumbnailSize, ThumbnailOptions.None); + image = WindowsThumbnailProvider.GetThumbnail(path, Constant.ThumbnailSize, Constant.ThumbnailSize, ThumbnailOptions.None); } } else diff --git a/src/modules/launcher/Wox.Infrastructure/Image/WindowsThumbnailProvider.cs b/src/modules/launcher/Wox.Infrastructure/Image/WindowsThumbnailProvider.cs index 37420c24a2..b82b0073e6 100644 --- a/src/modules/launcher/Wox.Infrastructure/Image/WindowsThumbnailProvider.cs +++ b/src/modules/launcher/Wox.Infrastructure/Image/WindowsThumbnailProvider.cs @@ -3,11 +3,11 @@ // See the LICENSE file in the project root for more information. using System; -using System.Runtime.InteropServices; using System.IO; +using System.Runtime.InteropServices; +using System.Windows; using System.Windows.Interop; using System.Windows.Media.Imaging; -using System.Windows; namespace Wox.Infrastructure.Image { @@ -66,7 +66,7 @@ namespace Wox.Infrastructure.Image PARENTRELATIVEEDITING = 0x80031001, DESKTOPABSOLUTEEDITING = 0x8004c000, FILESYSPATH = 0x80058000, - URL = 0x80068000 + URL = 0x80068000, } internal enum HResult @@ -84,7 +84,7 @@ namespace Wox.Infrastructure.Image Win32ErrorCanceled = 1223, Canceled = unchecked((int)0x800704C7), ResourceInUse = unchecked((int)0x800700AA), - AccessDenied = unchecked((int)0x80030005) + AccessDenied = unchecked((int)0x80030005), } [ComImportAttribute()] @@ -105,9 +105,15 @@ namespace Wox.Infrastructure.Image private int width; private int height; - public int Width { set { width = value; } } + public int Width + { + set { width = value; } + } - public int Height { set { height = value; } } + public int Height + { + set { height = value; } + } } public static BitmapSource GetThumbnail(string fileName, int width, int height, ThumbnailOptions options) @@ -132,12 +138,14 @@ namespace Wox.Infrastructure.Image int retCode = SHCreateItemFromParsingName(fileName, IntPtr.Zero, ref shellItem2Guid, out nativeShellItem); if (retCode != 0) + { throw Marshal.GetExceptionForHR(retCode); + } NativeSize nativeSize = new NativeSize { Width = width, - Height = height + Height = height, }; IntPtr hBitmap; @@ -151,7 +159,10 @@ namespace Wox.Infrastructure.Image Marshal.ReleaseComObject(nativeShellItem); - if (hr == HResult.Ok) return hBitmap; + if (hr == HResult.Ok) + { + return hBitmap; + } throw new COMException($"Error while extracting thumbnail for {fileName}", Marshal.GetExceptionForHR((int)hr)); } diff --git a/src/modules/launcher/Wox.Infrastructure/Logger/Log.cs b/src/modules/launcher/Wox.Infrastructure/Logger/Log.cs index cb1d2b8cb9..b7c8a794da 100644 --- a/src/modules/launcher/Wox.Infrastructure/Logger/Log.cs +++ b/src/modules/launcher/Wox.Infrastructure/Logger/Log.cs @@ -100,7 +100,8 @@ namespace Wox.Infrastructure.Logger logger.Error($"Exception target site:\n <{e.TargetSite}>"); logger.Error($"Exception HResult:\n <{e.HResult}>"); e = e.InnerException; - } while (e != null); + } + while (e != null); logger.Error("-------------------------- End exception --------------------------"); } diff --git a/src/modules/launcher/Wox.Infrastructure/MatchOption.cs b/src/modules/launcher/Wox.Infrastructure/MatchOption.cs new file mode 100644 index 0000000000..53461a1e4d --- /dev/null +++ b/src/modules/launcher/Wox.Infrastructure/MatchOption.cs @@ -0,0 +1,28 @@ +// 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.Runtime.CompilerServices; + +[assembly: InternalsVisibleToAttribute("Microsoft.Plugin.Program.UnitTests")] + +namespace Wox.Infrastructure +{ + public class MatchOption + { + /// + /// Gets or sets prefix of match char, use for highlight + /// + [Obsolete("this is never used")] + public string Prefix { get; set; } = string.Empty; + + /// + /// Gets or sets suffix of match char, use for highlight + /// + [Obsolete("this is never used")] + public string Suffix { get; set; } = string.Empty; + + public bool IgnoreCase { get; set; } = true; + } +} diff --git a/src/modules/launcher/Wox.Infrastructure/MatchResult.cs b/src/modules/launcher/Wox.Infrastructure/MatchResult.cs new file mode 100644 index 0000000000..266b2eb44f --- /dev/null +++ b/src/modules/launcher/Wox.Infrastructure/MatchResult.cs @@ -0,0 +1,77 @@ +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Collections.Generic; +using System.Runtime.CompilerServices; +using static Wox.Infrastructure.StringMatcher; + +[assembly: InternalsVisibleToAttribute("Microsoft.Plugin.Program.UnitTests")] + +namespace Wox.Infrastructure +{ + public class MatchResult + { + public MatchResult(bool success, SearchPrecisionScore searchPrecision) + { + Success = success; + SearchPrecision = searchPrecision; + } + + public MatchResult(bool success, SearchPrecisionScore searchPrecision, List matchData, int rawScore) + { + Success = success; + SearchPrecision = searchPrecision; + MatchData = matchData; + RawScore = rawScore; + } + + public bool Success { get; set; } + + /// + /// Gets the final score of the match result with search precision filters applied. + /// + public int Score { get; private set; } + + /// + /// The raw calculated search score without any search precision filtering applied. + /// + private int _rawScore; + + public int RawScore + { + get + { + return _rawScore; + } + + set + { + _rawScore = value; + Score = ScoreAfterSearchPrecisionFilter(_rawScore); + } + } + + /// + /// Gets or sets matched data to highlight. + /// + public List MatchData { get; set; } + + public SearchPrecisionScore SearchPrecision { get; set; } + + public bool IsSearchPrecisionScoreMet() + { + return IsSearchPrecisionScoreMet(_rawScore); + } + + private bool IsSearchPrecisionScoreMet(int rawScore) + { + return rawScore >= (int)SearchPrecision; + } + + private int ScoreAfterSearchPrecisionFilter(int rawScore) + { + return IsSearchPrecisionScoreMet(rawScore) ? rawScore : 0; + } + } +} diff --git a/src/modules/launcher/Wox.Infrastructure/Storage/BinaryStorage`1.cs b/src/modules/launcher/Wox.Infrastructure/Storage/BinaryStorage`1.cs index 833f869b50..ef1cc76614 100644 --- a/src/modules/launcher/Wox.Infrastructure/Storage/BinaryStorage`1.cs +++ b/src/modules/launcher/Wox.Infrastructure/Storage/BinaryStorage`1.cs @@ -77,7 +77,7 @@ namespace Wox.Infrastructure.Storage AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve; BinaryFormatter binaryFormatter = new BinaryFormatter { - AssemblyFormat = FormatterAssemblyStyle.Simple + AssemblyFormat = FormatterAssemblyStyle.Simple, }; try @@ -119,7 +119,7 @@ namespace Wox.Infrastructure.Storage { BinaryFormatter binaryFormatter = new BinaryFormatter { - AssemblyFormat = FormatterAssemblyStyle.Simple + AssemblyFormat = FormatterAssemblyStyle.Simple, }; try diff --git a/src/modules/launcher/Wox.Infrastructure/Storage/FileSystemWatcherWrapper.cs b/src/modules/launcher/Wox.Infrastructure/Storage/FileSystemWatcherWrapper.cs index a4a50b6fdb..1555608835 100644 --- a/src/modules/launcher/Wox.Infrastructure/Storage/FileSystemWatcherWrapper.cs +++ b/src/modules/launcher/Wox.Infrastructure/Storage/FileSystemWatcherWrapper.cs @@ -10,7 +10,9 @@ namespace Wox.Infrastructure.Storage // File System Watcher Wrapper class which implements the IFileSystemWatcherWrapper interface public class FileSystemWatcherWrapper : FileSystemWatcher, IFileSystemWatcherWrapper { - public FileSystemWatcherWrapper() { } + public FileSystemWatcherWrapper() + { + } Collection IFileSystemWatcherWrapper.Filters { diff --git a/src/modules/launcher/Wox.Infrastructure/Storage/JsonStorage`1.cs b/src/modules/launcher/Wox.Infrastructure/Storage/JsonStorage`1.cs index 08046eb2d4..7f34ecca80 100644 --- a/src/modules/launcher/Wox.Infrastructure/Storage/JsonStorage`1.cs +++ b/src/modules/launcher/Wox.Infrastructure/Storage/JsonStorage`1.cs @@ -37,7 +37,7 @@ namespace Wox.Infrastructure.Storage _serializerSettings = new JsonSerializerSettings { ObjectCreationHandling = ObjectCreationHandling.Replace, - NullValueHandling = NullValueHandling.Ignore + NullValueHandling = NullValueHandling.Ignore, }; } diff --git a/src/modules/launcher/Wox.Infrastructure/Storage/ListRepository`1.cs b/src/modules/launcher/Wox.Infrastructure/Storage/ListRepository`1.cs index 736405df1b..dd0759a907 100644 --- a/src/modules/launcher/Wox.Infrastructure/Storage/ListRepository`1.cs +++ b/src/modules/launcher/Wox.Infrastructure/Storage/ListRepository`1.cs @@ -18,7 +18,10 @@ namespace Wox.Infrastructure.Storage /// typeof public class ListRepository : IRepository, IEnumerable { - public IList Items { get { return _items.Values.ToList(); } } + public IList Items + { + get { return _items.Values.ToList(); } + } private ConcurrentDictionary _items = new ConcurrentDictionary(); diff --git a/src/modules/launcher/Wox.Infrastructure/Storage/PluginJsonStorage`1.cs b/src/modules/launcher/Wox.Infrastructure/Storage/PluginJsonStorage`1.cs index 6f3e259a10..b8353ff943 100644 --- a/src/modules/launcher/Wox.Infrastructure/Storage/PluginJsonStorage`1.cs +++ b/src/modules/launcher/Wox.Infrastructure/Storage/PluginJsonStorage`1.cs @@ -6,7 +6,8 @@ using System.IO; namespace Wox.Infrastructure.Storage { - public class PluginJsonStorage : JsonStorage where T : new() + public class PluginJsonStorage : JsonStorage + where T : new() { public PluginJsonStorage() { diff --git a/src/modules/launcher/Wox.Infrastructure/Storage/StoragePowerToysVersionInfo.cs b/src/modules/launcher/Wox.Infrastructure/Storage/StoragePowerToysVersionInfo.cs index 84811cbf4f..dea054c347 100644 --- a/src/modules/launcher/Wox.Infrastructure/Storage/StoragePowerToysVersionInfo.cs +++ b/src/modules/launcher/Wox.Infrastructure/Storage/StoragePowerToysVersionInfo.cs @@ -12,16 +12,16 @@ namespace Wox.Infrastructure.Storage // This detail is accessed by the storage items and is used to decide if the cache must be deleted or not public bool clearCache = false; - private String currentPowerToysVersion = String.Empty; + private string currentPowerToysVersion = string.Empty; - private String FilePath { get; set; } = String.Empty; + private string FilePath { get; set; } = string.Empty; // As of now this information is not pertinent but may be in the future // There may be cases when we want to delete only the .cache files and not the .json storage files private enum StorageType { BINARY_STORAGE = 0, - JSON_STORAGE = 1 + JSON_STORAGE = 1, } // To compare the version numbers @@ -33,7 +33,7 @@ namespace Wox.Infrastructure.Storage // If there is some error in populating/retrieving the version numbers, then the cache must be deleted // This case will not be hit, but is present as a fail safe - if (String.IsNullOrEmpty(version1) || String.IsNullOrEmpty(version2)) + if (string.IsNullOrEmpty(version1) || string.IsNullOrEmpty(version2)) { return true; } @@ -81,7 +81,7 @@ namespace Wox.Infrastructure.Storage } } - private string GetFilePath(String AssociatedFilePath, int type) + private string GetFilePath(string AssociatedFilePath, int type) { string suffix = string.Empty; string cacheSuffix = ".cache"; @@ -100,12 +100,12 @@ namespace Wox.Infrastructure.Storage return filePath; } - public StoragePowerToysVersionInfo(String AssociatedFilePath, int type) + public StoragePowerToysVersionInfo(string AssociatedFilePath, int type) { FilePath = GetFilePath(AssociatedFilePath, type); // Get the previous version of PowerToys and cache Storage details from the CacheDetails.json storage file - String previousVersion = GetPreviousVersion(); + string previousVersion = GetPreviousVersion(); currentPowerToysVersion = Microsoft.PowerToys.Settings.UI.Lib.Utilities.Helper.GetProductVersion(); // If the previous version is below a set threshold, then we want to delete the file diff --git a/src/modules/launcher/Wox.Infrastructure/Storage/WoxJsonStorage`1.cs b/src/modules/launcher/Wox.Infrastructure/Storage/WoxJsonStorage`1.cs index dc8cf91a2b..5ab52fe2e9 100644 --- a/src/modules/launcher/Wox.Infrastructure/Storage/WoxJsonStorage`1.cs +++ b/src/modules/launcher/Wox.Infrastructure/Storage/WoxJsonStorage`1.cs @@ -6,7 +6,8 @@ using System.IO; namespace Wox.Infrastructure.Storage { - public class WoxJsonStorage : JsonStorage where T : new() + public class WoxJsonStorage : JsonStorage + where T : new() { public WoxJsonStorage() { diff --git a/src/modules/launcher/Wox.Infrastructure/StringMatcher.cs b/src/modules/launcher/Wox.Infrastructure/StringMatcher.cs index d6b6104965..1b2d4c5a92 100644 --- a/src/modules/launcher/Wox.Infrastructure/StringMatcher.cs +++ b/src/modules/launcher/Wox.Infrastructure/StringMatcher.cs @@ -6,7 +6,6 @@ using System; using System.Collections.Generic; using System.Linq; using System.Runtime.CompilerServices; -using static Wox.Infrastructure.StringMatcher; [assembly: InternalsVisibleToAttribute("Microsoft.Plugin.Program.UnitTests")] @@ -62,7 +61,10 @@ namespace Wox.Infrastructure /// public MatchResult FuzzyMatch(string query, string stringToCompare, MatchOption opt) { - if (string.IsNullOrEmpty(stringToCompare) || string.IsNullOrEmpty(query)) return new MatchResult(false, UserSettingSearchPrecision); + if (string.IsNullOrEmpty(stringToCompare) || string.IsNullOrEmpty(query)) + { + return new MatchResult(false, UserSettingSearchPrecision); + } query = query.Trim(); @@ -93,7 +95,6 @@ namespace Wox.Infrastructure for (var compareStringIndex = 0; 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 if (fullStringToCompareWithoutCase[compareStringIndex].Equals(' ') && currentQuerySubstringIndex == 0) @@ -150,10 +151,12 @@ namespace Wox.Infrastructure currentQuerySubstringIndex++; allQuerySubstringsMatched = AllQuerySubstringsMatched(currentQuerySubstringIndex, querySubstrings.Length); - if (allQuerySubstringsMatched) - break; - - // otherwise move to the next query substring + if (allQuerySubstringsMatched) + { + break; + } + + // otherwise move to the next query substring currentQuerySubstring = querySubstrings[currentQuerySubstringIndex]; currentQuerySubstringCharacterIndex = 0; } @@ -186,8 +189,7 @@ namespace Wox.Infrastructure } } - private static bool AllPreviousCharsMatched(int startIndexToVerify, int currentQuerySubstringCharacterIndex, - string fullStringToCompareWithoutCase, string currentQuerySubstring) + private static bool AllPreviousCharsMatched(int startIndexToVerify, int currentQuerySubstringCharacterIndex, string fullStringToCompareWithoutCase, string currentQuerySubstring) { var allMatch = true; for (int indexToCheck = 0; indexToCheck < currentQuerySubstringCharacterIndex; indexToCheck++) @@ -250,11 +252,11 @@ namespace Wox.Infrastructure } else { - score += threshold * 10 + (count - threshold) * 5; + score += (threshold * 10) + ((count - threshold) * 5); } } - if (String.Equals(query, stringToCompare, StringComparison.CurrentCultureIgnoreCase)) + if (string.Equals(query, stringToCompare, StringComparison.CurrentCultureIgnoreCase)) { var bonusForExactMatch = 10; score += bonusForExactMatch; @@ -267,86 +269,7 @@ namespace Wox.Infrastructure { Regular = 50, Low = 20, - None = 0 + None = 0, } } - - public class MatchResult - { - public MatchResult(bool success, SearchPrecisionScore searchPrecision) - { - Success = success; - SearchPrecision = searchPrecision; - } - - public MatchResult(bool success, SearchPrecisionScore searchPrecision, List matchData, int rawScore) - { - Success = success; - SearchPrecision = searchPrecision; - MatchData = matchData; - RawScore = rawScore; - } - - public bool Success { get; set; } - - /// - /// The final score of the match result with search precision filters applied. - /// - public int Score { get; private set; } - - /// - /// The raw calculated search score without any search precision filtering applied. - /// - private int _rawScore; - - public int RawScore - { - get { return _rawScore; } - - set - { - _rawScore = value; - Score = ScoreAfterSearchPrecisionFilter(_rawScore); - } - } - - /// - /// Matched data to highlight. - /// - public List MatchData { get; set; } - - public SearchPrecisionScore SearchPrecision { get; set; } - - public bool IsSearchPrecisionScoreMet() - { - return IsSearchPrecisionScoreMet(_rawScore); - } - - private bool IsSearchPrecisionScoreMet(int rawScore) - { - return rawScore >= (int)SearchPrecision; - } - - private int ScoreAfterSearchPrecisionFilter(int rawScore) - { - return IsSearchPrecisionScoreMet(rawScore) ? rawScore : 0; - } - } - - public class MatchOption - { - /// - /// prefix of match char, use for highlight - /// - [Obsolete("this is never used")] - public string Prefix { get; set; } = ""; - - /// - /// suffix of match char, use for highlight - /// - [Obsolete("this is never used")] - public string Suffix { get; set; } = ""; - - public bool IgnoreCase { get; set; } = true; - } } diff --git a/src/modules/launcher/Wox.Infrastructure/UserSettings/PluginSettings.cs b/src/modules/launcher/Wox.Infrastructure/UserSettings/PluginSettings.cs index de267c669f..d975aa6f79 100644 --- a/src/modules/launcher/Wox.Infrastructure/UserSettings/PluginSettings.cs +++ b/src/modules/launcher/Wox.Infrastructure/UserSettings/PluginSettings.cs @@ -33,7 +33,7 @@ namespace Wox.Infrastructure.UserSettings ID = metadata.ID, Name = metadata.Name, ActionKeywords = metadata.ActionKeywords, - Disabled = metadata.Disabled + Disabled = metadata.Disabled, }; } } diff --git a/src/modules/launcher/Wox.Infrastructure/UserSettings/Settings.cs b/src/modules/launcher/Wox.Infrastructure/UserSettings/Settings.cs index 356fd79205..6d65147607 100644 --- a/src/modules/launcher/Wox.Infrastructure/UserSettings/Settings.cs +++ b/src/modules/launcher/Wox.Infrastructure/UserSettings/Settings.cs @@ -14,7 +14,7 @@ namespace Wox.Infrastructure.UserSettings public class Settings : BaseModel { private string _hotkey = "Alt + Space"; - private string _previousHotkey = ""; + private string _previousHotkey = string.Empty; public string PreviousHotkey { @@ -63,7 +63,7 @@ namespace Wox.Infrastructure.UserSettings public string ResultFontStretch { get; set; } /// - /// when false Alphabet static service will always return empty results + /// Gets or sets a value indicating whether when false Alphabet static service will always return empty results /// public bool ShouldUsePinyin { get; set; } = false; @@ -72,10 +72,13 @@ namespace Wox.Infrastructure.UserSettings [JsonIgnore] public string QuerySearchPrecisionString { - get { return QuerySearchPrecision.ToString(); } + get + { + return QuerySearchPrecision.ToString(); + } - set - { + set + { try { var precisionScore = (StringMatcher.SearchPrecisionScore)Enum @@ -92,8 +95,8 @@ namespace Wox.Infrastructure.UserSettings StringMatcher.Instance.UserSettingSearchPrecision = StringMatcher.SearchPrecisionScore.Regular; throw; - } - } + } + } } public bool AutoUpdates { get; set; } = false; @@ -143,17 +146,20 @@ namespace Wox.Infrastructure.UserSettings public bool HideOnStartup { get; set; } - bool _hideNotifyIcon { get; set; } + private bool _hideNotifyIcon; public bool HideNotifyIcon { - get { return _hideNotifyIcon; } + get + { + return _hideNotifyIcon; + } - set - { - _hideNotifyIcon = value; - OnPropertyChanged(); - } + set + { + _hideNotifyIcon = value; + OnPropertyChanged(); + } } public bool LeaveCmdOpen { get; set; } @@ -176,7 +182,7 @@ namespace Wox.Infrastructure.UserSettings { Selected, Empty, - Preserved + Preserved, } [Obsolete] @@ -184,6 +190,6 @@ namespace Wox.Infrastructure.UserSettings { Normal = 0, LayeredWindow = 1, - DWM = 2 + DWM = 2, } }