Add functions to find the Program Files folders on the C++ side. Resolves
MODIFY
include/vcpkg_Environment.h
include/vcpkg_Environment.h
@@ -24,4 +24,8 @@ namespace vcpkg::Environment
};
const vcvarsall_and_platform_toolset& get_vcvarsall_bat(const vcpkg_paths& paths);
+
+ const fs::path& get_ProgramFiles_32_bit();
+
+ const fs::path& get_ProgramFiles_Platform_bitness();
}

MODIFY
src/commands_edit.cpp
src/commands_edit.cpp
#include "vcpkg_Commands.h"
#include "vcpkg_System.h"
#include "vcpkg_Input.h"
+#include "vcpkg_Environment.h"
namespace vcpkg::Commands::Edit
{
@@ -24,7 +25,7 @@ namespace vcpkg::Commands::Edit
}
else
{
- static const std::wstring CODE_EXE_PATH = LR"(C:\Program Files (x86)\Microsoft VS Code\Code.exe)";
+ static 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;

MODIFY
src/commands_integrate.cpp
src/commands_integrate.cpp
namespace vcpkg::Commands::Integrate
{
static const std::array<fs::path, 2> old_system_target_files = {
- "C:/Program Files (x86)/MSBuild/14.0/Microsoft.Common.Targets/ImportBefore/vcpkg.nuget.targets",
- "C:/Program Files (x86)/MSBuild/14.0/Microsoft.Common.Targets/ImportBefore/vcpkg.system.targets"
+ Environment::get_ProgramFiles_32_bit() / "MSBuild/14.0/Microsoft.Common.Targets/ImportBefore/vcpkg.nuget.targets",
+ Environment::get_ProgramFiles_32_bit() / "MSBuild/14.0/Microsoft.Common.Targets/ImportBefore/vcpkg.system.targets"
};
- static const fs::path system_wide_targets_file = "C:/Program Files (x86)/MSBuild/Microsoft.Cpp/v4.0/V140/ImportBefore/Default/vcpkg.system.props";
+ static const fs::path system_wide_targets_file = Environment::get_ProgramFiles_32_bit() / "MSBuild/Microsoft.Cpp/v4.0/V140/ImportBefore/Default/vcpkg.system.props";
static std::string create_appdata_targets_shortcut(const std::string& target_path) noexcept
{

MODIFY
src/vcpkg_Environment.cpp
src/vcpkg_Environment.cpp
namespace vcpkg::Environment
{
- static const fs::path default_cmake_installation_dir = "C:/Program Files/CMake/bin";
- static const fs::path default_cmake_installation_dir_x86 = "C:/Program Files (x86)/CMake/bin";
- static const fs::path default_git_installation_dir = "C:/Program Files/git/cmd";
- static const fs::path default_git_installation_dir_x86 = "C:/Program Files (x86)/git/cmd";
-
static void ensure_on_path(const std::array<int, 3>& version, const std::wstring& version_check_cmd, const std::wstring& install_cmd)
{
System::exit_code_and_output ec_data = System::cmd_execute_and_capture_output(version_check_cmd);
@@ -54,12 +49,15 @@ namespace vcpkg::Environment
void ensure_git_on_path(const vcpkg_paths& paths)
{
+ static const fs::path default_git_installation_dir = Environment::get_ProgramFiles_Platform_bitness() / "git/cmd";
+ static const fs::path default_git_installation_dir_32 = Environment::get_ProgramFiles_32_bit() / "git/cmd";
+
const fs::path downloaded_git = paths.downloads / "PortableGit" / "cmd";
const std::wstring path_buf = Strings::wformat(L"%s;%s;%s;%s",
downloaded_git.native(),
*System::get_environmental_variable(L"PATH"),
default_git_installation_dir.native(),
- default_git_installation_dir_x86.native());
+ default_git_installation_dir_32.native());
System::set_environmental_variable(L"PATH", path_buf.c_str());
static constexpr std::array<int, 3> git_version = { 2,0,0 };
@@ -70,12 +68,15 @@ namespace vcpkg::Environment
void ensure_cmake_on_path(const vcpkg_paths& paths)
{
+ static const fs::path default_cmake_installation_dir = Environment::get_ProgramFiles_Platform_bitness() / "CMake/bin";
+ static const fs::path default_cmake_installation_dir_32 = Environment::get_ProgramFiles_32_bit() / "CMake/bin";
+
const fs::path downloaded_cmake = paths.downloads / "cmake-3.7.2-win32-x86" / "bin";
const std::wstring path_buf = Strings::wformat(L"%s;%s;%s;%s",
downloaded_cmake.native(),
*System::get_environmental_variable(L"PATH"),
default_cmake_installation_dir.native(),
- default_cmake_installation_dir_x86.native());
+ default_cmake_installation_dir_32.native());
System::set_environmental_variable(L"PATH", path_buf.c_str());
static constexpr std::array<int, 3> cmake_version = { 3,7,2 };
@@ -226,4 +227,38 @@ namespace vcpkg::Environment
static const vcvarsall_and_platform_toolset vcvarsall_bat = find_vcvarsall_bat(paths);
return vcvarsall_bat;
}
+
+ static fs::path find_ProgramFiles_32_bit()
+ {
+ const optional<std::wstring> program_files_X86 = System::get_environmental_variable(L"ProgramFiles(x86)");
+ if (program_files_X86)
+ {
+ return *program_files_X86;
+ }
+
+ return *System::get_environmental_variable(L"PROGRAMFILES");
+ }
+
+ const fs::path& get_ProgramFiles_32_bit()
+ {
+ static const fs::path p = find_ProgramFiles_32_bit();
+ return p;
+ }
+
+ static fs::path find_ProgramFiles_Platform_bitness()
+ {
+ const optional<std::wstring> program_files_W6432 = System::get_environmental_variable(L"ProgramW6432");
+ if (program_files_W6432)
+ {
+ return *program_files_W6432;
+ }
+
+ return *System::get_environmental_variable(L"PROGRAMFILES");
+ }
+
+ const fs::path& get_ProgramFiles_Platform_bitness()
+ {
+ static const fs::path p = find_ProgramFiles_Platform_bitness();
+ return p;
+ }
}

Add functions to find the Program Files folders on the C++ side. Resolves #606