mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 10:46:33 +02:00
fixing all warnings and info for infra (#5891)
This commit is contained in:
@@ -88,8 +88,8 @@ namespace Wox.Infrastructure
|
||||
_pinyinStorage.Save(GetPinyinCacheAsDictionary());
|
||||
}
|
||||
|
||||
private static string[] EmptyStringArray = new string[0];
|
||||
private static string[][] Empty2DStringArray = new string[0][];
|
||||
private static readonly string[] _emptyStringArray = new string[0];
|
||||
private static readonly string[][] _empty2DStringArray = new string[0][];
|
||||
|
||||
/// <summary>
|
||||
/// replace chinese character with pinyin, non chinese character won't be modified
|
||||
@@ -100,7 +100,7 @@ namespace Wox.Infrastructure
|
||||
{
|
||||
if (!_settings.ShouldUsePinyin)
|
||||
{
|
||||
return EmptyStringArray;
|
||||
return _emptyStringArray;
|
||||
}
|
||||
|
||||
var pinyin = word.Select(c =>
|
||||
@@ -122,7 +122,7 @@ namespace Wox.Infrastructure
|
||||
{
|
||||
if (!_settings.ShouldUsePinyin || string.IsNullOrEmpty(characters))
|
||||
{
|
||||
return Empty2DStringArray;
|
||||
return _empty2DStringArray;
|
||||
}
|
||||
|
||||
if (!_pinyinCache.ContainsKey(characters))
|
||||
@@ -181,7 +181,7 @@ namespace Wox.Infrastructure
|
||||
{
|
||||
if (!_settings.ShouldUsePinyin)
|
||||
{
|
||||
return EmptyStringArray;
|
||||
return _emptyStringArray;
|
||||
}
|
||||
|
||||
var combination = (
|
||||
|
||||
@@ -14,14 +14,15 @@ namespace Wox.Infrastructure
|
||||
public const string ExeFileName = "PowerLauncher";
|
||||
public const string ModuleLocation = "Microsoft\\PowerToys\\PowerToys Run";
|
||||
public const string Plugins = "Plugins";
|
||||
public const string PortableFolderName = "UserData";
|
||||
|
||||
private static readonly Assembly Assembly = Assembly.GetExecutingAssembly();
|
||||
public static readonly string ProgramDirectory = Directory.GetParent(Assembly.Location.NonNull()).ToString();
|
||||
public static readonly string ExecutablePath = Path.Combine(ProgramDirectory, ExeFileName + ".exe");
|
||||
|
||||
public static bool IsPortableMode;
|
||||
public const string PortableFolderName = "UserData";
|
||||
public static string PortableDataPath = Path.Combine(ProgramDirectory, PortableFolderName);
|
||||
public static bool IsPortableMode { get; set; }
|
||||
|
||||
public static string PortableDataPath { get; set; } = Path.Combine(ProgramDirectory, PortableFolderName);
|
||||
|
||||
public static string DetermineDataDirectory()
|
||||
{
|
||||
|
||||
@@ -190,7 +190,7 @@ namespace Wox.Infrastructure.Exception
|
||||
|
||||
return result;
|
||||
}
|
||||
catch (System.Exception e)
|
||||
catch (System.Exception)
|
||||
{
|
||||
return new List<string>();
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace Wox.Infrastructure.Hotkey
|
||||
|
||||
public Key CharKey { get; set; }
|
||||
|
||||
Dictionary<Key, string> specialSymbolDictionary = new Dictionary<Key, string>
|
||||
private readonly Dictionary<Key, string> _specialSymbolDictionary = new Dictionary<Key, string>
|
||||
{
|
||||
{ Key.Space, "Space" },
|
||||
{ Key.Oem3, "~" },
|
||||
@@ -32,6 +32,7 @@ namespace Wox.Infrastructure.Hotkey
|
||||
get
|
||||
{
|
||||
ModifierKeys modifierKeys = ModifierKeys.None;
|
||||
|
||||
if (Alt)
|
||||
{
|
||||
modifierKeys = ModifierKeys.Alt;
|
||||
@@ -39,17 +40,17 @@ namespace Wox.Infrastructure.Hotkey
|
||||
|
||||
if (Shift)
|
||||
{
|
||||
modifierKeys = modifierKeys | ModifierKeys.Shift;
|
||||
modifierKeys |= ModifierKeys.Shift;
|
||||
}
|
||||
|
||||
if (Win)
|
||||
{
|
||||
modifierKeys = modifierKeys | ModifierKeys.Windows;
|
||||
modifierKeys |= ModifierKeys.Windows;
|
||||
}
|
||||
|
||||
if (Ctrl)
|
||||
{
|
||||
modifierKeys = modifierKeys | ModifierKeys.Control;
|
||||
modifierKeys |= ModifierKeys.Control;
|
||||
}
|
||||
|
||||
return modifierKeys;
|
||||
@@ -109,7 +110,7 @@ namespace Wox.Infrastructure.Hotkey
|
||||
if (keys.Count > 0)
|
||||
{
|
||||
string charKey = keys[0];
|
||||
KeyValuePair<Key, string>? specialSymbolPair = specialSymbolDictionary.FirstOrDefault(pair => pair.Value == charKey);
|
||||
KeyValuePair<Key, string>? specialSymbolPair = _specialSymbolDictionary.FirstOrDefault(pair => pair.Value == charKey);
|
||||
if (specialSymbolPair.Value.Value != null)
|
||||
{
|
||||
CharKey = specialSymbolPair.Value.Key;
|
||||
@@ -152,8 +153,8 @@ namespace Wox.Infrastructure.Hotkey
|
||||
|
||||
if (CharKey != Key.None)
|
||||
{
|
||||
text += specialSymbolDictionary.ContainsKey(CharKey)
|
||||
? specialSymbolDictionary[CharKey]
|
||||
text += _specialSymbolDictionary.ContainsKey(CharKey)
|
||||
? _specialSymbolDictionary[CharKey]
|
||||
: CharKey.ToString();
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(text))
|
||||
|
||||
@@ -14,9 +14,11 @@ namespace Wox.Infrastructure.Image
|
||||
public class ImageCache
|
||||
{
|
||||
private const int MaxCached = 50;
|
||||
public ConcurrentDictionary<string, int> Usage = new ConcurrentDictionary<string, int>();
|
||||
private const int PermissibleFactor = 2;
|
||||
|
||||
private readonly ConcurrentDictionary<string, ImageSource> _data = new ConcurrentDictionary<string, ImageSource>();
|
||||
private const int permissibleFactor = 2;
|
||||
|
||||
public ConcurrentDictionary<string, int> Usage { get; set; } = new ConcurrentDictionary<string, int>();
|
||||
|
||||
public ImageSource this[string path]
|
||||
{
|
||||
@@ -33,7 +35,7 @@ namespace Wox.Infrastructure.Image
|
||||
|
||||
// To prevent the dictionary from drastically increasing in size by caching images, the dictionary size is not allowed to grow more than the permissibleFactor * maxCached size
|
||||
// This is done so that we don't constantly perform this resizing operation and also maintain the image cache size at the same time
|
||||
if (_data.Count > permissibleFactor * MaxCached)
|
||||
if (_data.Count > PermissibleFactor * MaxCached)
|
||||
{
|
||||
// This function resizes the Usage dictionary, taking the top 'maxCached' number of items and filtering the image icons that are not accessed frequently.
|
||||
Cleanup();
|
||||
@@ -41,11 +43,9 @@ namespace Wox.Infrastructure.Image
|
||||
// To delete the images from the data dictionary based on the resizing of the Usage Dictionary.
|
||||
foreach (var key in _data.Keys)
|
||||
{
|
||||
int dictValue;
|
||||
if (!Usage.TryGetValue(key, out dictValue) && !(key.Equals(Constant.ErrorIcon) || key.Equals(Constant.DefaultIcon) || key.Equals(Constant.LightThemedErrorIcon) || key.Equals(Constant.LightThemedDefaultIcon)))
|
||||
if (!Usage.TryGetValue(key, out _) && !(key.Equals(Constant.ErrorIcon) || key.Equals(Constant.DefaultIcon) || key.Equals(Constant.LightThemedErrorIcon) || key.Equals(Constant.LightThemedDefaultIcon)))
|
||||
{
|
||||
ImageSource imgSource;
|
||||
_data.TryRemove(key, out imgSource);
|
||||
_data.TryRemove(key, out _);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,11 +19,14 @@ namespace Wox.Infrastructure.Image
|
||||
public static class ImageLoader
|
||||
{
|
||||
private static readonly ImageCache ImageCache = new ImageCache();
|
||||
private static BinaryStorage<Dictionary<string, int>> _storage;
|
||||
private static readonly ConcurrentDictionary<string, string> GuidToKey = new ConcurrentDictionary<string, string>();
|
||||
|
||||
private static BinaryStorage<Dictionary<string, int>> _storage;
|
||||
private static IImageHashGenerator _hashGenerator;
|
||||
public static string ErrorIconPath;
|
||||
public static string DefaultIconPath;
|
||||
|
||||
public static string ErrorIconPath { get; set; }
|
||||
|
||||
public static string DefaultIconPath { get; set; }
|
||||
|
||||
private static readonly string[] ImageExtensions =
|
||||
{
|
||||
@@ -194,7 +197,7 @@ namespace Wox.Infrastructure.Image
|
||||
return new ImageResult(image, type);
|
||||
}
|
||||
|
||||
private static bool EnableImageHash = true;
|
||||
private static readonly bool _enableImageHash = true;
|
||||
|
||||
public static ImageSource Load(string path, bool loadFullImage = false)
|
||||
{
|
||||
@@ -202,20 +205,23 @@ namespace Wox.Infrastructure.Image
|
||||
|
||||
var img = imageResult.ImageSource;
|
||||
if (imageResult.ImageType != ImageType.Error && imageResult.ImageType != ImageType.Cache)
|
||||
{ // we need to get image hash
|
||||
string hash = EnableImageHash ? _hashGenerator.GetHashFromImage(img) : null;
|
||||
{
|
||||
// we need to get image hash
|
||||
string hash = _enableImageHash ? _hashGenerator.GetHashFromImage(img) : null;
|
||||
|
||||
if (hash != null)
|
||||
{
|
||||
int ImageCacheValue;
|
||||
if (GuidToKey.TryGetValue(hash, out string key))
|
||||
{ // image already exists
|
||||
if (ImageCache.Usage.TryGetValue(path, out ImageCacheValue))
|
||||
{
|
||||
// image already exists
|
||||
if (ImageCache.Usage.TryGetValue(path, out _))
|
||||
{
|
||||
img = ImageCache[key];
|
||||
}
|
||||
}
|
||||
else
|
||||
{ // new guid
|
||||
{
|
||||
// new guid
|
||||
GuidToKey[hash] = path;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,8 @@ namespace Wox.Infrastructure.Image
|
||||
[Guid("43826d1e-e718-42ee-bc55-a1e261c37bfe")]
|
||||
internal interface IShellItem
|
||||
{
|
||||
void BindToHandler(IntPtr pbc,
|
||||
void BindToHandler(
|
||||
IntPtr pbc,
|
||||
[MarshalAs(UnmanagedType.LPStruct)] Guid bhid,
|
||||
[MarshalAs(UnmanagedType.LPStruct)] Guid riid,
|
||||
out IntPtr ppv);
|
||||
@@ -87,9 +88,9 @@ namespace Wox.Infrastructure.Image
|
||||
AccessDenied = unchecked((int)0x80030005),
|
||||
}
|
||||
|
||||
[ComImportAttribute()]
|
||||
[GuidAttribute("bcc18b79-ba16-442f-80c4-8a59c30c463b")]
|
||||
[InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
[ComImport]
|
||||
[Guid("bcc18b79-ba16-442f-80c4-8a59c30c463b")]
|
||||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
internal interface IShellItemImageFactory
|
||||
{
|
||||
[PreserveSig]
|
||||
@@ -133,9 +134,8 @@ namespace Wox.Infrastructure.Image
|
||||
|
||||
private static IntPtr GetHBitmap(string fileName, int width, int height, ThumbnailOptions options)
|
||||
{
|
||||
IShellItem nativeShellItem;
|
||||
Guid shellItem2Guid = new Guid(IShellItem2Guid);
|
||||
int retCode = SHCreateItemFromParsingName(fileName, IntPtr.Zero, ref shellItem2Guid, out nativeShellItem);
|
||||
int retCode = SHCreateItemFromParsingName(fileName, IntPtr.Zero, ref shellItem2Guid, out IShellItem nativeShellItem);
|
||||
|
||||
if (retCode != 0)
|
||||
{
|
||||
@@ -148,8 +148,7 @@ namespace Wox.Infrastructure.Image
|
||||
Height = height,
|
||||
};
|
||||
|
||||
IntPtr hBitmap;
|
||||
HResult hr = ((IShellItemImageFactory)nativeShellItem).GetImage(nativeSize, options, out hBitmap);
|
||||
HResult hr = ((IShellItemImageFactory)nativeShellItem).GetImage(nativeSize, options, out IntPtr hBitmap);
|
||||
|
||||
// if extracting image thumbnail and failed, extract shell icon
|
||||
if (options == ThumbnailOptions.ThumbnailOnly && hr == HResult.ExtractionFailed)
|
||||
|
||||
@@ -60,8 +60,7 @@ namespace Wox.Infrastructure.Logger
|
||||
ExceptionInternal(classNameWithMethod, message, exception);
|
||||
}
|
||||
|
||||
private static string CheckClassAndMessageAndReturnFullClassWithMethod(string className, string message,
|
||||
string methodName)
|
||||
private static string CheckClassAndMessageAndReturnFullClassWithMethod(string className, string message, string methodName)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(className))
|
||||
{
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
[assembly: InternalsVisibleToAttribute("Microsoft.Plugin.Program.UnitTests")]
|
||||
[assembly: InternalsVisibleTo("Microsoft.Plugin.Program.UnitTests")]
|
||||
|
||||
namespace Wox.Infrastructure
|
||||
{
|
||||
|
||||
@@ -6,7 +6,7 @@ using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using static Wox.Infrastructure.StringMatcher;
|
||||
|
||||
[assembly: InternalsVisibleToAttribute("Microsoft.Plugin.Program.UnitTests")]
|
||||
[assembly: InternalsVisibleTo("Microsoft.Plugin.Program.UnitTests")]
|
||||
|
||||
namespace Wox.Infrastructure
|
||||
{
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace Wox.Infrastructure.Storage
|
||||
public class BinaryStorage<T> : IStorage<T>
|
||||
{
|
||||
// This storage helper returns whether or not to delete the binary storage items
|
||||
private static readonly int BINARY_STORAGE = 0;
|
||||
private static readonly int _binaryStorage = 0;
|
||||
private StoragePowerToysVersionInfo _storageHelper;
|
||||
|
||||
public BinaryStorage(string filename)
|
||||
@@ -36,10 +36,10 @@ namespace Wox.Infrastructure.Storage
|
||||
|
||||
public T TryLoad(T defaultData)
|
||||
{
|
||||
_storageHelper = new StoragePowerToysVersionInfo(FilePath, BINARY_STORAGE);
|
||||
_storageHelper = new StoragePowerToysVersionInfo(FilePath, _binaryStorage);
|
||||
|
||||
// Depending on the version number of the previously installed PT Run, delete the cache if it is found to be incompatible
|
||||
if (_storageHelper.clearCache)
|
||||
if (_storageHelper.ClearCache)
|
||||
{
|
||||
if (File.Exists(FilePath))
|
||||
{
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace Wox.Infrastructure.Storage
|
||||
public string DirectoryPath { get; set; }
|
||||
|
||||
// This storage helper returns whether or not to delete the json storage items
|
||||
private static readonly int JSON_STORAGE = 1;
|
||||
private static readonly int _jsonStorage = 1;
|
||||
private StoragePowerToysVersionInfo _storageHelper;
|
||||
|
||||
internal JsonStorage()
|
||||
@@ -43,10 +43,10 @@ namespace Wox.Infrastructure.Storage
|
||||
|
||||
public T Load()
|
||||
{
|
||||
_storageHelper = new StoragePowerToysVersionInfo(FilePath, JSON_STORAGE);
|
||||
_storageHelper = new StoragePowerToysVersionInfo(FilePath, _jsonStorage);
|
||||
|
||||
// Depending on the version number of the previously installed PT Run, delete the cache if it is found to be incompatible
|
||||
if (_storageHelper.clearCache)
|
||||
if (_storageHelper.ClearCache)
|
||||
{
|
||||
if (File.Exists(FilePath))
|
||||
{
|
||||
|
||||
@@ -10,9 +10,9 @@ namespace Wox.Infrastructure.Storage
|
||||
public class StoragePowerToysVersionInfo
|
||||
{
|
||||
// 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;
|
||||
public bool ClearCache { get; set; } = false;
|
||||
|
||||
private string currentPowerToysVersion = string.Empty;
|
||||
private readonly string currentPowerToysVersion = string.Empty;
|
||||
|
||||
private string FilePath { get; set; } = string.Empty;
|
||||
|
||||
@@ -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";
|
||||
@@ -96,13 +96,13 @@ namespace Wox.Infrastructure.Storage
|
||||
suffix = jsonSuffix;
|
||||
}
|
||||
|
||||
string filePath = AssociatedFilePath.Substring(0, AssociatedFilePath.Length - suffix.Length) + "_version.txt";
|
||||
string filePath = associatedFilePath.Substring(0, associatedFilePath.Length - suffix.Length) + "_version.txt";
|
||||
return filePath;
|
||||
}
|
||||
|
||||
public StoragePowerToysVersionInfo(string AssociatedFilePath, int type)
|
||||
public StoragePowerToysVersionInfo(string associatedFilePath, int type)
|
||||
{
|
||||
FilePath = GetFilePath(AssociatedFilePath, type);
|
||||
FilePath = GetFilePath(associatedFilePath, type);
|
||||
|
||||
// Get the previous version of PowerToys and cache Storage details from the CacheDetails.json storage file
|
||||
string previousVersion = GetPreviousVersion();
|
||||
@@ -112,7 +112,7 @@ namespace Wox.Infrastructure.Storage
|
||||
// However, we do not want to delete the cache if the same version of powerToys is being launched
|
||||
if (Lessthan(previousVersion, currentPowerToysVersion))
|
||||
{
|
||||
clearCache = true;
|
||||
ClearCache = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
[assembly: InternalsVisibleToAttribute("Microsoft.Plugin.Program.UnitTests")]
|
||||
[assembly: InternalsVisibleTo("Microsoft.Plugin.Program.UnitTests")]
|
||||
|
||||
namespace Wox.Infrastructure
|
||||
{
|
||||
|
||||
@@ -69,7 +69,7 @@
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<!--<ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\..\..\codeAnalysis\GlobalSuppressions.cs">
|
||||
<Link>GlobalSuppressions.cs</Link>
|
||||
</Compile>
|
||||
@@ -83,5 +83,5 @@
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>-->
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
Reference in New Issue
Block a user