private Result ConvertMFTSearch(MFTSearchRecord record, string query)
        {
            string icoPath = "Images/file.png";

            if (record.IsFolder)
            {
                icoPath = "Images/folder.png";
            }

            string       name    = Path.GetFileName(record.FullPath);
            FuzzyMatcher matcher = FuzzyMatcher.Create(query);

            return(new Result()
            {
                Title = name,
                Score = matcher.Evaluate(name).Score,
                SubTitle = record.FullPath,
                IcoPath = icoPath,
                Action = _ =>
                {
                    try
                    {
                        Process.Start(record.FullPath);
                    }
                    catch
                    {
                        context.API.ShowMsg("Can't open " + record.FullPath, string.Empty, string.Empty);
                        return false;
                    }
                    return true;
                },
                ContextMenu = GetContextMenu(record)
            });
        }
        public List <Result> Query(Query query)
        {
            string param = query.GetAllRemainingParameter().TrimStart();

            // Should top results be returned? (true if no search parameters have been passed)
            var topResults = string.IsNullOrEmpty(param);

            var returnList = cachedBookmarks;

            if (!topResults)
            {
                // Since we mixed chrome and firefox bookmarks, we should order them again
                var fuzzyMatcher = FuzzyMatcher.Create(param);
                returnList = cachedBookmarks.Where(o => MatchProgram(o, fuzzyMatcher)).ToList();
                returnList = returnList.OrderByDescending(o => o.Score).ToList();
            }

            return(returnList.Select(c => new Result()
            {
                Title = c.Name,
                SubTitle = "Bookmark: " + c.Url,
                IcoPath = @"Images\bookmark.png",
                Score = 5,
                Action = (e) =>
                {
                    context.API.HideApp();
                    context.API.ShellRun(c.Url);
                    return true;
                }
            }).ToList());
        }
Exemple #3
0
        public void MatchTest()
        {
            var sources = new List <string>()
            {
                "file open in browser-test",
                "Install Package",
                "add new bsd",
                "Inste",
                "aac",
            };


            var results = new List <Wox.Plugin.Result>();

            foreach (var str in sources)
            {
                results.Add(new Plugin.Result()
                {
                    Title = str,
                    Score = FuzzyMatcher.Create("inst").Evaluate(str).Score
                });
            }

            results = results.Where(x => x.Score > 0).OrderByDescending(x => x.Score).ToList();

            Assert.IsTrue(results.Count == 3);
            Assert.IsTrue(results[0].Title == "Inste");
            Assert.IsTrue(results[1].Title == "Install Package");
            Assert.IsTrue(results[2].Title == "file open in browser-test");
        }
Exemple #4
0
        protected override List <Result> QueryInternal(Query query)
        {
            if (query.RawQuery.Trim().Length <= 1)
            {
                return(new List <Result>());
            }

            var            fuzzyMather = FuzzyMatcher.Create(query.RawQuery);
            List <Program> returnList  = programs.Where(o => MatchProgram(o, fuzzyMather)).ToList();

            returnList.ForEach(ScoreFilter);
            returnList = returnList.OrderByDescending(o => o.Score).ToList();

            return(returnList.Select(c => new Result()
            {
                Title = c.Title,
                SubTitle = c.ExecutePath,
                IcoPath = c.IcoPath,
                Score = c.Score,
                Action = (e) =>
                {
                    context.API.HideApp();
                    context.API.ShellRun(c.ExecutePath);
                    return true;
                }
            }).ToList());
        }
