Misc fixes for Windows 7
authorSergey Zolotarev <sryze@protonmail.com>
Mon, 26 Oct 2020 19:51:12 +0000 (01:51 +0600)
committerKevin Ottens (Rebase PR Action) <er-vin@users.noreply.github.com>
Wed, 28 Oct 2020 06:24:53 +0000 (06:24 +0000)
Signed-off-by: Sergey Zolotarev <sryze@protonmail.com>
src/common/utility.h
src/common/utility_win.cpp
src/gui/navigationpanehelper.cpp
src/gui/systray.cpp

index 1058cf71953d81348a8221a906267c84e78c26d7..3913fd257761958d8b3ee83038beec5d0d28731f 100644 (file)
@@ -227,6 +227,7 @@ namespace Utility {
     OCSYNC_EXPORT QByteArray conflictFileBaseNameFromPattern(const QByteArray &conflictName);
 
 #ifdef Q_OS_WIN
+    OCSYNC_EXPORT bool registryKeyExists(HKEY hRootKey, const QString &subKey);
     OCSYNC_EXPORT QVariant registryGetKeyValue(HKEY hRootKey, const QString &subKey, const QString &valueName);
     OCSYNC_EXPORT bool registrySetKeyValue(HKEY hRootKey, const QString &subKey, const QString &valueName, DWORD type, const QVariant &value);
     OCSYNC_EXPORT bool registryDeleteKeyTree(HKEY hRootKey, const QString &subKey);
index 13badf59967b10eef01b6a3f99800be45b04d3cc..bfe9d7852e4d6fc245746918ca5f735da5111c5b 100644 (file)
@@ -114,6 +114,17 @@ QRect Utility::getTaskbarDimensions()
     return QRect(barRect.left, barRect.top, (barRect.right - barRect.left), (barRect.bottom - barRect.top));
 }
 
+bool Utility::registryKeyExists(HKEY hRootKey, const QString &subKey)
+{
+    HKEY hKey;
+
+    REGSAM sam = KEY_READ | KEY_WOW64_64KEY;
+    LONG result = RegOpenKeyEx(hRootKey, reinterpret_cast<LPCWSTR>(subKey.utf16()), 0, sam, &hKey);
+
+    RegCloseKey(hKey);
+    return result != ERROR_FILE_NOT_FOUND;
+}
+
 QVariant Utility::registryGetKeyValue(HKEY hRootKey, const QString &subKey, const QString &valueName)
 {
     QVariant value;
index a95830eee22118ce89bca28fd6c250a9b599ebef..ce2bad09c2bb59d194cec51f6c0ae7c53aa75301 100644 (file)
@@ -66,17 +66,18 @@ void NavigationPaneHelper::updateCloudStorageRegistry()
     // that matches ours when we saved.
     QVector<QUuid> entriesToRemove;
 #ifdef Q_OS_WIN
-    Utility::registryWalkSubKeys(
-        HKEY_CURRENT_USER,
-        QStringLiteral(R"(Software\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace)"),
-        [&entriesToRemove](HKEY key, const QString &subKey) {
-            QVariant appName = Utility::registryGetKeyValue(key, subKey, QStringLiteral("ApplicationName"));
-            if (appName.toString() == QLatin1String(APPLICATION_NAME)) {
-                QUuid clsid{ subKey };
-                Q_ASSERT(!clsid.isNull());
-                entriesToRemove.append(clsid);
-            }
-        });
+    QString nameSpaceKey = QStringLiteral(R"(Software\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace)");
+    if (Utility::registryKeyExists(HKEY_CURRENT_USER, nameSpaceKey)) {
+        Utility::registryWalkSubKeys(HKEY_CURRENT_USER, nameSpaceKey,
+            [&entriesToRemove](HKEY key, const QString &subKey) {
+                QVariant appName = Utility::registryGetKeyValue(key, subKey, QStringLiteral("ApplicationName"));
+                if (appName.toString() == QLatin1String(APPLICATION_NAME)) {
+                    QUuid clsid{ subKey };
+                    Q_ASSERT(!clsid.isNull());
+                    entriesToRemove.append(clsid);
+                }
+            });
+    }
 #endif
 
     // Only save folder entries if the option is enabled.
index 3309f54b3db0cfb5c113ef3815200f550c1522f4..421e13c6c2a7b595adcbe1ea36473fd4b85e6fb4 100644 (file)
@@ -238,9 +238,15 @@ Systray::TaskBarPosition Systray::taskbarOrientation() const
     return TaskBarPosition::Top;
 // Windows: Check registry for actual taskbar orientation
 #elif defined(Q_OS_WIN)
-    auto taskbarPosition = Utility::registryGetKeyValue(HKEY_CURRENT_USER,
-        "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\StuckRects3",
-        "Settings");
+    auto taskbarPositionSubkey = QStringLiteral("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\StuckRects3");
+    if (!Utility::registryKeyExists(HKEY_CURRENT_USER, taskbarPositionSubkey)) {
+        // Windows 7
+        taskbarPositionSubkey = QStringLiteral("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\StuckRects2");
+    }
+    if (!Utility::registryKeyExists(HKEY_CURRENT_USER, taskbarPositionSubkey)) {
+        return TaskBarPosition::Bottom;
+    }
+    auto taskbarPosition = Utility::registryGetKeyValue(HKEY_CURRENT_USER, taskbarPositionSubkey, "Settings");
     switch (taskbarPosition.toInt()) {
     // Mapping windows binary value (0 = left, 1 = top, 2 = right, 3 = bottom) to qml logic (0 = bottom, 1 = left...)
     case 0:
@@ -393,7 +399,7 @@ QPoint Systray::computeWindowPosition(int width, int height) const
     qCDebug(lcSystray) << "taskbarScreenEdge:" << taskbarScreenEdge;
     qCDebug(lcSystray) << "screenRect:" << screenRect;
     qCDebug(lcSystray) << "windowRect (reference)" << QRect(topLeft, bottomRight);
-    qCDebug(lcSystray) << "windowRect (adjusted )" << windowRect;
+    qCDebug(lcSystray) << "windowRect (adjusted)" << windowRect;
 
     return windowRect.topLeft();
 }