fixing all warnings and info for infra (#5891)

This commit is contained in:
Clint Rutkas
2020-08-12 10:44:58 -07:00
committed by GitHub
parent db6e9b6962
commit 8888739867
15 changed files with 67 additions and 61 deletions

View File

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