private bool QueryAndUpdateSettingsValue(ExternalAppInfo info, out bool appIsUsableAfterwards) { string enteredValue = WriteInvitationAndPerformQuery(info); bool enteredCorrectly = ProcessEnteredValue(enteredValue, info, out appIsUsableAfterwards); return(enteredCorrectly); }
/* ---------------------------------------------------- */ // コマンド /* ---------------------------------------------------- */ // エクスプローラーで開く public void OpenByExplorer() { ExternalAppInfo exAppInfo = new ExternalAppInfo(); exAppInfo.Path = "explorer.exe"; exAppInfo.Arg = "/select," + Format.FilePathFormat; OpenByExternalApp(exAppInfo); }
private bool ProcessEnteredValue(string enteredValue, ExternalAppInfo info, out bool appIsUsableAfterwards) { bool enteredCorrectly = true; if (string.IsNullOrWhiteSpace(enteredValue)) { // User wants to use the current value. // So no changes to settings. // We're good if we have the fallback appIsUsableAfterwards = info.UsableApplicationIsPresent; } else if (enteredValue == CleanSettingString) { // Users wants to clean the set value. _appPathProvider.SetSettingsPathFor(info.App, string.Empty); // Can we use the system one? if (info.FallbackPathExists) { appIsUsableAfterwards = true; _console.WriteLine("The system app will be used."); } else { appIsUsableAfterwards = false; } } else { string fullPath = null; try { enteredValue = enteredValue.Trim(' ', '"'); fullPath = _fileSystem.Path.GetFullPath(enteredValue); enteredCorrectly = _fileSystem.File.Exists(fullPath); } catch { enteredCorrectly = false; } // Something specific was entered. if (enteredCorrectly) { _appPathProvider.SetSettingsPathFor(info.App, fullPath); _console.WriteLine($"{fullPath} will be used."); } appIsUsableAfterwards = enteredCorrectly; } return(enteredCorrectly); }
public void Execute() { mw = MainWindow.Current; ImageFileContext ifc; if (mw.TileExpantionPanel.IsShowing) { ifc = mw.TileExpantionPanel.TargetImgFileContext; } else { ifc = mw.GetImageFileContextUnderCursor(); } if (ifc != null) { ExternalAppInfo exAppInfo = mw.Setting.ExternalAppInfoList.FirstOrDefault(i => i.Name == this.StrValue); try { if (exAppInfo == null) { // 実行ファイル名を対象に検索 exAppInfo = mw.Setting.ExternalAppInfoList.FirstOrDefault(i => System.IO.Path.GetFileName(i.Path) == this.StrValue); } if (exAppInfo == null) { // 実行ファイル名(拡張子抜き)を対象に検索 exAppInfo = mw.Setting.ExternalAppInfoList.FirstOrDefault(i => System.IO.Path.GetFileNameWithoutExtension(i.Path) == this.StrValue); } } catch { exAppInfo = null; } if (exAppInfo != null) { ifc.OpenByExternalApp(exAppInfo); } } }
private string WriteInvitationAndPerformQuery(ExternalAppInfo info) { // General invitation. _console.WriteLine($"Please enter the full path to {info.ExeName}."); if (info.FallbackPathExists) { _console.WriteLine($"(Enter {CleanSettingString} to use system app.)"); } // We may omit this if there is something right now. if (info.UsableApplicationIsPresent) { _console.WriteLine("(Skip to keep the current setting.)"); } _console.Write("> "); string enteredValue = _console.ReadLine(); return(enteredValue); }
private bool AskFor(ExternalApp externalApp) { ExternalAppInfo info = _appPathProvider.GetAppInformation(externalApp); _console.WriteLine("=== Path to {0} application ({1}) ===", info.Title, info.ExeName); // Info about default app. _console.WriteLine("System app path: {0}", ToStringOr(info.FallbackPath, "not found")); // Info about app set in settings. _console.WriteLine("Current explicit path: {0}", ToStringOr(info.SettingsPath, "not set")); if (info.SettingsPathIsSet) { if (info.SettingsPathExists) { _console.WriteLine("The specified file exists."); } else { _console.WriteLine("The specified file does not exist."); } } bool appIsUsableAfterwards = false; bool enteredCorrectly = false; while (!enteredCorrectly) { enteredCorrectly = QueryAndUpdateSettingsValue(info, out appIsUsableAfterwards); if (!enteredCorrectly) { _console.WriteLine("The entered path is not valid."); } } return(appIsUsableAfterwards); }
// 外部プログラムで画像を開く public void OpenByExternalApp(ExternalAppInfo exAppInfo) { if (exAppInfo == null) { return; } // ファイルパスの決定 string filePath = ""; if (exAppInfo.Arg.Contains(Format.FilePathFormat)) { if (Archiver.CanReadFile) { filePath = FilePath; } else { // 書庫内ファイルなら一時展開 if (TempFilePath == null) { WriteToTempFolder(); } filePath = TempFilePath; } } // フォルダ(書庫)パスの決定 string folderPath; if (Archiver is Archiver.NullArchiver) { try { folderPath = Directory.GetParent(FilePath).FullName; } catch { folderPath = ""; } } else { folderPath = Archiver.ArchiverPath; } // 親フォルダパスの決定 string parentFolderPath; try { parentFolderPath = Directory.GetParent(folderPath).FullName; } catch { parentFolderPath = ""; } // 外部プログラム呼び出し string arg = exAppInfo.Arg; arg = arg.Replace(Format.FilePathFormat, filePath); arg = arg.Replace(Format.FolderPathFormat, folderPath); arg = arg.Replace(Format.ParentFolderPathFormat, parentFolderPath); if (exAppInfo.Path != null && exAppInfo.Path != "") { // プログラムの指定あり try { Process.Start(exAppInfo.Path, arg); } catch { } } else { // プログラムの指定がなければ、拡張子で関連付けられているプログラムで開く(引数そのままStart()に) try { Process.Start(arg); } catch { } } }