[PTRun]Remove BinaryFormatter (#19036)

This commit is contained in:
Davide Giacometti
2022-07-01 15:44:24 +02:00
committed by GitHub
parent b7fccc3211
commit f4dbdbdd7a
10 changed files with 36 additions and 247 deletions

View File

@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation
// 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.
@@ -7,6 +7,7 @@ using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Media;
using Wox.Infrastructure.Storage;
using Wox.Plugin;
namespace Wox.Infrastructure.Image
@@ -18,9 +19,16 @@ namespace Wox.Infrastructure.Image
private const int PermissibleFactor = 2;
private readonly ConcurrentDictionary<string, ImageSource> _data = new ConcurrentDictionary<string, ImageSource>();
private readonly WoxJsonStorage<ConcurrentDictionary<string, int>> _storage;
public ConcurrentDictionary<string, int> Usage { get; private set; } = new ConcurrentDictionary<string, int>();
public ImageCache()
{
_storage = new WoxJsonStorage<ConcurrentDictionary<string, int>>("ImageCache");
Usage = _storage.Load();
}
public ImageSource this[string path]
{
get
@@ -87,9 +95,9 @@ namespace Wox.Infrastructure.Image
return new Dictionary<string, int>(Usage);
}
public void SetUsageAsDictionary(Dictionary<string, int> usage)
public void Save()
{
Usage = new ConcurrentDictionary<string, int>(usage);
_storage.Save();
}
}
}

View File

@@ -1,10 +1,9 @@
// Copyright (c) Microsoft Corporation
// 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.Collections.Concurrent;
using System.Collections.Generic;
using System.Globalization;
using System.IO.Abstractions;
using System.Linq;
@@ -13,7 +12,6 @@ using System.Threading.Tasks;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using ManagedCommon;
using Wox.Infrastructure.Storage;
using Wox.Plugin;
using Wox.Plugin.Logger;
@@ -29,7 +27,6 @@ namespace Wox.Infrastructure.Image
private static readonly ImageCache ImageCache = new ImageCache();
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 { get; set; }
@@ -49,9 +46,7 @@ namespace Wox.Infrastructure.Image
public static void Initialize(Theme theme)
{
_storage = new BinaryStorage<Dictionary<string, int>>("Image");
_hashGenerator = new ImageHashGenerator();
ImageCache.SetUsageAsDictionary(_storage.TryLoad(new Dictionary<string, int>()));
foreach (var icon in new[] { Constant.DefaultIcon, Constant.ErrorIcon, Constant.LightThemedDefaultIcon, Constant.LightThemedErrorIcon })
{
@@ -78,7 +73,7 @@ namespace Wox.Infrastructure.Image
public static void Save()
{
ImageCache.Cleanup();
_storage.Save(ImageCache.GetUsageAsDictionary());
ImageCache.Save();
}
// Todo : Update it with icons specific to each theme.