Exemple #5
0
        protected override List <Result> QueryInternal(Query query)
        {
            if (string.IsNullOrEmpty(query.RawQuery) || query.RawQuery.EndsWith(" ") || query.RawQuery.Length <= 1)
            {
                return(new List <Result>());
            }

            var            fuzzyMather = FuzzyMatcher.Create(query.RawQuery);
            List <Program> returnList  = installedList.Where(o => MatchProgram(o, fuzzyMather)).ToList();

            returnList.ForEach(ScoreFilter);
            //return ordered list instead of return the score, because programs scores will affect other
            //plugins, the weight of program should be less than the plugins when they showed at the same time.
            returnList = returnList.OrderByDescending(o => o.Score).ToList();

            return(returnList.Select(c => new Result()
            {
                Title = c.Title,
                SubTitle = c.ExecutePath,
                IcoPath = c.IcoPath,
                Score = 0,
                Action = (e) =>
                {
                    context.HideApp();
                    context.ShellRun(c.ExecutePath);
                    return true;
                }
            }).ToList());
        }
Exemple #6
0
        protected override List <Result> QueryInternal(Query query)
        {
            if (string.IsNullOrEmpty(query.RawQuery) || query.RawQuery.EndsWith(" ") || query.RawQuery.Length <= 1)
            {
                return(new List <Result>());
            }

            var             fuzzyMather = FuzzyMatcher.Create(query.RawQuery);
            List <Bookmark> returnList  = bookmarks.Where(o => MatchProgram(o, fuzzyMather)).ToList();

            returnList = returnList.OrderByDescending(o => o.Score).ToList();
            return(returnList.Select(c => new Result()
            {
                Title = c.Name,
                SubTitle = "Bookmark: " + c.Url,
                IcoPath = Path.GetDirectoryName(Application.ExecutablePath) + @"\Images\bookmark.png",
                Score = 5,
                Action = (e) =>
                {
                    context.HideApp();
                    context.ShellRun(c.Url);
                    return true;
                }
            }).ToList());
        }
Exemple #7
0
        public override List <Result> Query(Query query)
        {
            var matcher = FuzzyMatcher.Create(query.RawQuery);

            var ret = new List <Result>();

            foreach (var file in FileCache)
            {
                var fn  = Path.GetFileName(file);
                var ans = matcher.Evaluate(fn);
                if (ans.Success)
                {
                    ret.Add(CreateResult(file, ans.Score));
                }
                else
                {
                    var pyans = matcher.EvaluatePinYin(fn);
                    if (pyans.Success)
                    {
                        ret.Add(CreateResult(file, pyans.Score));
                    }
                }
            }
            return(ret);
        }
Exemple #8
0
        protected override List <Result> QueryInternal(Query query)
        {
            if (string.IsNullOrEmpty(query.RawQuery) || query.RawQuery.EndsWith(" ") || query.RawQuery.Length <= 1)
            {
                return(new List <Result>());
            }

            var            fuzzyMather = FuzzyMatcher.Create(query.RawQuery);
            List <Program> returnList  = installedList.Where(o => MatchProgram(o, fuzzyMather)).ToList();

            returnList.ForEach(ScoreFilter);
            //return ordered list instead of return the score, because programs scores will affect other
            //plugins, the weight of program should be less than the plugins when they showed at the same time.
            returnList = returnList.OrderByDescending(o => o.Score).ToList();
            returnList.ForEach(o => o.Score = 0);

            return(returnList.Select(c => new Result()
            {
                Title = c.Title,
                IcoPath = c.IcoPath,
                Score = c.Score,
                Action = (context) =>
                {
                    if (string.IsNullOrEmpty(c.ExecutePath))
                    {
                        MessageBox.Show("couldn't start" + c.Title);
                    }
                    else
                    {
                        try
                        {
                            Process.Start(c.ExecutePath);
                        }
                        catch (Win32Exception)
                        {
                            //Do nothing.
                            //It may be caused if UAC blocks the program.
                        }
                        catch (Exception e)
                        {
                            throw e;
                        }
                    }
                    return true;
                }
            }).ToList());
        }
