From af017922974c4612517fe9c512df7cdd1ac79b43 Mon Sep 17 00:00:00 2001 From: Mikhail Paulyshka Date: Wed, 23 Aug 2017 00:48:39 +0300 Subject: [vcpkg] use UTF-8 for console input/output --- toolsrc/src/vcpkg.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/toolsrc/src/vcpkg.cpp b/toolsrc/src/vcpkg.cpp index 9da501ec0..fc9b1a016 100644 --- a/toolsrc/src/vcpkg.cpp +++ b/toolsrc/src/vcpkg.cpp @@ -18,6 +18,30 @@ 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); @@ -192,6 +216,10 @@ 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::timer.lock() = ElapsedTime::create_started(); // Checks::register_console_ctrl_handler(); -- cgit v1.2.3 From 67b9475ef29496508640f73410a10ecf737389eb Mon Sep 17 00:00:00 2001 From: Robert Schumacher Date: Fri, 25 Aug 2017 16:55:14 -0700 Subject: [vcpkg] Set codepage to 65001, duplicate of #1682, fixes #1660 #1631 #1644 --- toolsrc/include/vcpkg_GlobalState.h | 3 +++ toolsrc/src/vcpkg.cpp | 36 ++++++------------------------------ toolsrc/src/vcpkg_Checks.cpp | 3 +++ toolsrc/src/vcpkg_GlobalState.cpp | 3 +++ 4 files changed, 15 insertions(+), 30 deletions(-) diff --git a/toolsrc/include/vcpkg_GlobalState.h b/toolsrc/include/vcpkg_GlobalState.h index 8f47fa00f..6522a25bf 100644 --- a/toolsrc/include/vcpkg_GlobalState.h +++ b/toolsrc/include/vcpkg_GlobalState.h @@ -12,5 +12,8 @@ namespace vcpkg static Util::LockGuarded timer; static std::atomic debugging; static std::atomic feature_packages; + + static std::atomic g_init_console_cp; + static std::atomic g_init_console_output_cp; }; } \ No newline at end of file diff --git a/toolsrc/src/vcpkg.cpp b/toolsrc/src/vcpkg.cpp index fc9b1a016..f37d079a6 100644 --- a/toolsrc/src/vcpkg.cpp +++ b/toolsrc/src/vcpkg.cpp @@ -18,30 +18,6 @@ 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) { diff --git a/toolsrc/src/vcpkg_Checks.cpp b/toolsrc/src/vcpkg_Checks.cpp index d8d857daa..2ad2d06ab 100644 --- a/toolsrc/src/vcpkg_Checks.cpp +++ b/toolsrc/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); } diff --git a/toolsrc/src/vcpkg_GlobalState.cpp b/toolsrc/src/vcpkg_GlobalState.cpp index c194da466..2221222c0 100644 --- a/toolsrc/src/vcpkg_GlobalState.cpp +++ b/toolsrc/src/vcpkg_GlobalState.cpp @@ -7,4 +7,7 @@ namespace vcpkg Util::LockGuarded GlobalState::timer; std::atomic GlobalState::debugging = false; std::atomic GlobalState::feature_packages = false; + + std::atomic GlobalState::g_init_console_cp = 0; + std::atomic GlobalState::g_init_console_output_cp = 0; } -- cgit v1.2.3