diff --git a/Plugins/Wox.Plugin.Everything/EverythingAPI.cs b/Plugins/Wox.Plugin.Everything/EverythingAPI.cs index 961c81abf..51433f475 100644 --- a/Plugins/Wox.Plugin.Everything/EverythingAPI.cs +++ b/Plugins/Wox.Plugin.Everything/EverythingAPI.cs @@ -171,7 +171,7 @@ namespace Wox.Plugin.Everything /// /// The key word. /// - public IEnumerable Search(string keyWord) + public IEnumerable Search(string keyWord) { return Search(keyWord, 0, int.MaxValue); } @@ -204,7 +204,7 @@ namespace Wox.Plugin.Everything /// The offset. /// The max count. /// - public IEnumerable Search(string keyWord, int offset, int maxCount) + public IEnumerable Search(string keyWord, int offset, int maxCount) { if (string.IsNullOrEmpty(keyWord)) throw new ArgumentNullException("keyWord"); @@ -254,12 +254,31 @@ namespace Wox.Plugin.Everything for (int idx = 0; idx < Everything_GetNumResults(); ++idx) { 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 } + public enum ResultType + { + Volume, + Folder, + File + } + + public class SearchResult + { + public string FullPath { get; set; } + public ResultType Type { get; set; } + } /// /// diff --git a/Plugins/Wox.Plugin.Everything/Images/folder.png b/Plugins/Wox.Plugin.Everything/Images/folder.png new file mode 100644 index 000000000..330cb2e4b Binary files /dev/null and b/Plugins/Wox.Plugin.Everything/Images/folder.png differ diff --git a/Plugins/Wox.Plugin.Everything/Images/image.png b/Plugins/Wox.Plugin.Everything/Images/image.png new file mode 100644 index 000000000..85c8a708d Binary files /dev/null and b/Plugins/Wox.Plugin.Everything/Images/image.png differ diff --git a/Plugins/Wox.Plugin.Everything/Main.cs b/Plugins/Wox.Plugin.Everything/Main.cs index a5ad006d4..29685b46c 100644 --- a/Plugins/Wox.Plugin.Everything/Main.cs +++ b/Plugins/Wox.Plugin.Everything/Main.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; +using System.Text.RegularExpressions; namespace Wox.Plugin.Everything { @@ -10,6 +11,7 @@ namespace Wox.Plugin.Everything { Wox.Plugin.PluginInitContext context; EverythingAPI api = new EverythingAPI(); + private static List imageExts = new List() { ".png", ".jpg", ".jpeg", ".gif", ".bmp", ".tiff" }; public List Query(Query query) { @@ -17,13 +19,14 @@ namespace Wox.Plugin.Everything if (query.ActionParameters.Count > 0 && query.ActionParameters[0].Length > 0) { var keyword = string.Join(" ", query.ActionParameters.ToArray()); - IEnumerable enumerable = api.Search(keyword, 0, 100); - foreach (string s in enumerable) + var enumerable = api.Search(keyword, 0, 100); + foreach (var s in enumerable) { - var path = s; + var path = s.FullPath; Result r = new Result(); r.Title = Path.GetFileName(path); r.SubTitle = path; + r.IcoPath = GetIconPath(s); r.Action = (c) => { context.HideApp(); @@ -48,6 +51,22 @@ namespace Wox.Plugin.Everything 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")] private static extern int LoadLibrary(string name); diff --git a/Plugins/Wox.Plugin.Everything/Wox.Plugin.Everything.csproj b/Plugins/Wox.Plugin.Everything/Wox.Plugin.Everything.csproj index ea7e3b20d..1953ba3b4 100644 --- a/Plugins/Wox.Plugin.Everything/Wox.Plugin.Everything.csproj +++ b/Plugins/Wox.Plugin.Everything/Wox.Plugin.Everything.csproj @@ -53,6 +53,12 @@ + + PreserveNewest + + + PreserveNewest + PreserveNewest @@ -65,6 +71,7 @@ PreserveNewest + diff --git a/Wox/ImagePathConverter.cs b/Wox/ImagePathConverter.cs index 6f4ccb10c..8b88f47c5 100644 --- a/Wox/ImagePathConverter.cs +++ b/Wox/ImagePathConverter.cs @@ -14,6 +14,7 @@ namespace Wox public class ImagePathConverter : IMultiValueConverter { private static Dictionary imageCache = new Dictionary(); + private static List imageExts = new List() { ".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;