mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-13 02:39:22 +08:00
53 lines
1.7 KiB
C#
53 lines
1.7 KiB
C#
|
using System;
|
||
|
using System.Drawing;
|
||
|
using System.Globalization;
|
||
|
using System.IO;
|
||
|
using System.Windows;
|
||
|
using System.Windows.Data;
|
||
|
using System.Windows.Media;
|
||
|
using System.Windows.Media.Imaging;
|
||
|
|
||
|
namespace Wox
|
||
|
{
|
||
|
public class ImagePathConverter : IMultiValueConverter
|
||
|
{
|
||
|
private static ImageSource GetIcon(string fileName)
|
||
|
{
|
||
|
Icon icon = Icon.ExtractAssociatedIcon(fileName);
|
||
|
return System.Windows.Interop.Imaging.CreateBitmapSourceFromHIcon(
|
||
|
icon.Handle,
|
||
|
new Int32Rect(0, 0, icon.Width, icon.Height),
|
||
|
BitmapSizeOptions.FromEmptyOptions());
|
||
|
}
|
||
|
|
||
|
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
|
||
|
{
|
||
|
string path = values[0].ToString();
|
||
|
string pluginDirectory = values[1].ToString();
|
||
|
|
||
|
string resolvedPath = string.Empty;
|
||
|
if (!string.IsNullOrEmpty(path) && path.Contains(":\\") && File.Exists(path))
|
||
|
{
|
||
|
resolvedPath = path;
|
||
|
}
|
||
|
else if (!string.IsNullOrEmpty(path) && File.Exists(pluginDirectory + path))
|
||
|
{
|
||
|
resolvedPath = pluginDirectory + path;
|
||
|
}
|
||
|
|
||
|
if (resolvedPath.ToLower().EndsWith(".exe") || resolvedPath.ToLower().EndsWith(".lnk"))
|
||
|
{
|
||
|
return GetIcon(resolvedPath);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
return new BitmapImage(new Uri(resolvedPath));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
|
||
|
{
|
||
|
return null;
|
||
|
}
|
||
|
}
|
||
|
}
|