Author: hbelusca
Date: Sat May 28 19:12:14 2016
New Revision: 71443

URL: http://svn.reactos.org/svn/reactos?rev=71443&view=rev
Log:
[DESK.CPL]
- Only use the minimum required registry rights needed in RegOpenKeyEx and 
RegCreateKeyEx calls.
- Fix SetDesktopBackColor function where we tried to save the selected desktop 
background color in the registry only in the case where opening the 
corresponding registry key actually failed... >_>
  Now we do the right thing!

Modified:
    trunk/reactos/dll/cpl/desk/background.c

Modified: trunk/reactos/dll/cpl/desk/background.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/cpl/desk/background.c?rev=71443&r1=71442&r2=71443&view=diff
==============================================================================
--- trunk/reactos/dll/cpl/desk/background.c     [iso-8859-1] (original)
+++ trunk/reactos/dll/cpl/desk/background.c     [iso-8859-1] Sat May 28 
19:12:14 2016
@@ -179,7 +179,6 @@
     LV_ITEM listItem;
     HIMAGELIST himl;
 
-
     szFileTypes = GdipGetSupportedFileExtensions();
     if (!szFileTypes)
     {
@@ -216,7 +215,6 @@
                                                 sizeof(sfi),
                                                 SHGFI_SYSICONINDEX | 
SHGFI_SMALLICON |
                                                 SHGFI_DISPLAYNAME);
-
                 if (himl == NULL)
                     break;
 
@@ -332,7 +330,7 @@
     pData->listViewItemCount++;
 
     /* Add current wallpaper if any */
-    result = RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("Control Panel\\Desktop"), 
0, KEY_ALL_ACCESS, &regKey);
+    result = RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("Control Panel\\Desktop"), 
0, KEY_QUERY_VALUE, &regKey);
     if (result == ERROR_SUCCESS)
     {
         result = RegQueryValueEx(regKey, TEXT("Wallpaper"), 0, &varType, 
(LPBYTE)wallpaperFilename, &bufferSize);
@@ -376,7 +374,6 @@
                                              sizeof(sfi),
                                              SHGFI_SYSICONINDEX | 
SHGFI_SMALLICON |
                                              SHGFI_DISPLAYNAME);
-
             if (himl != NULL)
             {
                 if (i++ == 0)
@@ -513,8 +510,8 @@
     LONG res = ERROR_SUCCESS;
     CHOOSECOLOR cc;
 
-    res = RegCreateKeyEx(HKEY_CURRENT_USER, TEXT("Control Panel\\Appearance"), 
0, NULL, 0,
-        KEY_ALL_ACCESS, NULL, &hKey, NULL);
+    res = RegCreateKeyEx(HKEY_CURRENT_USER, TEXT("Control Panel\\Appearance"), 
0, NULL,
+                         REG_OPTION_NON_VOLATILE, KEY_QUERY_VALUE, NULL, 
&hKey, NULL);
     /* Now the key is either created or opened existing, if res == 
ERROR_SUCCESS */
     if (res == ERROR_SUCCESS)
     {
@@ -522,7 +519,7 @@
         DWORD dwType = REG_BINARY;
         DWORD cbData = sizeof(pData->custom_colors);
         res = RegQueryValueEx(hKey, TEXT("CustomColors"), NULL, &dwType,
-            (LPBYTE)pData->custom_colors, &cbData);
+                              (LPBYTE)pData->custom_colors, &cbData);
         RegCloseKey(hKey);
         hKey = NULL;
     }
@@ -554,12 +551,12 @@
 
         /* Save custom colors to reg. To this moment key must be created 
already. See above */
         res = RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("Control 
Panel\\Appearance"), 0,
-            KEY_WRITE, &hKey);
+                           KEY_SET_VALUE, &hKey);
         if (res == ERROR_SUCCESS)
         {
             /* Key opened */
             RegSetValueEx(hKey, TEXT("CustomColors"), 0, REG_BINARY,
-                (const BYTE *)pData->custom_colors, 
sizeof(pData->custom_colors));
+                          (LPBYTE)pData->custom_colors, 
sizeof(pData->custom_colors));
             RegCloseKey(hKey);
             hKey = NULL;
         }
@@ -907,7 +904,6 @@
     size_t length = 0;
     GpStatus status;
 
-
     if (FAILED(SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA | CSIDL_FLAG_CREATE, 
NULL, 0, szWallpaper)))
     {
         return;
@@ -918,24 +914,28 @@
         return;
     }
 
