aboutsummaryrefslogtreecommitdiff
path: root/toolsrc/src/commands_edit.cpp
diff options
context:
space:
mode:
authorAlexander Karatarakis <alex@karatarakis.com>2017-09-21 12:22:00 -0700
committerGitHub <noreply@github.com>2017-09-21 12:22:00 -0700
commitfac96eb344a500405ab65b7e7f3755af0ad00b7e (patch)
treef9e3376ca1a8f2de408e087e42ae393f224d6c42 /toolsrc/src/commands_edit.cpp
parent46db0f03fcb42d9f738474885fda372160362e44 (diff)
parent1bbce1ee844262647f994afd5f31da12d938e7ee (diff)
downloadvcpkg-fac96eb344a500405ab65b7e7f3755af0ad00b7e.tar.gz
vcpkg-fac96eb344a500405ab65b7e7f3755af0ad00b7e.zip
Merge branch 'master' into master
Diffstat (limited to 'toolsrc/src/commands_edit.cpp')
-rw-r--r--toolsrc/src/commands_edit.cpp112
1 files changed, 58 insertions, 54 deletions
diff --git a/toolsrc/src/commands_edit.cpp b/toolsrc/src/commands_edit.cpp
index 4e83fcca8..823c87534 100644
--- a/toolsrc/src/commands_edit.cpp
+++ b/toolsrc/src/commands_edit.cpp
@@ -6,77 +6,81 @@
namespace vcpkg::Commands::Edit
{
+ static std::vector<fs::path> find_from_registry()
+ {
+ static const std::array<const wchar_t*, 3> REGKEYS = {
+ LR"(SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{C26E74D1-022E-4238-8B9D-1E7564A36CC9}_is1)",
+ LR"(SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{1287CAD5-7C8D-410D-88B9-0D1EE4A83FF2}_is1)",
+ LR"(SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{F8A2A208-72B3-4D61-95FC-8A65D340689B}_is1)",
+ };
+
+ std::vector<fs::path> output;
+ for (auto&& keypath : REGKEYS)
+ {
+ const Optional<std::wstring> code_installpath =
+ System::get_registry_string(HKEY_LOCAL_MACHINE, keypath, L"InstallLocation");
+ if (const auto c = code_installpath.get())
+ {
+ const fs::path install_path = fs::path(*c);
+ output.push_back(install_path / "Code - Insiders.exe");
+ output.push_back(install_path / "Code.exe");
+ }
+ }
+ return output;
+ }
+
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths)
{
+ static const std::string OPTION_BUILDTREES = "--buildtrees";
+
+ static const fs::path VS_CODE_INSIDERS = fs::path{"Microsoft VS Code Insiders"} / "Code - Insiders.exe";
+ static const fs::path VS_CODE = fs::path{"Microsoft VS Code"} / "Code.exe";
+
auto& fs = paths.get_filesystem();
- static const std::string example = Commands::Help::create_example_string("edit zlib");
- args.check_exact_arg_count(1, example);
- args.check_and_get_optional_command_arguments({});
+ static const std::string EXAMPLE = Commands::Help::create_example_string("edit zlib");
+ args.check_exact_arg_count(1, EXAMPLE);
+ const std::unordered_set<std::string> options =
+ args.check_and_get_optional_command_arguments({OPTION_BUILDTREES});
const std::string port_name = args.command_arguments.at(0);
const fs::path portpath = paths.ports / port_name;
Checks::check_exit(VCPKG_LINE_INFO, fs.is_directory(portpath), R"(Could not find port named "%s")", port_name);
- // Find the user's selected editor
- std::wstring env_EDITOR;
+ std::vector<fs::path> candidate_paths;
+ const std::vector<fs::path> from_path = Files::find_from_PATH(L"EDITOR");
+ candidate_paths.insert(candidate_paths.end(), from_path.cbegin(), from_path.cend());
+ candidate_paths.push_back(System::get_program_files_platform_bitness() / VS_CODE_INSIDERS);
+ candidate_paths.push_back(System::get_program_files_32_bit() / VS_CODE_INSIDERS);
+ candidate_paths.push_back(System::get_program_files_platform_bitness() / VS_CODE);
+ candidate_paths.push_back(System::get_program_files_32_bit() / VS_CODE);
- if (env_EDITOR.empty())
- {
- const Optional<std::wstring> env_EDITOR_optional = System::get_environment_variable(L"EDITOR");
- if (auto e = env_EDITOR_optional.get())
- {
- env_EDITOR = *e;
- }
- }
+ const std::vector<fs::path> from_registry = find_from_registry();
+ candidate_paths.insert(candidate_paths.end(), from_registry.cbegin(), from_registry.cend());
- if (env_EDITOR.empty())
+ auto it = Util::find_if(candidate_paths, [&](const fs::path& p) { return fs.exists(p); });
+ if (it == candidate_paths.cend())
{
- const fs::path CODE_EXE_PATH = System::get_ProgramFiles_32_bit() / "Microsoft VS Code/Code.exe";
- if (fs.exists(CODE_EXE_PATH))
- {
- env_EDITOR = CODE_EXE_PATH;
- }
+ System::println(System::Color::error,
+ "Error: Visual Studio Code was not found and the environment variable EDITOR is not set.");
+ System::println("The following paths were examined:");
+ Files::print_paths(candidate_paths);
+ System::println("You can also set the environmental variable EDITOR to your editor of choice.");
+ Checks::exit_fail(VCPKG_LINE_INFO);
}
- if (env_EDITOR.empty())
+ const fs::path env_editor = *it;
+ if (options.find(OPTION_BUILDTREES) != options.cend())
{
- 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)
- {
- const Optional<std::wstring> code_installpath =
- System::get_registry_string(HKEY_LOCAL_MACHINE, keypath, L"InstallLocation");
- if (auto c = code_installpath.get())
- {
- auto p = fs::path(*c) / "Code.exe";
- if (fs.exists(p))
- {
- env_EDITOR = p.native();
- break;
- }
- auto p_insiders = fs::path(*c) / "Code - Insiders.exe";
- if (fs.exists(p_insiders))
- {
- env_EDITOR = p_insiders.native();
- break;
- }
- }
- }
- }
+ const auto buildtrees_current_dir = paths.buildtrees / port_name;
- if (env_EDITOR.empty())
- {
- Checks::exit_with_message(
- VCPKG_LINE_INFO, "Visual Studio Code was not found and the environment variable EDITOR is not set");
+ const std::wstring cmd_line =
+ Strings::wformat(LR"("%s" "%s" -n)", env_editor, buildtrees_current_dir.native());
+ Checks::exit_with_code(VCPKG_LINE_INFO, System::cmd_execute(cmd_line));
}
- std::wstring cmdLine = Strings::wformat(
- LR"("%s" "%s" "%s" -n)", env_EDITOR, portpath.native(), (portpath / "portfile.cmake").native());
- Checks::exit_with_code(VCPKG_LINE_INFO, System::cmd_execute(cmdLine));
+ const std::wstring cmd_line = Strings::wformat(
+ LR"("%s" "%s" "%s" -n)", env_editor, portpath.native(), (portpath / "portfile.cmake").native());
+ Checks::exit_with_code(VCPKG_LINE_INFO, System::cmd_execute(cmd_line));
}
}