[vcpkg] Set codepage to 65001, duplicate of fixes
MODIFY
include/vcpkg_GlobalState.h
include/vcpkg_GlobalState.h
@@ -12,5 +12,8 @@ namespace vcpkg
static Util::LockGuarded<ElapsedTime> timer;
static std::atomic<bool> debugging;
static std::atomic<bool> feature_packages;
+
+ static std::atomic<int> g_init_console_cp;
+ static std::atomic<int> g_init_console_output_cp;
};
}
\ No newline at end of file

MODIFY
src/vcpkg.cpp
src/vcpkg.cpp
using namespace vcpkg;
-UINT console_cp_input;
-UINT console_cp_output;
-
-void console_cp_set()
-{
- console_cp_input = GetConsoleCP();
- console_cp_output = GetConsoleOutputCP();
-
- SetConsoleCP(CP_UTF8);
- SetConsoleOutputCP(CP_UTF8);
-}
-
-void console_cp_reset()
-{
- SetConsoleCP(console_cp_input);
- SetConsoleOutputCP(console_cp_output);
-}
-
-BOOL console_ctrl_handler(DWORD fdwCtrlType)
-{
- console_cp_reset();
- return TRUE;
-}
-
void invalid_command(const std::string& cmd)
{
System::println(System::Color::error, "invalid command: %s", cmd);
@@ -216,13 +192,13 @@ int wmain(const int argc, const wchar_t* const* const argv)
{
if (argc == 0) std::abort();
- console_cp_set();
- SetConsoleCtrlHandler(PHANDLER_ROUTINE(console_ctrl_handler), TRUE);
- atexit(console_cp_reset);
+ GlobalState::g_init_console_cp = GetConsoleCP();
+ GlobalState::g_init_console_output_cp = GetConsoleOutputCP();
- *GlobalState::timer.lock() = ElapsedTime::create_started();
+ SetConsoleCP(65001);
+ SetConsoleOutputCP(65001);
- // Checks::register_console_ctrl_handler();
+ *GlobalState::timer.lock() = ElapsedTime::create_started();
const std::string trimmed_command_line = trim_path_from_command_line(Strings::to_utf8(GetCommandLineW()));
@@ -240,7 +216,7 @@ int wmain(const int argc, const wchar_t* const* const argv)
if (auto p = args.sendmetrics.get()) Metrics::g_metrics.lock()->set_send_metrics(*p);
if (auto p = args.debug.get()) GlobalState::debugging = *p;
- vcpkg::Checks::register_console_ctrl_handler();
+ Checks::register_console_ctrl_handler();
if (GlobalState::debugging)
{

MODIFY
src/vcpkg_Checks.cpp
src/vcpkg_Checks.cpp
@@ -17,6 +17,9 @@ namespace vcpkg::Checks
GlobalState::debugging = false;
metrics->flush();
+ SetConsoleCP(GlobalState::g_init_console_cp);
+ SetConsoleOutputCP(GlobalState::g_init_console_output_cp);
+
::exit(exit_code);
}

MODIFY
src/vcpkg_GlobalState.cpp
src/vcpkg_GlobalState.cpp
@@ -7,4 +7,7 @@ namespace vcpkg
Util::LockGuarded<ElapsedTime> GlobalState::timer;
std::atomic<bool> GlobalState::debugging = false;
std::atomic<bool> GlobalState::feature_packages = false;
+
+ std::atomic<int> GlobalState::g_init_console_cp = 0;
+ std::atomic<int> GlobalState::g_init_console_output_cp = 0;
}

[vcpkg] Set codepage to 65001, duplicate of #1682, fixes #1660 #1631 #1644