From 95a9a98edefe91fbcfffd53bfc4501955553de33 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Fri, 24 Feb 2017 14:44:37 -0800 Subject: [PATCH] Throw error is PROGRAMFILES env variable is not found --- toolsrc/src/vcpkg_Environment.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/toolsrc/src/vcpkg_Environment.cpp b/toolsrc/src/vcpkg_Environment.cpp index 527d8de895..8f3030269d 100644 --- a/toolsrc/src/vcpkg_Environment.cpp +++ b/toolsrc/src/vcpkg_Environment.cpp @@ -231,6 +231,19 @@ namespace vcpkg::Environment return vcvarsall_bat; } + static fs::path find_ProgramFiles() + { + const optional program_files = System::get_environmental_variable(L"PROGRAMFILES"); + Checks::check_exit(program_files.get() != nullptr, "Could not detect the PROGRAMFILES environmental variable"); + return *program_files; + } + + static const fs::path& get_ProgramFiles() + { + static const fs::path p = find_ProgramFiles(); + return p; + } + static fs::path find_ProgramFiles_32_bit() { const optional program_files_X86 = System::get_environmental_variable(L"ProgramFiles(x86)"); @@ -239,7 +252,7 @@ namespace vcpkg::Environment return *program_files_X86; } - return *System::get_environmental_variable(L"PROGRAMFILES"); + return get_ProgramFiles(); } const fs::path& get_ProgramFiles_32_bit() @@ -256,7 +269,7 @@ namespace vcpkg::Environment return *program_files_W6432; } - return *System::get_environmental_variable(L"PROGRAMFILES"); + return get_ProgramFiles(); } const fs::path& get_ProgramFiles_platform_bitness()