Exemple #9
0
        /// <summary>
        /// Check if a candidate is match with the source
        /// </summary>
        /// <param name="source"></param>
        /// <param name="candidate"></param>
        /// <returns>Match score</returns>
        public static int Match(string source, string candidate)
        {
            if (string.IsNullOrEmpty(source) || string.IsNullOrEmpty(candidate))
            {
                return(0);
            }

            FuzzyMatcher matcher = FuzzyMatcher.Create(candidate);
            int          score   = matcher.Evaluate(source).Score;

            if (score > 0)
            {
                return(score);
            }

            score = matcher.Evaluate(source.Unidecode()).Score;
            return(score);
        }
Exemple #10
0
        protected override List <Result> QueryInternal(Query query)
        {
            if (query.RawQuery.EndsWith(" ") || query.RawQuery.Length <= 1)
            {
                return(new List <Result>());
            }
            string myQuery = query.RawQuery.Trim();

            List <Result> results = new List <Result>();

            foreach (var item in controlPanelItems)
            {
                var fuzzyMather = FuzzyMatcher.Create(myQuery);
                if (MatchProgram(item, fuzzyMather))
                {
                    results.Add(new Result()
                    {
                        Title    = item.LocalizedString,
                        SubTitle = item.InfoTip,
                        Score    = item.Score,
                        IcoPath  = "Images\\ControlPanelIcons\\" + item.GUID + fileType,
                        Action   = e =>
                        {
                            try
                            {
                                Process.Start(item.ExecutablePath);
                            }
                            catch (Exception)
                            {
                                //Silently Fail for now..
                            }
                            return(true);
                        }
                    });
                }
            }

            List <Result> panelItems = results.OrderByDescending(o => o.Score).Take(5).ToList();

            return(panelItems);
        }
Exemple #11
0
        public List <Result> Query(Query query)
        {
            var fuzzyMather = FuzzyMatcher.Create(query.Search);
            var results     = programs.Where(p => MatchProgram(p, fuzzyMather)).
                              Select(ScoreFilter).
                              OrderByDescending(p => p.Score)
                              .Select(c => new Result
            {
                Title       = c.Title,
                SubTitle    = c.ExecutePath,
                IcoPath     = c.IcoPath,
                Score       = c.Score,
                ContextData = c,
                Action      = e =>
                {
                    var hide = StartProcess(new ProcessStartInfo(c.ExecutePath));
                    return(hide);
                }
            }).ToList();

            return(results);
        }
Exemple #12
0
        public List <Result> Query(Query query)
        {
            var fuzzyMather = FuzzyMatcher.Create(query.Search);
            var results     = programs.Where(o => MatchProgram(o, fuzzyMather)).
                              Select(ScoreFilter).
                              OrderByDescending(o => o.Score)
                              .Select(c => new Result()
            {
                Title       = c.Title,
                SubTitle    = c.ExecutePath,
                IcoPath     = c.IcoPath,
                Score       = c.Score,
                ContextData = c,
                Action      = (e) =>
                {
                    context.API.HideApp();
                    context.API.ShellRun(c.ExecutePath);
                    return(true);
                }
            }).ToList();

            return(results);
        }
Exemple #13
0
        public List <Result> Query(Query query)
        {
            string        myQuery = query.Search.Trim();
            List <Result> results = new List <Result>();

            foreach (var item in controlPanelItems)
            {
                var fuzzyMather = FuzzyMatcher.Create(myQuery);
                if (MatchProgram(item, fuzzyMather))
                {
                    results.Add(new Result
                    {
                        Title    = item.LocalizedString,
                        SubTitle = item.InfoTip,
                        Score    = item.Score,
                        IcoPath  = Path.Combine(context.CurrentPluginMetadata.PluginDirectory, @"Images\\ControlPanelIcons\\" + item.GUID + fileType),
                        Action   = e =>
                        {
                            try
                            {
                                Process.Start(item.ExecutablePath);
                            }
                            catch (Exception)
                            {
                                //Silently Fail for now..
                            }
                            return(true);
                        }
                    });
                }
            }

            List <Result> panelItems = results.OrderByDescending(o => o.Score).Take(5).ToList();

            return(panelItems);
        }
