From a01ee1be83ac7a48229885cfe72d5e36c401e06b Mon Sep 17 00:00:00 2001 From: Sven Strickroth Date: Thu, 6 Jan 2022 13:31:28 +0100 Subject: [PATCH] Try to better detect Windows version and build number This is not nice but I'm not aware of any better solution. Signed-off-by: Sven Strickroth --- src/TortoiseProc/UpdateDownloader.cpp | 25 ++++++++++++++++++++++--- src/TortoiseProc/UpdateDownloader.h | 3 ++- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/TortoiseProc/UpdateDownloader.cpp b/src/TortoiseProc/UpdateDownloader.cpp index 58fd5ef25..76ee943fa 100644 --- a/src/TortoiseProc/UpdateDownloader.cpp +++ b/src/TortoiseProc/UpdateDownloader.cpp @@ -1,6 +1,6 @@ // TortoiseGit - a Windows shell extension for easy version control -// Copyright (C) 2013-2017, 2019-2020 - TortoiseGit +// Copyright (C) 2013-2017, 2019-2022 - TortoiseGit // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -27,10 +27,14 @@ CUpdateDownloader::CUpdateDownloader(HWND hwnd, const CString& sVersion, bool fo , m_eventStop(eventStop) { OSVERSIONINFOEX inf = {0}; - BruteforceGetWindowsVersionNumber(inf); + if (!GetTrueWindowsVersion(inf)) + BruteforceGetWindowsVersionNumber(inf); m_sWindowsPlatform = (inf.dwPlatformId == VER_PLATFORM_WIN32_NT) ? L"NT" : L""; - m_sWindowsVersion.Format(L"%ld.%ld", inf.dwMajorVersion, inf.dwMinorVersion); + if (inf.dwBuildNumber && inf.dwMajorVersion >= 10) + m_sWindowsVersion.Format(L"%ld.%ld.%ld", inf.dwMajorVersion, inf.dwMinorVersion, inf.dwBuildNumber); + else + m_sWindowsVersion.Format(L"%ld.%ld", inf.dwMajorVersion, inf.dwMinorVersion); if (inf.wServicePackMajor) m_sWindowsServicePack.Format(L"SP%ld", inf.wServicePackMajor); @@ -45,6 +49,21 @@ CUpdateDownloader::~CUpdateDownloader() InternetCloseHandle(hOpenHandle); } +bool CUpdateDownloader::GetTrueWindowsVersion(OSVERSIONINFOEX& pOSversion) +{ + typedef LONG(WINAPI * RtlGetVersion_FUNC)(OSVERSIONINFOEXW*); + + CAutoLibrary hNTdllDll = ::LoadLibrary(L"ntdll.dll"); + if (!hNTdllDll) + return false; + + RtlGetVersion_FUNC pRtlGetVersion = (RtlGetVersion_FUNC)::GetProcAddress(hNTdllDll, "RtlGetVersion"); + if (!pRtlGetVersion) + return false; + + return pRtlGetVersion(&pOSversion) == 0; +} + void CUpdateDownloader::BruteforceGetWindowsVersionNumber(OSVERSIONINFOEX& osVersionInfo) { osVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); diff --git a/src/TortoiseProc/UpdateDownloader.h b/src/TortoiseProc/UpdateDownloader.h index 3b92a9895..220897c53 100644 --- a/src/TortoiseProc/UpdateDownloader.h +++ b/src/TortoiseProc/UpdateDownloader.h @@ -1,6 +1,6 @@ // TortoiseGit - a Windows shell extension for easy version control -// Copyright (C) 2014, 2020 - TortoiseGit +// Copyright (C) 2014, 2020-2022 - TortoiseGit // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -36,6 +36,7 @@ public: CString m_sWindowsServicePack; private: + static bool GetTrueWindowsVersion(OSVERSIONINFOEX& osVersionInfo); static void BruteforceGetWindowsVersionNumber(OSVERSIONINFOEX& osVersionInfo); HINTERNET hOpenHandle; -- 2.11.4.GIT