Use existing fct for RegKeyQuery instead of redundant subroutine
authorDominique Fuchs <32204802+DominiqueFuchs@users.noreply.github.com>
Sun, 8 Sep 2019 11:44:00 +0000 (13:44 +0200)
committerDominique Fuchs <32204802+DominiqueFuchs@users.noreply.github.com>
Sun, 8 Sep 2019 11:44:00 +0000 (13:44 +0200)
Signed-off-by: Dominique Fuchs <32204802+DominiqueFuchs@users.noreply.github.com>
src/common/utility_win.cpp

index 52f7087ff27b7ae59dfeec401756b8cf932a99d1..3a8c16fffff8c7fcdbe6b902cdd95bfcc18b2913 100644 (file)
@@ -90,32 +90,13 @@ void setLaunchOnStartup_private(const QString &appName, const QString &guiName,
 // TODO: Right now only detection on toggle/startup, not when windows theme is switched while nextcloud is running
 static inline bool hasDarkSystray_private()
 {
-    bool hasDarkSystray = true;
-    // Open registry key first, continue only on success (may be legitimately absent in earlier windows versions)
-    HKEY hKey;
-    LONG lRes = RegOpenKeyExW(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", 0, KEY_READ, &hKey);
-    
-    // classical windows function - preserve buff size for DWORD, call ExW version, store regkey value in nResult
-    if (lRes == ERROR_SUCCESS) {
-        DWORD dwBufferSize(sizeof(DWORD));
-        DWORD nResult(0);
-
-        // https://docs.microsoft.com/en-us/windows/win32/api/winreg/nf-winreg-regqueryvalueexw
-        LONG nError = ::RegQueryValueExW(hKey,
-            L"SystemUsesLightTheme",
-            NULL,
-            NULL,
-            reinterpret_cast<LPBYTE>(&nResult),
-            &dwBufferSize);
-        
-        // if RegQuery returned no error and light theme was found, change systray return value
-        if (nError == ERROR_SUCCESS && nResult == 1)
-            hasDarkSystray = false;
-
-        return hasDarkSystray;
-    } else {
-        // fallback to true if regkey could not be determined
-        return hasDarkSystray;
+    if(Utility::registryGetKeyValue(    HKEY_CURRENT_USER,
+                                        "Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize",
+                                        "SystemUsesLightTheme" ) == 1) {
+        return false;
+    }
+    else {
+        return true;
     }
 }