diff options
| author | Robert Schumacher <roschuma@microsoft.com> | 2017-03-10 16:36:39 -0800 |
|---|---|---|
| committer | Robert Schumacher <roschuma@microsoft.com> | 2017-03-10 16:37:10 -0800 |
| commit | 5ba6f1725da1d11fbe1103dbafb6729107cec629 (patch) | |
| tree | 299d223470e3ae8647365f9277bb9bd1fb5f20b9 /toolsrc/src/commands_edit.cpp | |
| parent | f81fc894124bbeb709799f6117c01654be8df07f (diff) | |
| download | vcpkg-5ba6f1725da1d11fbe1103dbafb6729107cec629.tar.gz vcpkg-5ba6f1725da1d11fbe1103dbafb6729107cec629.zip | |
[vcpkg] Also search registry keys for VSCode. Prefer insider version if available. Fixes #764.
Diffstat (limited to 'toolsrc/src/commands_edit.cpp')
| -rw-r--r-- | toolsrc/src/commands_edit.cpp | 44 |
1 files changed, 36 insertions, 8 deletions
diff --git a/toolsrc/src/commands_edit.cpp b/toolsrc/src/commands_edit.cpp index 5a2433e5a..ce0557e09 100644 --- a/toolsrc/src/commands_edit.cpp +++ b/toolsrc/src/commands_edit.cpp @@ -16,27 +16,55 @@ namespace vcpkg::Commands::Edit const fs::path portpath = paths.ports / port_name; Checks::check_exit(fs::is_directory(portpath), R"(Could not find port named "%s")", port_name); - // Find editor - const optional<std::wstring> env_EDITOR_optional = System::get_environmental_variable(L"EDITOR"); + // Find the user's selected editor std::wstring env_EDITOR; - if (env_EDITOR_optional) + if (env_EDITOR.empty()) { - env_EDITOR = *env_EDITOR_optional; + const optional<std::wstring> env_EDITOR_optional = System::get_environmental_variable(L"EDITOR"); + if (env_EDITOR_optional) + { + env_EDITOR = *env_EDITOR_optional; + } } - else + + if (env_EDITOR.empty()) { - static const fs::path CODE_EXE_PATH = Environment::get_ProgramFiles_32_bit() / "Microsoft VS Code/Code.exe"; + const fs::path CODE_EXE_PATH = Environment::get_ProgramFiles_32_bit() / "Microsoft VS Code/Code.exe"; if (fs::exists(CODE_EXE_PATH)) { env_EDITOR = CODE_EXE_PATH; } - else + } + + if (env_EDITOR.empty()) + { + static const std::array<const wchar_t*, 4> regkeys = { + LR"(SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{C26E74D1-022E-4238-8B9D-1E7564A36CC9}_is1)", + LR"(SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{C26E74D1-022E-4238-8B9D-1E7564A36CC9}_is1)", + LR"(SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{F8A2A208-72B3-4D61-95FC-8A65D340689B}_is1)", + LR"(SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{F8A2A208-72B3-4D61-95FC-8A65D340689B}_is1)", + }; + for (auto&& keypath : regkeys) { - Checks::exit_with_message("Visual Studio Code was not found and the environmental variable EDITOR is not set"); + auto code_installpath = System::get_registry_string(HKEY_LOCAL_MACHINE, keypath, L"InstallLocation"); + if (code_installpath) + { + auto p = fs::path(*code_installpath) / "Code.exe"; + if (fs::exists(p)) + { + env_EDITOR = p.native(); + break; + } + } } } + if (env_EDITOR.empty()) + { + Checks::exit_with_message("Visual Studio Code was not found and the environment variable EDITOR is not set"); + } + std::wstring cmdLine = Strings::wformat(LR"("%s" "%s" "%s" -n)", env_EDITOR, portpath.native(), (portpath / "portfile.cmake").native()); exit(System::cmd_execute(cmdLine)); } |
