diff options
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/platforms/windows/qwindowscontext.cpp | 26 | ||||
-rw-r--r-- | src/plugins/platforms/windows/qwindowsservices.cpp | 27 |
2 files changed, 15 insertions, 38 deletions
diff --git a/src/plugins/platforms/windows/qwindowscontext.cpp b/src/plugins/platforms/windows/qwindowscontext.cpp index bb349f08a7..f7d04b667d 100644 --- a/src/plugins/platforms/windows/qwindowscontext.cpp +++ b/src/plugins/platforms/windows/qwindowscontext.cpp @@ -79,6 +79,7 @@ #include <QtCore/qscopedpointer.h> #include <QtCore/quuid.h> #include <QtCore/private/qsystemlibrary_p.h> +#include <QtCore/private/qwinregistry_p.h> #include <QtEventDispatcherSupport/private/qwindowsguieventdispatcher_p.h> @@ -1518,28 +1519,13 @@ QTouchDevice *QWindowsContext::touchDevice() const d->m_pointerHandler.touchDevice() : d->m_mouseHandler.touchDevice(); } -static DWORD readDwordRegistrySetting(const wchar_t *regKey, const wchar_t *subKey, DWORD defaultValue) -{ - DWORD result = defaultValue; - HKEY handle; - if (RegOpenKeyEx(HKEY_CURRENT_USER, regKey, 0, KEY_READ, &handle) == ERROR_SUCCESS) { - DWORD type; - if (RegQueryValueEx(handle, subKey, nullptr, &type, nullptr, nullptr) == ERROR_SUCCESS - && type == REG_DWORD) { - DWORD value; - DWORD size = sizeof(result); - if (RegQueryValueEx(handle, subKey, nullptr, nullptr, reinterpret_cast<unsigned char *>(&value), &size) == ERROR_SUCCESS) - result = value; - } - RegCloseKey(handle); - } - return result; -} - DWORD QWindowsContext::readAdvancedExplorerSettings(const wchar_t *subKey, DWORD defaultValue) { - return readDwordRegistrySetting(L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced", - subKey, defaultValue); + const auto value = + QWinRegistryKey(HKEY_CURRENT_USER, + LR"(Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced)") + .dwordValue(subKey); + return value.second ? value.first : defaultValue; } static inline bool isEmptyRect(const RECT &rect) diff --git a/src/plugins/platforms/windows/qwindowsservices.cpp b/src/plugins/platforms/windows/qwindowsservices.cpp index b2b1dee232..83b052bb49 100644 --- a/src/plugins/platforms/windows/qwindowsservices.cpp +++ b/src/plugins/platforms/windows/qwindowsservices.cpp @@ -45,6 +45,8 @@ #include <QtCore/qdebug.h> #include <QtCore/qdir.h> +#include <QtCore/private/qwinregistry_p.h> + #include <shlobj.h> #include <intshcut.h> @@ -78,35 +80,24 @@ static inline QString mailCommand() const wchar_t mailUserKey[] = L"Software\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\mailto\\UserChoice"; - wchar_t command[MAX_PATH] = {0}; // Check if user has set preference, otherwise use default. - HKEY handle; - QString keyName; - if (!RegOpenKeyEx(HKEY_CURRENT_USER, mailUserKey, 0, KEY_READ, &handle)) { - DWORD bufferSize = BufferSize; - if (!RegQueryValueEx(handle, L"Progid", nullptr, nullptr, reinterpret_cast<unsigned char*>(command), &bufferSize)) - keyName = QString::fromWCharArray(command); - RegCloseKey(handle); - } + QString keyName = QWinRegistryKey(HKEY_CURRENT_USER, mailUserKey) + .stringValue( L"Progid"); const QLatin1String mailto = keyName.isEmpty() ? QLatin1String("mailto") : QLatin1String(); keyName += mailto + QLatin1String("\\Shell\\Open\\Command"); if (debug) qDebug() << __FUNCTION__ << "keyName=" << keyName; - command[0] = 0; - if (!RegOpenKeyExW(HKEY_CLASSES_ROOT, reinterpret_cast<const wchar_t*>(keyName.utf16()), 0, KEY_READ, &handle)) { - DWORD bufferSize = BufferSize; - RegQueryValueEx(handle, L"", nullptr, nullptr, reinterpret_cast<unsigned char*>(command), &bufferSize); - RegCloseKey(handle); - } + const QString command = QWinRegistryKey(HKEY_CLASSES_ROOT, keyName).stringValue(L""); // QTBUG-57816: As of Windows 10, if there is no mail client installed, an entry like // "rundll32.exe .. url.dll,MailToProtocolHandler %l" is returned. Launching it // silently fails or brings up a broken dialog after a long time, so exclude it and // fall back to ShellExecute() which brings up the URL assocation dialog. - if (!command[0] || wcsstr(command, L",MailToProtocolHandler") != nullptr) + if (command.isEmpty() || command.contains(QLatin1String(",MailToProtocolHandler"))) return QString(); wchar_t expandedCommand[MAX_PATH] = {0}; - return ExpandEnvironmentStrings(command, expandedCommand, MAX_PATH) ? - QString::fromWCharArray(expandedCommand) : QString::fromWCharArray(command); + return ExpandEnvironmentStrings(reinterpret_cast<const wchar_t *>(command.utf16()), + expandedCommand, MAX_PATH) + ? QString::fromWCharArray(expandedCommand) : command; } static inline bool launchMail(const QUrl &url) |