Exemple #14
0
        public List <Result> Query(Query query)
        {
            var results = new List <Result>();

            if (query.ActionParameters.Count > 0 && query.ActionParameters[0].Length > 0)
            {
                var keyword = query.GetAllRemainingParameter();
                if (ContextMenuStorage.Instance.MaxSearchCount <= 0)
                {
                    ContextMenuStorage.Instance.MaxSearchCount = 100;
                    ContextMenuStorage.Instance.Save();
                }

                try
                {
                    var searchList  = api.Search(keyword, maxCount: ContextMenuStorage.Instance.MaxSearchCount).ToList();
                    var fuzzyMather = FuzzyMatcher.Create(keyword);
                    searchList.Sort(
                        (x, y) =>
                        fuzzyMather.Evaluate(Path.GetFileName(y.FullPath)).Score -
                        fuzzyMather.Evaluate(Path.GetFileName(x.FullPath)).Score);

                    foreach (var s in searchList)
                    {
                        var    path = s.FullPath;
                        Result r    = new Result();
                        r.Title    = Path.GetFileName(path);
                        r.SubTitle = path;
                        r.IcoPath  = GetIconPath(s);
                        r.Action   = (c) =>
                        {
                            context.API.HideApp();
                            context.API.ShellRun(path);
                            return(true);
                        };
                        r.ContextMenu = GetContextMenu(s);
                        results.Add(r);
                    }
                }
                catch (IPCErrorException)
                {
                    StartEverything();
                    results.Add(new Result()
                    {
                        Title   = "Everything is not running, we already run it for you now. Try search again",
                        IcoPath = "Images\\warning.png"
                    });
                }
                catch (Exception e)
                {
                    results.Add(new Result()
                    {
                        Title    = "Everything plugin has an error (enter to copy error message)",
                        SubTitle = e.Message,
                        Action   = _ =>
                        {
                            System.Windows.Clipboard.SetText(e.Message + "\r\n" + e.StackTrace);
                            context.API.ShowMsg("Copied", "Error message has copied to your clipboard", string.Empty);
                            return(false);
                        },
                        IcoPath = "Images\\error.png"
                    });
                }
            }

            api.Reset();

            return(results);
        }
