//public OpenWithItemCommandModel(Profile<FI, DI, FSI> profile, // FileModel<FI, DI, FSI> appliedEntryModel) //{ // _profile = profile; // _appliedEntryModel = appliedEntryModel; // IsExecutable = true; // Header = Texts.strChooseDefaultProgram; //} public OpenWithItemCommandModel(Profile <FI, DI, FSI> profile, EntryModel <FI, DI, FSI> appliedEntryModel, OpenWithInfo info) { _profile = profile; _appliedEntryModel = appliedEntryModel; _info = info; IsExecutable = true; if (info != null && !info.Equals(OpenWithInfo.OpenAs)) { string exePath = OpenWithInfo.GetExecutablePath(info.OpenCommand); if (File.Exists(exePath)) { HeaderIcon = _profile.IconExtractor.GetIcon(exePath, Converters.IconSize.small, false); } if (File.Exists(exePath)) { FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(exePath); if (fvi.ProductName.EndsWith("Operating System")) //WordPad / NotePad { Header = fvi.FileDescription; } Header = fvi.ProductName; } } else { Header = Texts.strChooseDefaultProgram; } }
public virtual void Open(FI entry, OpenWithInfo openInfo = null) { string diskPath = GetDiskPath(entry); ProcessStartInfo psi = null; if (File.Exists(diskPath)) { if (openInfo != null) { if (!openInfo.Equals(OpenWithInfo.OpenAs)) { psi = new ProcessStartInfo(OpenWithInfo.GetExecutablePath(openInfo.OpenCommand), diskPath); } else { //http://bytes.com/topic/c-sharp/answers/826842-call-windows-open-dialog psi = new ProcessStartInfo("Rundll32.exe"); psi.Arguments = String.Format(" shell32.dll, OpenAs_RunDLL {0}", diskPath); } } else { psi = new ProcessStartInfo(diskPath); } } if (psi != null) { try { Process.Start(psi); } catch (Exception ex) { Debug.WriteLine(ex.Message); } } }
public void Open(EntryModel <FI, DI, FSI> entryModel, OpenWithInfo openInfo = null) { if (entryModel is FileModel <FI, DI, FSI> ) { Open(entryModel as FileModel <FI, DI, FSI>, openInfo); } else { Open(entryModel as DirectoryModel <FI, DI, FSI>, openInfo); } }
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 }); } } }
public override IEnumerable <CommandModel> GetSubActions() { string ext = PathEx.GetExtension(_appliedEntryModel.Name); foreach (OpenWithInfo info in FileTypeInfoProvider.GetFileTypeInfo(ext).OpenWithList) { if (info.OpenCommand != null && File.Exists(OpenWithInfo.GetExecutablePath(info.OpenCommand))) { yield return(new OpenWithItemCommandModel <FI, DI, FSI>(_profile, _appliedEntryModel, info)); } } QueryOpenWithInfoEventArgs <FI, DI, FSI> openInfoArgs = new QueryOpenWithInfoEventArgs <FI, DI, FSI>(_appliedEntryModel); OnQueryOpenWithInfo(this, openInfoArgs); foreach (OpenWithInfo info in openInfoArgs.ReturnList) { yield return(new OpenWithItemCommandModel <FI, DI, FSI>(_profile, _appliedEntryModel, info)); } yield return(new OpenWithItemCommandModel <FI, DI, FSI>(_profile, _appliedEntryModel, OpenWithInfo.OpenAs)); }
public override async Task <IScriptCommand> ExecuteAsync(ParameterDic pm) { var parameter = _srcModelFunc(pm); //Last line can obtain from FileList.Selection, not current directory. This just temporary fix. if (parameter != null && parameter.Count() == 0) { parameter = new[] { pm.GetValue <IEntryModel>("{FileList.CurrentDirectory}") } } ; if (parameter != null && parameter.Count() == 1) { bool _isFolder = parameter[0].IsDirectory; IDiskProfile profile = parameter[0].Profile as IDiskProfile; if (profile == null) { return(ResultCommand.Error(new NotSupportedException("IDiskProfile"))); } if (profile.DiskIO.Mapper is NullDiskPatheMapper) { return(ResultCommand.Error(new NotSupportedException())); } string appliedFileName = await profile.DiskIO.WriteToCacheAsync(parameter[0], pm.CancellationToken); if (_isFolder || appliedFileName.StartsWith("::{")) { if (appliedFileName.StartsWith("::{") || Directory.Exists(appliedFileName)) { try { Process.Start(appliedFileName); } catch (Exception ex) { return(ResultCommand.Error(ex)); } } } else { ProcessStartInfo psi = null; if (File.Exists(appliedFileName)) { if (_info != null) { if (!_info.Equals(OpenWithInfo.OpenAs)) { psi = new ProcessStartInfo(OpenWithInfo.GetExecutablePath(_info.OpenCommand), appliedFileName); } else { //http://bytes.com/topic/c-sharp/answers/826842-call-windows-open-dialog psi = new ProcessStartInfo("Rundll32.exe"); psi.Arguments = String.Format(" shell32.dll, OpenAs_RunDLL {0}", appliedFileName); } } else { psi = new ProcessStartInfo(appliedFileName); } } if (psi != null) { try { Process.Start(psi); } catch (Exception ex) { return(ResultCommand.Error(ex)); } } } return(ResultCommand.OK); } else { return(ResultCommand.Error(new Exception("Wrong Parameter type or more than one item."))); } } }
/// <summary> /// Launch a file (e.g. txt) using the OpenWithInfo, if null then default method will be used, Require Parameter (IEntryModel[]) /// </summary> /// <param name="info"></param> public OpenWithScriptCommand(OpenWithInfo info = null, Func <ParameterDic, IEntryModel[]> srcModelFunc = null) : base("OpenWith") { _info = info; _srcModelFunc = srcModelFunc ?? WPFScriptCommands.GetEntryModelFromParameter; }
public virtual void Open(FileModel <FI, DI, FSI> fileModel, OpenWithInfo openInfo = null) { Open(fileModel.EmbeddedFile, openInfo); }