feat: add os version show for windows

This commit is contained in:
2026-04-16 17:20:42 +08:00
parent 9c7812f205
commit 296bd8e07a

View File

@@ -1,13 +1,37 @@
#pragma once #pragma once
#include <string> #include <string>
#include <fstream>
#include <Cubed/tools/log.hpp> #include <Cubed/tools/log.hpp>
#ifdef _WIN32 #ifdef _WIN32
#include <windows.h>
typedef LONG (WINAPI* RtlGetVersionPtr)(PRTL_OSVERSIONINFOW);
inline bool get_os_version(std::string& str) {
HMODULE hntdll = GetModuleHandleW(L"ntdll.dll");
if (!hntdll) return false;
auto prtl_get_version = reinterpret_cast<RtlGetVersionPtr>(
GetProcAddress(hntdll, "RtlGetVersion"));
if (!prtl_get_version) return false;
RTL_OSVERSIONINFOW osvi = { 0 };
osvi.dwOSVersionInfoSize = sizeof(osvi);
if (prtl_get_version(&osvi) != 0) return false;
if (osvi.dwMajorVersion == 10) {
if (osvi.dwBuildNumber >= 22000) {
str = "Windows 11 Build " + std::to_string(osvi.dwBuildNumber);
} else {
str = "Windows 10 Build " + std::to_string(osvi.dwBuildNumber);
}
} else {
str = "Windows Build " + std::to_string(osvi.dwBuildNumber);
}
return true;
}
#elif defined(__linux__) #elif defined(__linux__)
#include <fstream>
inline bool get_os_version(std::string& str) { inline bool get_os_version(std::string& str) {
std::ifstream file("/etc/os-release"); std::ifstream file("/etc/os-release");
if (!file.is_open()) { if (!file.is_open()) {
@@ -33,6 +57,11 @@ inline bool get_os_version(std::string& str) {
} }
return false; return false;
} }
#else
inline bool get_os_version(std::string& str) {
str = "Unknown OS";
return false;
}
#endif #endif