mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 03:07:04 +02:00
Add Everything support show file icon
and add a file icon cache associate with file extension
This commit is contained in:
@@ -14,6 +14,7 @@ namespace Wox
|
||||
public class ImagePathConverter : IMultiValueConverter
|
||||
{
|
||||
private static Dictionary<string, object> imageCache = new Dictionary<string, object>();
|
||||
private static List<string> imageExts = new List<string>() { ".png", ".jpg", ".jpeg", ".gif", ".bmp", ".tiff" };
|
||||
|
||||
private static ImageSource GetIcon(string fileName)
|
||||
{
|
||||
@@ -36,10 +37,15 @@ namespace Wox
|
||||
string path = values[0].ToString();
|
||||
string pluginDirectory = values[1].ToString();
|
||||
string fullPath = Path.Combine(pluginDirectory, path);
|
||||
string ext = Path.GetExtension(path).ToLower();
|
||||
if (imageCache.ContainsKey(fullPath))
|
||||
{
|
||||
return imageCache[fullPath];
|
||||
}
|
||||
if (imageCache.ContainsKey(ext))
|
||||
{
|
||||
return imageCache[ext];
|
||||
}
|
||||
|
||||
string resolvedPath = string.Empty;
|
||||
if (!string.IsNullOrEmpty(path) && path.Contains(":\\") && File.Exists(path))
|
||||
@@ -51,18 +57,24 @@ namespace Wox
|
||||
resolvedPath = fullPath;
|
||||
}
|
||||
|
||||
var cacheKey = fullPath;
|
||||
if (resolvedPath.ToLower().EndsWith(".exe") || resolvedPath.ToLower().EndsWith(".lnk"))
|
||||
{
|
||||
img = GetIcon(resolvedPath);
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(resolvedPath) && File.Exists(resolvedPath))
|
||||
else if (!string.IsNullOrEmpty(resolvedPath) && imageExts.Contains(ext) && File.Exists(resolvedPath))
|
||||
{
|
||||
img = new BitmapImage(new Uri(resolvedPath));
|
||||
img = new BitmapImage(new Uri(resolvedPath));
|
||||
}
|
||||
else
|
||||
{
|
||||
img = GetIcon(resolvedPath);
|
||||
cacheKey = ext;
|
||||
}
|
||||
|
||||
if (img != null)
|
||||
{
|
||||
imageCache.Add(fullPath, img);
|
||||
imageCache.Add(cacheKey, img);
|
||||
}
|
||||
|
||||
return img;
|
||||
|
||||
Reference in New Issue
Block a user