1 #ifndef OOKII_WIN32_HELPER_H_
4 #define OOKII_WIN32_HELPER_H_
8 #if !defined(OOKII_NO_PLATFORM_HEADERS) && (!defined(OOKII_PLATFORM_NOT_INLINE) || defined(OOKII_PLATFORM_DEFINITION))
10 #define WIN32_LEAN_AND_MEAN
26 #pragma comment(lib, "version.lib")
36 namespace ookii::details
39 #ifdef OOKII_PLATFORM_FUNC_HAS_BODY
41 HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
42 CONSOLE_SCREEN_BUFFER_INFO info;
43 if (GetConsoleScreenBufferInfo(handle, &info))
45 return static_cast<short>(info.srWindow.Right - info.srWindow.Left + 1);
53 using tstring = std::wstring;
55 using tstring = std::string;
65 OOKII_PLATFORM_FUNC(std::optional<tstring> get_module_file_name())
66 #ifdef OOKII_PLATFORM_FUNC_HAS_BODY
68 std::vector<TCHAR> buffer;
72 buffer.resize(buffer.size() + MAX_PATH);
73 count = GetModuleFileName(
nullptr, buffer.data(),
static_cast<DWORD
>(buffer.size()));
74 }
while (count >= buffer.size());
81 return tstring{buffer.begin(), buffer.begin() + count};
85 OOKII_PLATFORM_FUNC(std::optional<version_info> get_version_resource())
86 #ifdef OOKII_PLATFORM_FUNC_HAS_BODY
88 auto file_name = get_module_file_name();
94 auto size = GetFileVersionInfoSize(file_name->data(),
nullptr);
100 std::vector<std::byte> buffer;
102 if (!GetFileVersionInfo(file_name->data(), 0, size, buffer.data()))
107 struct LANGANDCODEPAGE {
113 if (!VerQueryValue(buffer.data(), TEXT(
"\\VarFileInfo\\Translation"),
reinterpret_cast<LPVOID *
>(&translate), &len) ||
114 len <
sizeof(LANGANDCODEPAGE))
119 auto sub_block =
OOKII_FMT_NS format(TEXT(
"\\StringFileInfo\\{:04x}{:04x}\\"), translate->language, translate->codepage);
120 auto block = sub_block + TEXT(
"ProductName");
122 if (!VerQueryValue(buffer.data(), block.data(),
reinterpret_cast<LPVOID *
>(&value), &len) || len == 0)
128 result.product_name = tstring{value, value + len};
129 block = sub_block + TEXT(
"ProductVersion");
130 if (VerQueryValue(buffer.data(), block.data(),
reinterpret_cast<LPVOID *
>(&value), &len))
132 result.version = tstring{value, value + len};
135 block = sub_block + TEXT(
"LegalCopyright");
136 if (VerQueryValue(buffer.data(), block.data(),
reinterpret_cast<LPVOID *
>(&value), &len))
138 result.copyright = tstring{value, value + len};
short get_console_width(short default_width=80) noexcept
Determines the width of the console.
Definition: console_helper.h:19