From 05a829f923a88e69b2ceaa372820a2dcb8c083cd Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 27 Sep 2019 13:36:38 +0200 Subject: Win32: Consolidate registry code Add a RAII class for registry keys and use it throughout the code base. Change-Id: I666b2fbb790f83436443101d6bc1e3c0525e78df Reviewed-by: Volker Hilsheimer --- src/corelib/global/qglobal.cpp | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) (limited to 'src/corelib/global/qglobal.cpp') diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp index 17aab17fe4..6ae5bf299a 100644 --- a/src/corelib/global/qglobal.cpp +++ b/src/corelib/global/qglobal.cpp @@ -47,12 +47,11 @@ #include "qoperatingsystemversion.h" #include "qoperatingsystemversion_p.h" #if defined(Q_OS_WIN) || defined(Q_OS_CYGWIN) || defined(Q_OS_WINRT) -#include "qoperatingsystemversion_win_p.h" -# if QT_CONFIG(settings) -# include "qsettings.h" -# include "qvariant.h" +# include "qoperatingsystemversion_win_p.h" +# ifndef Q_OS_WINRT +# include "private/qwinregistry_p.h" # endif -#endif +#endif // Q_OS_WIN || Q_OS_CYGWIN #include #include @@ -2190,28 +2189,25 @@ const QSysInfo::WinVersion QSysInfo::WindowsVersion = QSysInfo::windowsVersion() QT_WARNING_POP #endif -static QString readRegistryString(const QString &key, const QString &subKey) +static QString readVersionRegistryString(const wchar_t *subKey) { -#if QT_CONFIG(settings) - QSettings settings(key, QSettings::NativeFormat); - return settings.value(subKey).toString(); +#if !defined(QT_BUILD_QMAKE) && !defined(Q_OS_WINRT) + return QWinRegistryKey(HKEY_LOCAL_MACHINE, LR"(SOFTWARE\Microsoft\Windows NT\CurrentVersion)") + .stringValue(subKey); #else - Q_UNUSED(key); - Q_UNUSED(subKey); - return QString(); + Q_UNUSED(subKey); + return QString(); #endif } -static inline QString windowsVersionKey() { return QStringLiteral(R"(HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion)"); } - static inline QString windows10ReleaseId() { - return readRegistryString(windowsVersionKey(), QStringLiteral("ReleaseId")); + return readVersionRegistryString(L"ReleaseId"); } static inline QString windows7Build() { - return readRegistryString(windowsVersionKey(), QStringLiteral("CurrentBuild")); + return readVersionRegistryString(L"CurrentBuild"); } static QString winSp_helper() @@ -3078,6 +3074,7 @@ QByteArray QSysInfo::machineUniqueId() } #elif defined(Q_OS_WIN) && !defined(Q_OS_WINRT) // Let's poke at the registry + // ### Qt 6: Use new helpers from qwinregistry.cpp (once bootstrap builds are obsolete) HKEY key = NULL; if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Cryptography", 0, KEY_READ | KEY_WOW64_64KEY, &key) == ERROR_SUCCESS) { -- cgit v1.2.3