From acece00ae291d143c3b712a98814a64b9dd43f14 Mon Sep 17 00:00:00 2001
From: Sine Striker <trueful@163.com>
Date: 周一, 11 12月 2023 17:12:41 +0800
Subject: [PATCH] Remove VersionHelper

---
 src/core/qwindowkit_windows.cpp |   29 +++++++++++++++--------------
 1 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/src/core/qwindowkit_windows.cpp b/src/core/qwindowkit_windows.cpp
index aeb2954..826c454 100644
--- a/src/core/qwindowkit_windows.cpp
+++ b/src/core/qwindowkit_windows.cpp
@@ -2,21 +2,22 @@
 
 namespace QWK {
 
-    QString winErrorMessage(DWORD code) {
-        LPWSTR buf = nullptr;
-        if (::FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
-                                 FORMAT_MESSAGE_IGNORE_INSERTS,
-                             nullptr, code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
-                             reinterpret_cast<LPWSTR>(&buf), 0, nullptr) == 0) {
-            return {};
-        }
-        const QString &errorText = QString::fromWCharArray(buf).trimmed();
-        ::LocalFree(buf);
-        return errorText;
-    }
+    typedef NTSTATUS(WINAPI *RtlGetVersionPtr)(PRTL_OSVERSIONINFOW);
 
-    QString winLastErrorMessage() {
-        return winErrorMessage(::GetLastError());
+    RTL_OSVERSIONINFOW GetRealOSVersion() {
+        HMODULE hMod = GetModuleHandleW(L"ntdll.dll");
+        if (hMod) {
+            auto fxPtr = reinterpret_cast<RtlGetVersionPtr>(GetProcAddress(hMod, "RtlGetVersion"));
+            if (fxPtr != nullptr) {
+                RTL_OSVERSIONINFOW rovi = {0};
+                rovi.dwOSVersionInfoSize = sizeof(rovi);
+                if (0 == fxPtr(&rovi)) {
+                    return rovi;
+                }
+            }
+        }
+        RTL_OSVERSIONINFOW rovi = {0};
+        return rovi;
     }
 
 }
\ No newline at end of file

--
Gitblit v1.9.1