-    RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("Control Panel\\Desktop"), 0, 
KEY_ALL_ACCESS, &regKey);
+    if (RegCreateKeyEx(HKEY_CURRENT_USER, TEXT("Control Panel\\Desktop"), 0, 
NULL,
+                       REG_OPTION_NON_VOLATILE, KEY_SET_VALUE, NULL, &regKey, 
NULL) != ERROR_SUCCESS)
+    {
+        return;
+    }
 
     if (pData->placementSelection == PLACEMENT_TILE)
     {
-        RegSetValueEx(regKey, TEXT("TileWallpaper"), 0, REG_SZ, (BYTE 
*)TEXT("1"), sizeof(TCHAR) * 2);
-        RegSetValueEx(regKey, TEXT("WallpaperStyle"), 0, REG_SZ, (BYTE 
*)TEXT("0"), sizeof(TCHAR) * 2);
+        RegSetValueEx(regKey, TEXT("TileWallpaper"), 0, REG_SZ, 
(LPBYTE)TEXT("1"), sizeof(TCHAR) * 2);
+        RegSetValueEx(regKey, TEXT("WallpaperStyle"), 0, REG_SZ, 
(LPBYTE)TEXT("0"), sizeof(TCHAR) * 2);
     }
 
     if (pData->placementSelection == PLACEMENT_CENTER)
     {
-        RegSetValueEx(regKey, TEXT("TileWallpaper"), 0, REG_SZ, (BYTE 
*)TEXT("0"), sizeof(TCHAR) * 2);
-        RegSetValueEx(regKey, TEXT("WallpaperStyle"), 0, REG_SZ, (BYTE 
*)TEXT("0"), sizeof(TCHAR) * 2);
+        RegSetValueEx(regKey, TEXT("TileWallpaper"), 0, REG_SZ, 
(LPBYTE)TEXT("0"), sizeof(TCHAR) * 2);
+        RegSetValueEx(regKey, TEXT("WallpaperStyle"), 0, REG_SZ, 
(LPBYTE)TEXT("0"), sizeof(TCHAR) * 2);
     }
 
     if (pData->placementSelection == PLACEMENT_STRETCH)
     {
-        RegSetValueEx(regKey, TEXT("TileWallpaper"), 0, REG_SZ, (BYTE 
*)TEXT("0"), sizeof(TCHAR) * 2);
-        RegSetValueEx(regKey, TEXT("WallpaperStyle"), 0, REG_SZ, (BYTE 
*)TEXT("2"), sizeof(TCHAR) * 2);
+        RegSetValueEx(regKey, TEXT("TileWallpaper"), 0, REG_SZ, 
(LPBYTE)TEXT("0"), sizeof(TCHAR) * 2);
+        RegSetValueEx(regKey, TEXT("WallpaperStyle"), 0, REG_SZ, 
(LPBYTE)TEXT("2"), sizeof(TCHAR) * 2);
     }
 
     if (pData->backgroundItems[pData->backgroundSelection].bWallpaper == TRUE)
@@ -979,7 +979,7 @@
                           TEXT("ConvertedWallpaper"),
                           0,
                           REG_SZ,
-                          
(BYTE*)pData->backgroundItems[pData->backgroundSelection].szFilename,
+                          
(LPBYTE)pData->backgroundItems[pData->backgroundSelection].szFilename,
                           (DWORD)((length + 1) * sizeof(TCHAR)));
         }
 
@@ -989,7 +989,7 @@
                           TEXT("OriginalWallpaper"),
                           0,
                           REG_SZ,
-                          (BYTE *)szWallpaper,
+                          (LPBYTE)szWallpaper,
                           (DWORD)((length + 1) * sizeof(TCHAR)));
         }
 
@@ -1008,30 +1008,34 @@
 static VOID
 SetDesktopBackColor(HWND hwndDlg, DATA *pData)
 {
+    HKEY hKey;
     INT iElement = COLOR_BACKGROUND;
-    HKEY hKey;
-    LONG result;
     TCHAR clText[16];
     BYTE red, green, blue;
-    DWORD dwDispostion;
-
-    if( !SetSysColors( 1, &iElement, &g_GlobalData.desktop_color ) )
-        MessageBox(hwndDlg, TEXT("SetSysColor() failed!"), /* these error 
texts can need internationalization? */
+
+    if (!SetSysColors(1, &iElement, &g_GlobalData.desktop_color))
+    {
+        /* FIXME: these error texts can need internationalization? */
+        MessageBox(hwndDlg, TEXT("SetSysColor() failed!"),
             TEXT("Error!"), MB_ICONSTOP );
-
-    result = RegCreateKeyEx( HKEY_CURRENT_USER, TEXT("Control Panel\\Colors"), 
0, NULL, 0,
-        KEY_ALL_ACCESS, NULL, &hKey, &dwDispostion );
-    if (result != ERROR_SUCCESS)
-    {
-        red   = GetRValue(g_GlobalData.desktop_color);
-        green = GetGValue(g_GlobalData.desktop_color);
-        blue  = GetBValue(g_GlobalData.desktop_color);
-        /* Format string to be set to registry */
-        StringCbPrintf(clText, sizeof(clText), TEXT("%d %d %d"), red, green, 
blue);
-        RegSetValueEx(hKey, TEXT("Background"), 0, REG_SZ, (BYTE *)clText,
-                      (lstrlen(clText) + 1) * sizeof(TCHAR));
-        RegCloseKey(hKey);
-    }
+    }
+
+    if (RegCreateKeyEx(HKEY_CURRENT_USER, TEXT("Control Panel\\Colors"), 0, 
NULL,
+                       REG_OPTION_NON_VOLATILE, KEY_SET_VALUE, NULL, &hKey, 
NULL) != ERROR_SUCCESS)
+    {
+        return;
+    }
+
+    red   = GetRValue(g_GlobalData.desktop_color);
+    green = GetGValue(g_GlobalData.desktop_color);
+    blue  = GetBValue(g_GlobalData.desktop_color);
+
+    /* Format string to be set to registry */
+    StringCbPrintf(clText, sizeof(clText), TEXT("%d %d %d"), red, green, blue);
+    RegSetValueEx(hKey, TEXT("Background"), 0, REG_SZ, (LPBYTE)clText,
+                  (wcslen(clText) + 1) * sizeof(TCHAR));
+
+    RegCloseKey(hKey);
 }
 
 INT_PTR CALLBACK


Reply via email to