summaryrefslogtreecommitdiffhomepage
path: root/loader/init.cpp
blob: 89d9d6c9df7f65d6a3bfa856e547fb6bfbce7208 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "impl.hpp"

#ifdef _WIN32
#include <windows.h>
#if __has_include(<ntddk.h>)
#include <ntddk.h>
#else
extern "C" __declspec(dllimport) long WINAPI RtlGetVersion(PRTL_OSVERSIONINFOEXW);
#endif
#ifdef _MSC_VER
#pragma comment(lib, "ntdll.lib")
#endif
#if defined __GNUG__ && !defined __clang__
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
#endif

#endif // _WIN32

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
    (void)::SetConsoleOutputCP(CP_UTF8);
    if (check_windows_build_number(10, 0, 17035))
        (void)::SetConsoleCP(CP_UTF8);
#endif
}

void loader_impl::system_init()
{
    static bool once = false;
    if (once)
        return;
    once = true;
    system_init_();
}

} // namespace floormat::loader_detail