public IEnumerable <ICommandModel> GetCommands(FileSystemInfoExModel appliedModel)
        {
            if (!appliedModel.IsDirectory)
            {
                string ext = PathEx.GetExtension(appliedModel.Name);
                foreach (OpenWithInfo info in FileTypeInfoProvider.GetFileTypeInfo(ext).OpenWithList)
                {
                    if (info.OpenCommand != null)
                    {
                        string executePath = OpenWithInfo.GetExecutablePath(info.OpenCommand);
                        string exeName     = Path.GetFileNameWithoutExtension(executePath);

                        if (info.OpenCommand != null && File.Exists(executePath))
                        {
                            IEntryModel exeModel = AsyncUtils.RunSync(() => _profile.ParseAsync(executePath));
                            if (exeModel != null)
                            {
                                yield return new CommandModel(new OpenWithScriptCommand(info))
                                       {
                                           Header              = String.Format("{0} ({1})", exeName, info.KeyName),
                                           ToolTip             = info.Description,
                                           HeaderIconExtractor =
                                               ModelIconExtractor <ICommandModel>
                                               .FromTaskFunc(t =>
                                                             _profile.GetIconExtractSequence(exeModel)
                                                             .Last().GetIconBytesForModelAsync(exeModel,
                                                                                               CancellationToken.None)),
                                           IsEnabled = true
                                       }
                            }
                            ;
                        }
                    }
                }

                yield return(new CommandModel(new OpenWithScriptCommand(OpenWithInfo.OpenAs))
                {
                    Header = "Open with...",
                    IsEnabled = true
                });
            }
        }
    }
Esempio n. 2
0
 public override async Task <IEntryModel> ParseAsync(string path)
 {
     return(await Task <IEntryModel> .Factory.StartNew(() =>
     {
         IEntryModel retVal = null;
         if (String.IsNullOrEmpty(path))
         {
             retVal = new FileSystemInfoExModel(this, DirectoryInfoEx.DesktopDirectory);
         }
         else
         if (path.StartsWith("::"))
         {
             if (DirectoryEx.Exists(path))
             {
                 retVal = new FileSystemInfoExModel(this, createDirectoryInfo(path));
             }
             else
             if (FileEx.Exists(path))
             {
                 retVal = new FileSystemInfoExModel(this, createFileInfo(path));
             }
         }
         else
         {
             if (Directory.Exists(path))
             {
                 retVal = new FileSystemInfoExModel(this, createDirectoryInfo(path));
             }
             else
             if (File.Exists(path))
             {
                 retVal = new FileSystemInfoExModel(this, createFileInfo(path));
             }
         }
         return Converters.Convert(retVal);
     }));
 }