mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-15 20:19:17 +08:00
343b904607
* Added thumbnail loader * Deleted old shell icon extraction logic. Refactored ImageLoader.Load to improve readibility. * Moved error handling down into the API call itself * Minor renamings in ImageLoader * Load icons only for files that are not images. Fixes stutters when loading folders. * Added the ability to load a full image through ImageLoader. ImageLoader.Load now also has a "loadFullImage" parameter. * Max image cache is now 5000 instead of 200. * Added some commentaries on how thumbnails are loaded
45 lines
1.2 KiB
C#
45 lines
1.2 KiB
C#
using System;
|
|
using System.Collections.Concurrent;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Windows.Media;
|
|
|
|
namespace Wox.Infrastructure.Image
|
|
{
|
|
[Serializable]
|
|
public class ImageCache
|
|
{
|
|
private const int MaxCached = 5000;
|
|
public ConcurrentDictionary<string, int> Usage = new ConcurrentDictionary<string, int>();
|
|
private readonly ConcurrentDictionary<string, ImageSource> _data = new ConcurrentDictionary<string, ImageSource>();
|
|
|
|
|
|
public ImageSource this[string path]
|
|
{
|
|
get
|
|
{
|
|
Usage.AddOrUpdate(path, 1, (k, v) => v + 1);
|
|
var i = _data[path];
|
|
return i;
|
|
}
|
|
set { _data[path] = value; }
|
|
}
|
|
|
|
public void Cleanup()
|
|
{
|
|
var images = Usage
|
|
.OrderByDescending(o => o.Value)
|
|
.Take(MaxCached)
|
|
.ToDictionary(i => i.Key, i => i.Value);
|
|
Usage = new ConcurrentDictionary<string, int>(images);
|
|
}
|
|
|
|
public bool ContainsKey(string key)
|
|
{
|
|
var contains = _data.ContainsKey(key);
|
|
return contains;
|
|
}
|
|
}
|
|
|
|
}
|