Exemple #15
0
        private void QueryInternal_Directory_Exists(string currentPath, string input, List <Result> results)
        {
            string path = Directory.Exists(currentPath) ? new DirectoryInfo(currentPath).FullName : Path.GetDirectoryName(input);

            if (!System.IO.Directory.Exists(path))
            {
                return;
            }

            results.Add(new Result("Open this directory", "Images/folder.png")
            {
                Score  = 100000,
                Action = (c) => {
                    if (Directory.Exists(currentPath))
                    {
                        Process.Start(currentPath);
                    }
                    else if (currentPath.Contains("\\"))
                    {
                        var index = currentPath.LastIndexOf("\\");
                        Process.Start(currentPath.Remove(index) + "\\");
                    }

                    return(true);
                }
            });


            //if (System.IO.Directory.Exists(input)) {
            var dirs = new DirectoryInfo(path).GetDirectories();

            var parentDirKey = input.TrimEnd('\\', '/');

            if (!parentDirectories.ContainsKey(parentDirKey))
            {
                parentDirectories.Add(parentDirKey, dirs);
            }

            var fuzzy = FuzzyMatcher.Create(Path.GetFileName(currentPath).ToLower());

            foreach (var dir in dirs)                                           //.Where(x => (x.Attributes & FileAttributes.Hidden) != 0)) {
            {
                if ((dir.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
                {
                    continue;
                }

                var result = new Result(dir.Name, "Images/folder.png")
                {
                    Action = (c) => {
                        //context.ChangeQuery(dir.FullName);
                        context.ChangeQuery(input + dir.Name + "\\");
                        return(false);
                    }
                };

                if (Path.GetFileName(currentPath).ToLower() != "")
                {
                    var matchResult = fuzzy.Evaluate(dir.Name);
                    result.Score = matchResult.Score;
                    if (!matchResult.Success)
                    {
                        continue;
                    }
                }

                results.Add(result);
            }
            //}

            var Folder = Path.GetDirectoryName(currentPath);

            if (Folder != null)
            {
                //var fuzzy = FuzzyMatcher.Create(Path.GetFileName(currentPath).ToLower());
                foreach (var dir in new DirectoryInfo(Folder).GetFiles())                   //.Where(x => (x.Attributes & FileAttributes.Hidden) != 0)) {
                {
                    if ((dir.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
                    {
                        continue;
                    }

                    var    dirPath = dir.FullName;
                    Result result  = new Result(Path.GetFileNameWithoutExtension(dirPath), dirPath)
                    {
                        Action = (c) => {
                            try {
                                Process.Start(dirPath);
                            }
                            catch (Exception ex) {
                                MessageBox.Show(ex.Message, "Could not start " + dir.Name);
                            }

                            return(true);
                        }
                    };

                    if (Path.GetFileName(currentPath) != "")
                    {
                        var matchResult = fuzzy.Evaluate(dir.Name);
                        result.Score = matchResult.Score;
                        if (!matchResult.Success)
                        {
                            continue;
                        }
                    }

                    results.Add(result);
                }
            }
        }
Exemple #16
0
        public List <Result> Query(Query query)
        {
            var results = new List <Result>();

            if (!string.IsNullOrEmpty(query.Search))
            {
                var keyword = query.Search;
                if (ContextMenuStorage.Instance.MaxSearchCount <= 0)
                {
                    ContextMenuStorage.Instance.MaxSearchCount = 50;
                    ContextMenuStorage.Instance.Save();
                }

                if (keyword == "uninstalleverything")
                {
                    Result r = new Result();
                    r.Title    = "Uninstall Everything";
                    r.SubTitle = "You need to uninstall everything service if you can not move/delete wox folder";
                    r.IcoPath  = "Images\\find.png";
                    r.Action   = (c) =>
                    {
                        UnInstallEverything();
                        return(true);
                    };
                    r.Score = 2000;
                    results.Add(r);
                }

                try
                {
                    var searchList  = api.Search(keyword, maxCount: ContextMenuStorage.Instance.MaxSearchCount).ToList();
                    var fuzzyMather = FuzzyMatcher.Create(keyword);
                    searchList.Sort(
                        (x, y) =>
                        fuzzyMather.Evaluate(Path.GetFileName(y.FullPath)).Score -
                        fuzzyMather.Evaluate(Path.GetFileName(x.FullPath)).Score);

                    foreach (var s in searchList)
                    {
                        var    path = s.FullPath;
                        Result r    = new Result();
                        r.Title    = Path.GetFileName(path);
                        r.SubTitle = path;
                        r.IcoPath  = GetIconPath(s);
                        r.Action   = (c) =>
                        {
                            context.API.HideApp();
                            context.API.ShellRun(path);
                            return(true);
                        };
                        r.ContextData = s;
                        results.Add(r);
                    }
                }
                catch (IPCErrorException)
                {
                    StartEverything();
                    results.Add(new Result()
                    {
                        Title   = context.API.GetTranslation("wox_plugin_everything_is_not_running"),
                        IcoPath = "Images\\warning.png"
                    });
                }
                catch (Exception e)
                {
                    results.Add(new Result()
                    {
                        Title    = context.API.GetTranslation("wox_plugin_everything_query_error"),
                        SubTitle = e.Message,
                        Action   = _ =>
                        {
                            System.Windows.Clipboard.SetText(e.Message + "\r\n" + e.StackTrace);
                            context.API.ShowMsg(context.API.GetTranslation("wox_plugin_everything_copied"), null, string.Empty);
                            return(false);
                        },
                        IcoPath = "Images\\error.png"
                    });
                }
            }

            api.Reset();

            return(results);
        }