From 18084d5aa0e5544ffce4de514351734aa5f73aed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20B=C3=A1lint=20Misius?= Date: Sat, 13 May 2023 14:51:41 +0200 Subject: [PATCH] Request UTF-8 code page at startup on windows This makes the *A Win32 API variants work correctly with UTF-8 parameters, which is nice because standard C/C++ facilities use those (because microsoft's libc is a steaming pile of microsoft code). OF COURSE this only works on win10 1903 and above. See https://learn.microsoft.com/en-us/windows/apps/design/globalizing/use-utf8-code-page --- resources/meson.build | 1 + resources/powder-res.rc | 2 ++ resources/winutf8.xml | 8 ++++++++ src/common/platform/Windows.cpp | 5 +++++ 4 files changed, 16 insertions(+) create mode 100644 resources/winutf8.xml diff --git a/resources/meson.build b/resources/meson.build index 48dd45de3..bf8b39532 100644 --- a/resources/meson.build +++ b/resources/meson.build @@ -60,6 +60,7 @@ if host_platform == 'windows' ], depend_files: [ 'resource.h', + 'winutf8.xml', ], ) elif host_platform == 'darwin' diff --git a/resources/powder-res.rc b/resources/powder-res.rc index a591330f8..7bb0c594e 100644 --- a/resources/powder-res.rc +++ b/resources/powder-res.rc @@ -1,4 +1,6 @@ #include "resource.h" +#include IDI_ICON ICON DISCARDABLE "icon_exe.ico" IDI_DOC_ICON ICON DISCARDABLE "icon_cps.ico" +CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "winutf8.xml" diff --git a/resources/winutf8.xml b/resources/winutf8.xml new file mode 100644 index 000000000..522749a1d --- /dev/null +++ b/resources/winutf8.xml @@ -0,0 +1,8 @@ + + + + + UTF-8 + + + diff --git a/src/common/platform/Windows.cpp b/src/common/platform/Windows.cpp index 585af3a1d..53ca59801 100644 --- a/src/common/platform/Windows.cpp +++ b/src/common/platform/Windows.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -398,6 +399,10 @@ void UpdateCleanup() void SetupCrt() { + _setmode(0, _O_BINARY); + _setmode(1, _O_BINARY); + SetConsoleCP(CP_UTF8); + SetConsoleOutputCP(CP_UTF8); if constexpr (DEBUG) { _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_DEBUG);