Skip to content

Commit 5b97b17

Browse files
committed
获取完整的4位版本号
1 parent d7cf8ce commit 5b97b17

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

src/Snap.Hutao.Remastered.Native/HutaoNative.cpp

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,7 @@ HRESULT __stdcall HutaoNative::GetWindowsVersion(HutaoPrivateWindowsVersion* pv)
187187
{
188188
AssertNonNullAndReturn(pv);
189189

190-
// Use RtlGetVersion to get accurate Windows version information
191-
typedef LONG (WINAPI* RtlGetVersionPtr)(PRTL_OSVERSIONINFOW);
190+
typedef LONG(WINAPI* RtlGetVersionPtr)(PRTL_OSVERSIONINFOW);
192191
HMODULE hNtdll = GetModuleHandleW(L"ntdll.dll");
193192
if (hNtdll == nullptr)
194193
{
@@ -199,7 +198,6 @@ HRESULT __stdcall HutaoNative::GetWindowsVersion(HutaoPrivateWindowsVersion* pv)
199198

200199
RtlGetVersionPtr pRtlGetVersion = reinterpret_cast<RtlGetVersionPtr>(
201200
GetProcAddress(hNtdll, "RtlGetVersion"));
202-
203201
if (pRtlGetVersion == nullptr)
204202
{
205203
HRESULT hr = HRESULT_FROM_WIN32(GetLastError());
@@ -209,20 +207,37 @@ HRESULT __stdcall HutaoNative::GetWindowsVersion(HutaoPrivateWindowsVersion* pv)
209207

210208
RTL_OSVERSIONINFOW versionInfo = { 0 };
211209
versionInfo.dwOSVersionInfoSize = sizeof(versionInfo);
212-
210+
213211
LONG status = pRtlGetVersion(&versionInfo);
214-
if (status != 0) // STATUS_SUCCESS is 0
212+
if (status != 0) // STATUS_SUCCESS Ϊ 0
215213
{
216214
HRESULT hr = HRESULT_FROM_NT(status);
217215
ThrowForHR(hr, "RtlGetVersion failed");
218216
return hr;
219217
}
220218

221-
// Fill the structure
222219
pv->major = versionInfo.dwMajorVersion;
223220
pv->minor = versionInfo.dwMinorVersion;
224221
pv->build = versionInfo.dwBuildNumber;
225-
pv->revision = 0; // RTL_OSVERSIONINFOW doesn't have revision field, set to 0
222+
223+
pv->revision = 0;
224+
HKEY hKey = nullptr;
225+
LONG result = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
226+
L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion",
227+
0, KEY_READ, &hKey);
228+
if (result == ERROR_SUCCESS)
229+
{
230+
DWORD ubr = 0;
231+
DWORD dataSize = sizeof(ubr);
232+
DWORD type = 0;
233+
result = RegQueryValueExW(hKey, L"UBR", nullptr, &type,
234+
reinterpret_cast<LPBYTE>(&ubr), &dataSize);
235+
if (result == ERROR_SUCCESS && type == REG_DWORD)
236+
{
237+
pv->revision = ubr;
238+
}
239+
RegCloseKey(hKey);
240+
}
226241

227242
return S_OK;
228243
}

0 commit comments

Comments
 (0)