Skip to content

Commit

Permalink
more fixes for getting styleCop up, this will need one more push to g…
Browse files Browse the repository at this point in the history
…et another 15 that will require renaming of vars (#5875)
  • Loading branch information
crutkas committed Aug 11, 2020
1 parent 90502f7 commit 2c49df4
Show file tree
Hide file tree
Showing 24 changed files with 255 additions and 181 deletions.
34 changes: 20 additions & 14 deletions src/modules/launcher/Wox.Infrastructure/Alphabet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ namespace Wox.Infrastructure
{
public class Alphabet : IAlphabet
{
private readonly HanyuPinyinOutputFormat Format = new HanyuPinyinOutputFormat();
private ConcurrentDictionary<string, string[][]> PinyinCache;
private readonly HanyuPinyinOutputFormat _pinyinFormat = new HanyuPinyinOutputFormat();
private ConcurrentDictionary<string, string[][]> _pinyinCache;
private BinaryStorage<Dictionary<string, string[][]>> _pinyinStorage;
private Settings _settings;

Expand All @@ -31,17 +31,17 @@ public void Initialize([NotNull] Settings settings)

private void InitializePinyinHelpers()
{
Format.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
_pinyinFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE);

Stopwatch.Normal("|Wox.Infrastructure.Alphabet.Initialize|Preload pinyin cache", () =>
{
_pinyinStorage = new BinaryStorage<Dictionary<string, string[][]>>("Pinyin");
SetPinyinCacheAsDictionary(_pinyinStorage.TryLoad(new Dictionary<string, string[][]>()));
// 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)
Expand All @@ -52,17 +52,23 @@ public string Translate(string str)
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();
Expand All @@ -85,11 +91,11 @@ public void Save()
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 ")]
/// <summary>
/// replace chinese character with pinyin, non chinese character won't be modified
/// <param name="word"> should be word or sentence, instead of single character. e.g. 微软 </param>
/// </summary>
[Obsolete("Not accurate, eg 音乐 will not return yinyue but returns yinle ")]
public string[] Pinyin(string word)
{
if (!_settings.ShouldUsePinyin)
Expand Down Expand Up @@ -119,12 +125,12 @@ public string[][] PinyinCombination(string characters)
return Empty2DStringArray;
}

if (!PinyinCache.ContainsKey(characters))
if (!_pinyinCache.ContainsKey(characters))
{
var allPinyins = new List<string[]>();
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();
Expand All @@ -138,18 +144,18 @@ public string[][] PinyinCombination(string characters)
}

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;
}

Expand Down Expand Up @@ -188,12 +194,12 @@ private string[] Combination(string[] array1, string[] array2)

private Dictionary<string, string[][]> GetPinyinCacheAsDictionary()
{
return new Dictionary<string, string[][]>(PinyinCache);
return new Dictionary<string, string[][]>(_pinyinCache);
}

private void SetPinyinCacheAsDictionary(Dictionary<string, string[][]> usage)
{
PinyinCache = new ConcurrentDictionary<string, string[][]>(usage);
_pinyinCache = new ConcurrentDictionary<string, string[][]>(usage);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,33 +121,46 @@ private static List<string> GetFrameworkVersionFromRegistry()
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;
}

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));
}
}
}
}
Expand All @@ -159,13 +172,19 @@ private static List<string> GetFrameworkVersionFromRegistry()
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");
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ namespace Wox.Infrastructure.FileSystemHelper
{
public class FileVersionInfoWrapper : IFileVersionInfoWrapper
{
public FileVersionInfoWrapper() { }
public FileVersionInfoWrapper()
{
}

public FileVersionInfo GetVersionInfo(string path)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
// 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;

namespace Wox.Infrastructure.FileSystemHelper
{
public class FileWrapper : IFileWrapper
{
public FileWrapper() { }
public FileWrapper()
{
}

public string[] ReadAllLines(string path)
{
Expand All @@ -21,7 +22,7 @@ public string[] ReadAllLines(string path)
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 };
}
}
}
Expand Down
11 changes: 4 additions & 7 deletions src/modules/launcher/Wox.Infrastructure/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,8 @@ public static void ValidateDirectory(string path)

public static string Formatted<T>(this T t)
{
var formatted = JsonConvert.SerializeObject(
t,
Formatting.Indented,
new StringEnumConverter()
);
var formatted = JsonConvert.SerializeObject(t, Formatting.Indented, new StringEnumConverter());

return formatted;
}

Expand All @@ -89,7 +86,7 @@ public static void RunAsAdmin(string path)
FileName = path,
WorkingDirectory = Path.GetDirectoryName(path),
Verb = "runas",
UseShellExecute = true
UseShellExecute = true,
};

try
Expand All @@ -107,7 +104,7 @@ public static Process OpenInConsole(string path)
var processStartInfo = new ProcessStartInfo
{
WorkingDirectory = path,
FileName = "cmd.exe"
FileName = "cmd.exe",
};

return Process.Start(processStartInfo);
Expand Down
4 changes: 2 additions & 2 deletions src/modules/launcher/Wox.Infrastructure/Hotkey/HotkeyModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class HotkeyModel
Dictionary<Key, string> specialSymbolDictionary = new Dictionary<Key, string>
{
{ Key.Space, "Space" },
{ Key.Oem3, "~" }
{ Key.Oem3, "~" },
};

public ModifierKeys ModifierKeys
Expand Down Expand Up @@ -81,7 +81,7 @@ private void Parse(string hotkeyString)
return;
}

List<string> keys = hotkeyString.Replace(" ", "").Split('+').ToList();
List<string> keys = hotkeyString.Replace(" ", string.Empty).Split('+').ToList();
if (keys.Contains("Alt"))
{
Alt = true;
Expand Down
2 changes: 1 addition & 1 deletion src/modules/launcher/Wox.Infrastructure/Hotkey/KeyEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ public enum KeyEvent
/// <summary>
/// System key down
/// </summary>
WM_SYSKEYDOWN = 260
WM_SYSKEYDOWN = 260,
}
}
2 changes: 1 addition & 1 deletion src/modules/launcher/Wox.Infrastructure/Http/Http.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static IWebProxy WebProxy()
{
var webProxy = new WebProxy(Proxy.Server, Proxy.Port)
{
Credentials = new NetworkCredential(Proxy.UserName, Proxy.Password)
Credentials = new NetworkCredential(Proxy.UserName, Proxy.Password),
};
return webProxy;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public string GetHashFromImage(ImageSource imageSource)
{
// PngBitmapEncoder enc2 = new PngBitmapEncoder();
// enc2.Frames.Add(BitmapFrame.Create(tt));

var enc = new JpegBitmapEncoder();
var bitmapFrame = BitmapFrame.Create(image);
bitmapFrame.Freeze();
Expand Down
13 changes: 5 additions & 8 deletions src/modules/launcher/Wox.Infrastructure/Image/ImageLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static class ImageLoader
".gif",
".bmp",
".tiff",
".ico"
".ico",
};

public static void Initialize(Theme theme)
Expand Down Expand Up @@ -104,7 +104,7 @@ private enum ImageType
Data,
ImageFile,
Error,
Cache
Cache,
}

private static ImageResult LoadInternal(string path, bool loadFullImage = false)
Expand Down Expand Up @@ -144,8 +144,7 @@ private static ImageResult LoadInternal(string path, bool loadFullImage = false)
* - 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))
{
Expand All @@ -164,15 +163,13 @@ private static ImageResult LoadInternal(string path, bool loadFullImage = false)
* 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
Expand Down

0 comments on commit 2c49df4

Please sign in to comment.