Move Environment::get_program_files() to System::get_program_files()
MODIFY
include/vcpkg_Environment.h
include/vcpkg_Environment.h
@@ -12,8 +12,4 @@ 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
include/vcpkg_System.h
include/vcpkg_System.h
@@ -62,4 +62,8 @@ namespace vcpkg::System
optional<std::wstring> get_environmental_variable(const cwstring_view varname) noexcept;
optional<std::wstring> get_registry_string(HKEY base, const cwstring_view subkey, const cwstring_view valuename);
+
+ 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
{
@@ -30,7 +29,7 @@ namespace vcpkg::Commands::Edit
if (env_EDITOR.empty())
{
- const fs::path CODE_EXE_PATH = Environment::get_ProgramFiles_32_bit() / "Microsoft VS Code/Code.exe";
+ 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;

MODIFY
src/commands_integrate.cpp
src/commands_integrate.cpp
namespace vcpkg::Commands::Integrate
{
static const std::array<fs::path, 2> old_system_target_files = {
- 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"
+ System::get_ProgramFiles_32_bit() / "MSBuild/14.0/Microsoft.Common.Targets/ImportBefore/vcpkg.nuget.targets",
+ System::get_ProgramFiles_32_bit() / "MSBuild/14.0/Microsoft.Common.Targets/ImportBefore/vcpkg.system.targets"
};
- 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 const fs::path system_wide_targets_file = System::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
@@ -137,38 +137,4 @@ namespace vcpkg::Environment
static const vcvarsall_and_platform_toolset vcvarsall_bat = find_vcvarsall_bat(paths);
return vcvarsall_bat;
}
-
- static const fs::path& get_ProgramFiles()
- {
- static const fs::path p = System::get_environmental_variable(L"PROGRAMFILES").value_or_exit(VCPKG_LINE_INFO);
- return p;
- }
-
- const fs::path& get_ProgramFiles_32_bit()
- {
- static const fs::path p = []() -> fs::path
- {
- auto value = System::get_environmental_variable(L"ProgramFiles(x86)");
- if (auto v = value.get())
- {
- return std::move(*v);
- }
- return get_ProgramFiles();
- }();
- return p;
- }
-
- const fs::path& get_ProgramFiles_platform_bitness()
- {
- static const fs::path p = []() -> fs::path
- {
- auto value = System::get_environmental_variable(L"ProgramW6432");
- if (auto v = value.get())
- {
- return std::move(*v);
- }
- return get_ProgramFiles();
- }();
- return p;
- }
}

MODIFY
src/vcpkg_System.cpp
src/vcpkg_System.cpp
@@ -202,4 +202,38 @@ namespace vcpkg::System
ret.pop_back(); // remove extra trailing null byte
return ret;
}
+
+ static const fs::path& get_ProgramFiles()
+ {
+ static const fs::path p = System::get_environmental_variable(L"PROGRAMFILES").value_or_exit(VCPKG_LINE_INFO);
+ return p;
+ }
+
+ const fs::path& get_ProgramFiles_32_bit()
+ {
+ static const fs::path p = []() -> fs::path
+ {
+ auto value = System::get_environmental_variable(L"ProgramFiles(x86)");
+ if (auto v = value.get())
+ {
+ return std::move(*v);
+ }
+ return get_ProgramFiles();
+ }();
+ return p;
+ }
+
+ const fs::path& get_ProgramFiles_platform_bitness()
+ {
+ static const fs::path p = []() -> fs::path
+ {
+ auto value = System::get_environmental_variable(L"ProgramW6432");
+ if (auto v = value.get())
+ {
+ return std::move(*v);
+ }
+ return get_ProgramFiles();
+ }();
+ return p;
+ }
}

MODIFY
src/vcpkg_paths.cpp
src/vcpkg_paths.cpp
#include "pch.h"
-#include "expected.h"
+#include "vcpkg_expected.h"
#include "vcpkg_paths.h"
#include "metrics.h"
#include "vcpkg_System.h"
@@ -98,8 +98,8 @@ namespace vcpkg
std::vector<fs::path> candidate_paths;
candidate_paths.push_back(downloaded_copy);
candidate_paths.insert(candidate_paths.end(), from_path.cbegin(), from_path.cend());
- candidate_paths.push_back(Environment::get_ProgramFiles_platform_bitness() / "CMake" / "bin" / "cmake.exe");
- candidate_paths.push_back(Environment::get_ProgramFiles_32_bit() / "CMake" / "bin");
+ candidate_paths.push_back(System::get_ProgramFiles_platform_bitness() / "CMake" / "bin" / "cmake.exe");
+ candidate_paths.push_back(System::get_ProgramFiles_32_bit() / "CMake" / "bin");
const optional<fs::path> path = find_if_has_equal_or_greater_version(candidate_paths, version_check_arguments, expected_version);
if (auto p = path.get())
@@ -142,8 +142,8 @@ namespace vcpkg
std::vector<fs::path> candidate_paths;
candidate_paths.push_back(downloaded_copy);
candidate_paths.insert(candidate_paths.end(), from_path.cbegin(), from_path.cend());
- candidate_paths.push_back(Environment::get_ProgramFiles_platform_bitness() / "git" / "cmd" / "git.exe");
- candidate_paths.push_back(Environment::get_ProgramFiles_32_bit() / "git" / "cmd" / "git.exe");
+ candidate_paths.push_back(System::get_ProgramFiles_platform_bitness() / "git" / "cmd" / "git.exe");
+ candidate_paths.push_back(System::get_ProgramFiles_32_bit() / "git" / "cmd" / "git.exe");
const optional<fs::path> path = find_if_has_equal_or_greater_version(candidate_paths, version_check_arguments, expected_version);
if (auto p = path.get())

Move Environment::get_program_files() to System::get_program_files()