Use QOperatingSystemVersion.

This commit is contained in:
John Preston 2021-09-01 18:33:53 +03:00
parent a0a3de125a
commit 1d2a18929a
1 changed files with 7 additions and 13 deletions

View File

@ -21,6 +21,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "mainwindow.h" #include "mainwindow.h"
#include "windows_quiethours_h.h" #include "windows_quiethours_h.h"
#include <QtCore/QOperatingSystemVersion>
#include <Shobjidl.h> #include <Shobjidl.h>
#include <shellapi.h> #include <shellapi.h>
@ -261,21 +263,13 @@ DWORD QuietHoursValue = 0;
[[nodiscard]] bool UseQuietHoursRegistryEntry() { [[nodiscard]] bool UseQuietHoursRegistryEntry() {
static const bool result = [] { static const bool result = [] {
// Taken from QSysInfo. const auto version = QOperatingSystemVersion::current();
OSVERSIONINFO result = { sizeof(OSVERSIONINFO), 0, 0, 0, 0,{ '\0' } };
if (const auto library = GetModuleHandle(L"ntdll.dll")) {
using RtlGetVersionFunction = NTSTATUS(NTAPI*)(LPOSVERSIONINFO);
const auto RtlGetVersion = reinterpret_cast<RtlGetVersionFunction>(
GetProcAddress(library, "RtlGetVersion"));
if (RtlGetVersion) {
RtlGetVersion(&result);
}
}
// At build 17134 (Redstone 4) the "Quiet hours" was replaced // At build 17134 (Redstone 4) the "Quiet hours" was replaced
// by "Focus assist" and it looks like it doesn't use registry. // by "Focus assist" and it looks like it doesn't use registry.
return (result.dwMajorVersion == 10 return (version.majorVersion() == 10)
&& result.dwMinorVersion == 0 && (version.minorVersion() == 0)
&& result.dwBuildNumber < 17134); && (version.microVersion() < 17134);
}(); }();
return result; return result;
} }