예제 #1
0
        private void AddCommands(List <Result> resultList, Query query)
        {
            var enumeration_actions = _recentActionProcessor.RecentActionList.OrderByDescending(x => x.CreationTime).Distinct();

            foreach (var recentActionDescriptor in enumeration_actions)
            {
                TargetDescriptor target = recentActionDescriptor.Target;

                Result commandResult = new Result();

                if (target.Type == TargetType.Unknown)
                {
                    commandResult.Title    = recentActionDescriptor.ActionName;
                    commandResult.SubTitle = recentActionDescriptor.ActionLink;
                    commandResult.IcoPath  = "Images\\recent_icon.png";
                }
                else if (target.Type == TargetType.Directory)
                {
                    commandResult.Title    = target.Name;
                    commandResult.SubTitle = $"Directory : {target.Path} ";
                    commandResult.IcoPath  = "Images\\recent_dir.png";
                }
                else
                {
                    var subtitle = String.IsNullOrEmpty(target.Arguments) ?
                                   target.Path : $"{target.Path} ,Args: {target.Arguments}";

                    commandResult.Title    = target.Name;
                    commandResult.SubTitle = subtitle;
                    commandResult.IcoPath  = "Images\\recent.png";
                }

                commandResult.Score       = (int)(1000 * StringTools.FuzzyMatch(query.Search, commandResult.Title));
                commandResult.ContextData = recentActionDescriptor;

                commandResult.Action = e =>
                {
                    void thread_execution()
                    {
                        Thread.Sleep(100);

                        Process process = new Process();

                        process.StartInfo.FileName = recentActionDescriptor.ActionLink;
                        process.Start();
                    }

                    new Thread(thread_execution).Start();

                    return(true);
                };

                resultList.Add(commandResult);
            }
        }
예제 #2
0
        private void GrabRecentActions()
        {
            this._recentActionList.Clear();

            DirectoryInfo recentDir = new DirectoryInfo(Paths.WindowsRecentDirectory);

            foreach (FileInfo fileInfo in recentDir.GetFiles())
            {
                TargetDescriptor target = null;
                Start_STA_Thread(() => target = GetShortcutTargetDescriptor(fileInfo.FullName));

                this._recentActionList.Add(new RecentActionDescriptor()
                {
                    ActionLink   = fileInfo.FullName,
                    CreationTime = fileInfo.CreationTime,
                    ActionName   = Path.GetFileNameWithoutExtension(fileInfo.FullName),
                    Target       = target
                });;
            }
        }
예제 #3
0
        private static TargetDescriptor GetShortcutTargetDescriptor(string shortcutFilename)
        {
            string pathOnly     = Path.GetDirectoryName(shortcutFilename);
            string filenameOnly = Path.GetFileName(shortcutFilename);

            Shell      shell      = new Shell();
            Folder     folder     = shell.NameSpace(pathOnly);
            FolderItem folderItem = folder.ParseName(filenameOnly);

            TargetDescriptor desc = new TargetDescriptor();

            desc.Type = TargetType.Unknown;

            if (folderItem != null)
            {
                Shell32.ShellLinkObject link = (Shell32.ShellLinkObject)folderItem.GetLink;

                if (string.IsNullOrWhiteSpace(link.Path))
                {
                    return(desc);
                }
                else
                {
                    desc.Path             = link.Path;
                    desc.Extension        = Path.GetExtension(desc.Path);
                    desc.Name             = Path.GetFileName(desc.Path);
                    desc.Arguments        = link.Arguments;
                    desc.WorkingDirectory = link.WorkingDirectory;

                    desc.Type = Directory.Exists(link.Path) ? TargetType.Directory : TargetType.File;

                    return(desc);
                }
            }

            return(desc);
        }