Bug 719538: make nsWindowsShellService use nsIWindowsRegKey, r=jmathies

This commit is contained in:
Gavin Sharp 2012-01-19 11:44:27 -08:00
parent c3136238c1
commit 367f1197cc

View File

@ -189,7 +189,6 @@ typedef struct {
#define APP_REG_NAME L"Firefox" #define APP_REG_NAME L"Firefox"
#define CLS_HTML "FirefoxHTML" #define CLS_HTML "FirefoxHTML"
#define CLS_URL "FirefoxURL" #define CLS_URL "FirefoxURL"
#define CPL_DESKTOP L"Control Panel\\Desktop"
#define VAL_OPEN "\"%APPPATH%\" -requestPending -osint -url \"%1\"" #define VAL_OPEN "\"%APPPATH%\" -requestPending -osint -url \"%1\""
#define VAL_FILE_ICON "%APPPATH%,1" #define VAL_FILE_ICON "%APPPATH%,1"
#define DI "\\DefaultIcon" #define DI "\\DefaultIcon"
@ -617,44 +616,41 @@ nsWindowsShellService::SetDesktopBackground(nsIDOMElement* aElement,
// if the file was written successfully, set it as the system wallpaper // if the file was written successfully, set it as the system wallpaper
if (NS_SUCCEEDED(rv)) { if (NS_SUCCEEDED(rv)) {
bool result = false; nsCOMPtr<nsIWindowsRegKey> regKey =
DWORD dwDisp = 0; do_CreateInstance("@mozilla.org/windows-registry-key;1", &rv);
HKEY key; NS_ENSURE_SUCCESS(rv, rv);
// Try to create/open a subkey under HKCU.
DWORD res = ::RegCreateKeyExW(HKEY_CURRENT_USER, CPL_DESKTOP,
0, NULL, REG_OPTION_NON_VOLATILE,
KEY_WRITE, NULL, &key, &dwDisp);
if (REG_SUCCEEDED(res)) {
PRUnichar tile[2], style[2];
switch (aPosition) {
case BACKGROUND_TILE:
tile[0] = '1';
style[0] = '1';
break;
case BACKGROUND_CENTER:
tile[0] = '0';
style[0] = '0';
break;
case BACKGROUND_STRETCH:
tile[0] = '0';
style[0] = '2';
break;
}
tile[1] = '\0';
style[1] = '\0';
// The size is always 3 unicode characters. rv = regKey->Create(nsIWindowsRegKey::ROOT_KEY_CURRENT_USER,
PRInt32 size = 3 * sizeof(PRUnichar); NS_LITERAL_STRING("Control Panel\\Desktop"),
::RegSetValueExW(key, L"TileWallpaper", nsIWindowsRegKey::ACCESS_SET_VALUE);
0, REG_SZ, (const BYTE *)tile, size); NS_ENSURE_SUCCESS(rv, rv);
::RegSetValueExW(key, L"WallpaperStyle",
0, REG_SZ, (const BYTE *)style, size);
::SystemParametersInfoW(SPI_SETDESKWALLPAPER, 0, (PVOID)path.get(),
SPIF_UPDATEINIFILE | SPIF_SENDCHANGE);
// Close the key we opened. nsAutoString tile;
::RegCloseKey(key); nsAutoString style;
switch (aPosition) {
case BACKGROUND_TILE:
style.AssignLiteral("0");
tile.AssignLiteral("1");
break;
case BACKGROUND_CENTER:
style.AssignLiteral("0");
tile.AssignLiteral("0");
break;
case BACKGROUND_STRETCH:
style.AssignLiteral("2");
tile.AssignLiteral("0");
break;
} }
rv = regKey->WriteStringValue(NS_LITERAL_STRING("TileWallpaper"), tile);
NS_ENSURE_SUCCESS(rv, rv);
rv = regKey->WriteStringValue(NS_LITERAL_STRING("WallpaperStyle"), style);
NS_ENSURE_SUCCESS(rv, rv);
rv = regKey->Close();
NS_ENSURE_SUCCESS(rv, rv);
::SystemParametersInfoW(SPI_SETDESKWALLPAPER, 0, (PVOID)path.get(),
SPIF_UPDATEINIFILE | SPIF_SENDCHANGE);
} }
return rv; return rv;
} }
@ -779,28 +775,24 @@ nsWindowsShellService::SetDesktopBackgroundColor(PRUint32 aColor)
::SetSysColors(sizeof(aParameters) / sizeof(int), aParameters, colors); ::SetSysColors(sizeof(aParameters) / sizeof(int), aParameters, colors);
bool result = false; nsresult rv;
DWORD dwDisp = 0; nsCOMPtr<nsIWindowsRegKey> regKey =
HKEY key; do_CreateInstance("@mozilla.org/windows-registry-key;1", &rv);
// Try to create/open a subkey under HKCU. NS_ENSURE_SUCCESS(rv, rv);
DWORD rv = ::RegCreateKeyExW(HKEY_CURRENT_USER,
L"Control Panel\\Colors", 0, NULL,
REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
&key, &dwDisp);
if (REG_SUCCEEDED(rv)) { rv = regKey->Create(nsIWindowsRegKey::ROOT_KEY_CURRENT_USER,
char rgb[12]; NS_LITERAL_STRING("Control Panel\\Colors"),
sprintf((char*)rgb, "%u %u %u\0", r, g, b); nsIWindowsRegKey::ACCESS_SET_VALUE);
NS_ConvertUTF8toUTF16 backColor(rgb); NS_ENSURE_SUCCESS(rv, rv);
::RegSetValueExW(key, L"Background", PRUnichar rgb[12];
0, REG_SZ, (const BYTE *)backColor.get(), _snwprintf(rgb, 12, L"%u %u %u", r, g, b);
(backColor.Length() + 1) * sizeof(PRUnichar));
} rv = regKey->WriteStringValue(NS_LITERAL_STRING("Background"),
nsDependentString(rgb));
// Close the key we opened. NS_ENSURE_SUCCESS(rv, rv);
::RegCloseKey(key);
return NS_OK; return regKey->Close();
} }
NS_IMETHODIMP NS_IMETHODIMP