summaryrefslogtreecommitdiff
path: root/vcl/win
diff options
context:
space:
mode:
authorkubak <kuba@openoffice.com.pl>2024-04-27 18:27:46 +0200
committerMike Kaganski <mike.kaganski@collabora.com>2024-04-30 13:49:46 +0200
commit2db558b5a1c01b3a08f60962c0115a34aa09bf90 (patch)
tree94fe1209e2a25b2f4124ad29a62999b26b76c78d /vcl/win
parent82ba7e2f78fa1c867c7df40a5b0120ced4446702 (diff)
tdf#145305 Improve Windows version string.
Version: 6.1 -> Windows 7 SP1, 6.2 -> Windows 8, 6.3 -> Windows 8.1, 10.0 build number < 22000 -> Windows 10, 10.0 build number >= 22000 -> Windows 11. Change string format in AboutBox from "Windows 10.0 build 22631" to "Windows 11 (10.0 build 22631)". Co-authored-by: Achintya Sharma <sharmaachintya08@gmail.com> Joel Dowdy <joeldowdy12@gmail.com> Change-Id: Icdd559a08f5d67d39c4a088585c2113bf4c3695b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166779 Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com> Tested-by: Jenkins
Diffstat (limited to 'vcl/win')
-rw-r--r--vcl/win/app/salinst.cxx44
1 files changed, 32 insertions, 12 deletions
diff --git a/vcl/win/app/salinst.cxx b/vcl/win/app/salinst.cxx
index b6341d9a47a3..4fc2b5e57e72 100644
--- a/vcl/win/app/salinst.cxx
+++ b/vcl/win/app/salinst.cxx
@@ -23,7 +23,6 @@
#include <osl/conditn.hxx>
#include <osl/file.hxx>
-#include <rtl/ustrbuf.hxx>
#include <sal/log.hxx>
#include <tools/debug.hxx>
#include <tools/time.hxx>
@@ -949,10 +948,34 @@ typedef LONG NTSTATUS;
typedef NTSTATUS(WINAPI* RtlGetVersion_t)(PRTL_OSVERSIONINFOW);
constexpr NTSTATUS STATUS_SUCCESS = 0x00000000;
+static OUString getOSVersionString(const OUString& aNtVersionString, DWORD nBuildNumber)
+{
+ OUString aVersionPlusBuild
+ = " (" + aNtVersionString + " build " + OUString::number(nBuildNumber) + ")";
+
+ if (aNtVersionString == "6.1")
+ return "Windows 7 Service Pack 1" + aVersionPlusBuild;
+ else if (aNtVersionString == "6.2")
+ return "Windows 8" + aVersionPlusBuild;
+ else if (aNtVersionString == "6.3")
+ return "Windows 8.1" + aVersionPlusBuild;
+ else if (aNtVersionString == "10.0")
+ {
+ if (nBuildNumber >= 22000)
+ return "Windows 11" + aVersionPlusBuild;
+ else
+ return "Windows 10" + aVersionPlusBuild;
+ }
+ else if (aNtVersionString.isEmpty()) // We don't know what Windows it is
+ return u"Windows unknown"_ustr;
+ else if (nBuildNumber == 0) // We don't know the build number
+ return "Windows (" + aNtVersionString + ")";
+ else // return Windows NtVersion and build number - we don't know this release
+ return "Windows" + aVersionPlusBuild;
+}
+
OUString WinSalInstance::getOSVersion()
{
- OUStringBuffer aVer(50); // capacity for string like "Windows 6.1 Service Pack 1 build 7601"
- aVer.append("Windows ");
// GetVersion(Ex) and VersionHelpers (based on VerifyVersionInfo) API are
// subject to manifest-based behavior since Windows 8.1, so give wrong results.
// Another approach would be to use NetWkstaGetInfo, but that has some small
@@ -960,6 +983,7 @@ OUString WinSalInstance::getOSVersion()
// poor network connections.
// So go with a solution described at https://msdn.microsoft.com/en-us/library/ms724429
bool bHaveVerFromKernel32 = false;
+ OUString aNtVersion;
if (HMODULE h_kernel32 = GetModuleHandleW(L"kernel32.dll"))
{
wchar_t szPath[MAX_PATH];
@@ -977,7 +1001,7 @@ OUString WinSalInstance::getOSVersion()
if (VerQueryValueW(ver.get(), L"\\", &pBlock, &dwBlockSz) != FALSE && dwBlockSz >= sizeof(VS_FIXEDFILEINFO))
{
VS_FIXEDFILEINFO* vi1 = static_cast<VS_FIXEDFILEINFO*>(pBlock);
- aVer.append(OUString::number(HIWORD(vi1->dwProductVersionMS)) + "."
+ aNtVersion = (OUString::number(HIWORD(vi1->dwProductVersionMS)) + "."
+ OUString::number(LOWORD(vi1->dwProductVersionMS)));
bHaveVerFromKernel32 = true;
}
@@ -988,6 +1012,7 @@ OUString WinSalInstance::getOSVersion()
// Now use RtlGetVersion (which is not subject to deprecation for GetVersion(Ex) API)
// to get build number and SP info
bool bHaveVerFromRtlGetVersion = false;
+ DWORD nBuildNumber = 0;
if (HMODULE h_ntdll = GetModuleHandleW(L"ntdll.dll"))
{
if (auto RtlGetVersion
@@ -998,19 +1023,14 @@ OUString WinSalInstance::getOSVersion()
if (STATUS_SUCCESS == RtlGetVersion(&vi2))
{
if (!bHaveVerFromKernel32) // we failed above; let's hope this would be useful
- aVer.append(OUString::number(vi2.dwMajorVersion) + "."
+ aNtVersion = (OUString::number(vi2.dwMajorVersion) + "."
+ OUString::number(vi2.dwMinorVersion));
- aVer.append(" ");
- if (vi2.szCSDVersion[0])
- aVer.append(OUString::Concat(o3tl::toU(vi2.szCSDVersion)) + " ");
- aVer.append("Build " + OUString::number(vi2.dwBuildNumber));
+ nBuildNumber = vi2.dwBuildNumber;
bHaveVerFromRtlGetVersion = true;
}
}
}
- if (!bHaveVerFromKernel32 && !bHaveVerFromRtlGetVersion)
- aVer.append("unknown");
- return aVer.makeStringAndClear();
+ return getOSVersionString(aNtVersion, nBuildNumber);
}
void WinSalInstance::BeforeAbort(const OUString&, bool)