diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2022-11-11 12:51:03 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-11-11 12:51:03 +0100 |
commit | 183f7b1dc55c9af6159dae45f5cd33078562b71e (patch) | |
tree | 4bf0d0d8905fa2bfccff1262b88c206ec2df7d67 /loader/init.cpp | |
parent | 9878f9774d2c1f90a4079c6d13f47ce4ef2a7fd3 (diff) |
set windows utf-8 codepage on startup via loader
Diffstat (limited to 'loader/init.cpp')
-rw-r--r-- | loader/init.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/loader/init.cpp b/loader/init.cpp new file mode 100644 index 00000000..d6a447e0 --- /dev/null +++ b/loader/init.cpp @@ -0,0 +1,44 @@ +#include "impl.hpp" +#ifdef _WIN32 +#include <windows.h> +extern "C" __declspec(dllimport) long WINAPI RtlGetVersion (PRTL_OSVERSIONINFOEXW); +#ifdef _MSC_VER +#pragma comment(lib, "ntdll.lib") +#endif +#endif + +namespace floormat::loader_detail { + +#ifdef _WIN32 +static bool check_windows_build_number(unsigned major, unsigned minor, unsigned build) +{ + if (RTL_OSVERSIONINFOEXW rovi = {.dwOSVersionInfoSize = sizeof(rovi)}; !RtlGetVersion(&rovi)) + return rovi.dwMajorVersion > major || + rovi.dwMajorVersion == major && rovi.dwMinorVersion > minor || + rovi.dwMajorVersion == major && rovi.dwMinorVersion == minor && rovi.dwBuildNumber >= build; + else + return false; +} +#endif + +static void system_init_() +{ +#ifdef _WIN32 + if (check_windows_build_number(10, 0, 17035)) + { + (void)::SetConsoleOutputCP(CP_UTF8); + (void)::SetConsoleCP(CP_UTF8); + } +#endif +} + +void system_init() +{ + static bool once = false; + if (once) + return; + once = true; + system_init_(); +} + +} // namespace floormat::loader_detail |