mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 11:48:06 +01:00
Add Everything support show file icon
and add a file icon cache associate with file extension
This commit is contained in:
@@ -171,7 +171,7 @@ namespace Wox.Plugin.Everything
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="keyWord">The key word.</param>
|
/// <param name="keyWord">The key word.</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public IEnumerable<string> Search(string keyWord)
|
public IEnumerable<SearchResult> Search(string keyWord)
|
||||||
{
|
{
|
||||||
return Search(keyWord, 0, int.MaxValue);
|
return Search(keyWord, 0, int.MaxValue);
|
||||||
}
|
}
|
||||||
@@ -204,7 +204,7 @@ namespace Wox.Plugin.Everything
|
|||||||
/// <param name="offset">The offset.</param>
|
/// <param name="offset">The offset.</param>
|
||||||
/// <param name="maxCount">The max count.</param>
|
/// <param name="maxCount">The max count.</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public IEnumerable<string> Search(string keyWord, int offset, int maxCount)
|
public IEnumerable<SearchResult> Search(string keyWord, int offset, int maxCount)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(keyWord))
|
if (string.IsNullOrEmpty(keyWord))
|
||||||
throw new ArgumentNullException("keyWord");
|
throw new ArgumentNullException("keyWord");
|
||||||
@@ -254,12 +254,31 @@ namespace Wox.Plugin.Everything
|
|||||||
for (int idx = 0; idx < Everything_GetNumResults(); ++idx)
|
for (int idx = 0; idx < Everything_GetNumResults(); ++idx)
|
||||||
{
|
{
|
||||||
Everything_GetResultFullPathName(idx, buffer, bufferSize);
|
Everything_GetResultFullPathName(idx, buffer, bufferSize);
|
||||||
yield return buffer.ToString();
|
|
||||||
|
var result = new SearchResult() { FullPath = buffer.ToString() };
|
||||||
|
if (Everything_IsFolderResult(idx))
|
||||||
|
result.Type = ResultType.Folder;
|
||||||
|
else if (Everything_IsFileResult(idx))
|
||||||
|
result.Type = ResultType.File;
|
||||||
|
|
||||||
|
yield return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum ResultType
|
||||||
|
{
|
||||||
|
Volume,
|
||||||
|
Folder,
|
||||||
|
File
|
||||||
|
}
|
||||||
|
|
||||||
|
public class SearchResult
|
||||||
|
{
|
||||||
|
public string FullPath { get; set; }
|
||||||
|
public ResultType Type { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
|
|||||||
BIN
Plugins/Wox.Plugin.Everything/Images/folder.png
Normal file
BIN
Plugins/Wox.Plugin.Everything/Images/folder.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.2 KiB |
BIN
Plugins/Wox.Plugin.Everything/Images/image.png
Normal file
BIN
Plugins/Wox.Plugin.Everything/Images/image.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.4 KiB |
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace Wox.Plugin.Everything
|
namespace Wox.Plugin.Everything
|
||||||
{
|
{
|
||||||
@@ -10,6 +11,7 @@ namespace Wox.Plugin.Everything
|
|||||||
{
|
{
|
||||||
Wox.Plugin.PluginInitContext context;
|
Wox.Plugin.PluginInitContext context;
|
||||||
EverythingAPI api = new EverythingAPI();
|
EverythingAPI api = new EverythingAPI();
|
||||||
|
private static List<string> imageExts = new List<string>() { ".png", ".jpg", ".jpeg", ".gif", ".bmp", ".tiff" };
|
||||||
|
|
||||||
public List<Result> Query(Query query)
|
public List<Result> Query(Query query)
|
||||||
{
|
{
|
||||||
@@ -17,13 +19,14 @@ namespace Wox.Plugin.Everything
|
|||||||
if (query.ActionParameters.Count > 0 && query.ActionParameters[0].Length > 0)
|
if (query.ActionParameters.Count > 0 && query.ActionParameters[0].Length > 0)
|
||||||
{
|
{
|
||||||
var keyword = string.Join(" ", query.ActionParameters.ToArray());
|
var keyword = string.Join(" ", query.ActionParameters.ToArray());
|
||||||
IEnumerable<string> enumerable = api.Search(keyword, 0, 100);
|
var enumerable = api.Search(keyword, 0, 100);
|
||||||
foreach (string s in enumerable)
|
foreach (var s in enumerable)
|
||||||
{
|
{
|
||||||
var path = s;
|
var path = s.FullPath;
|
||||||
Result r = new Result();
|
Result r = new Result();
|
||||||
r.Title = Path.GetFileName(path);
|
r.Title = Path.GetFileName(path);
|
||||||
r.SubTitle = path;
|
r.SubTitle = path;
|
||||||
|
r.IcoPath = GetIconPath(s);
|
||||||
r.Action = (c) =>
|
r.Action = (c) =>
|
||||||
{
|
{
|
||||||
context.HideApp();
|
context.HideApp();
|
||||||
@@ -48,6 +51,22 @@ namespace Wox.Plugin.Everything
|
|||||||
|
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private string GetIconPath(SearchResult s)
|
||||||
|
{
|
||||||
|
if (s.Type == ResultType.Folder)
|
||||||
|
{
|
||||||
|
return "Images\\folder.png";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var ext = Path.GetExtension(s.FullPath);
|
||||||
|
if (!string.IsNullOrEmpty(ext) && imageExts.Contains(ext.ToLower()))
|
||||||
|
return "Images\\image.png";
|
||||||
|
else
|
||||||
|
return s.FullPath;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[System.Runtime.InteropServices.DllImport("kernel32.dll")]
|
[System.Runtime.InteropServices.DllImport("kernel32.dll")]
|
||||||
private static extern int LoadLibrary(string name);
|
private static extern int LoadLibrary(string name);
|
||||||
|
|||||||
@@ -53,6 +53,12 @@
|
|||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Content Include="Images\folder.png">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</Content>
|
||||||
|
<Content Include="Images\image.png">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</Content>
|
||||||
<Content Include="x64\Everything.dll">
|
<Content Include="x64\Everything.dll">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</Content>
|
</Content>
|
||||||
@@ -65,6 +71,7 @@
|
|||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup />
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<PostBuildEvent>
|
<PostBuildEvent>
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ namespace Wox
|
|||||||
public class ImagePathConverter : IMultiValueConverter
|
public class ImagePathConverter : IMultiValueConverter
|
||||||
{
|
{
|
||||||
private static Dictionary<string, object> imageCache = new Dictionary<string, object>();
|
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)
|
private static ImageSource GetIcon(string fileName)
|
||||||
{
|
{
|
||||||
@@ -36,10 +37,15 @@ namespace Wox
|
|||||||
string path = values[0].ToString();
|
string path = values[0].ToString();
|
||||||
string pluginDirectory = values[1].ToString();
|
string pluginDirectory = values[1].ToString();
|
||||||
string fullPath = Path.Combine(pluginDirectory, path);
|
string fullPath = Path.Combine(pluginDirectory, path);
|
||||||
|
string ext = Path.GetExtension(path).ToLower();
|
||||||
if (imageCache.ContainsKey(fullPath))
|
if (imageCache.ContainsKey(fullPath))
|
||||||
{
|
{
|
||||||
return imageCache[fullPath];
|
return imageCache[fullPath];
|
||||||
}
|
}
|
||||||
|
if (imageCache.ContainsKey(ext))
|
||||||
|
{
|
||||||
|
return imageCache[ext];
|
||||||
|
}
|
||||||
|
|
||||||
string resolvedPath = string.Empty;
|
string resolvedPath = string.Empty;
|
||||||
if (!string.IsNullOrEmpty(path) && path.Contains(":\\") && File.Exists(path))
|
if (!string.IsNullOrEmpty(path) && path.Contains(":\\") && File.Exists(path))
|
||||||
@@ -51,18 +57,24 @@ namespace Wox
|
|||||||
resolvedPath = fullPath;
|
resolvedPath = fullPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var cacheKey = fullPath;
|
||||||
if (resolvedPath.ToLower().EndsWith(".exe") || resolvedPath.ToLower().EndsWith(".lnk"))
|
if (resolvedPath.ToLower().EndsWith(".exe") || resolvedPath.ToLower().EndsWith(".lnk"))
|
||||||
{
|
{
|
||||||
img = GetIcon(resolvedPath);
|
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)
|
if (img != null)
|
||||||
{
|
{
|
||||||
imageCache.Add(fullPath, img);
|
imageCache.Add(cacheKey, img);
|
||||||
}
|
}
|
||||||
|
|
||||||
return img;
|
return img;
|
||||||
|
|||||||
Reference in New Issue
Block a user