From 871998661d2d47bfddb8da1ab8f44e656c075e76 Mon Sep 17 00:00:00 2001 From: "bryner%brianryner.com" Date: Tue, 20 Apr 2004 21:31:22 +0000 Subject: [PATCH] reintroduce getRegistryEntry (bug 237754). patch by dave532@uklinux.net, r=ben. git-svn-id: svn://10.0.0.236/trunk@155245 18797224-902f-48f8-a5cc-f745e15eee43 --- .../shell/public/nsIWindowsShellService.idl | 22 +++++++++ .../shell/src/nsWindowsShellService.cpp | 47 +++++++++++++++++++ 2 files changed, 69 insertions(+) diff --git a/mozilla/browser/components/shell/public/nsIWindowsShellService.idl b/mozilla/browser/components/shell/public/nsIWindowsShellService.idl index 36dd5fe4837..98eda21b173 100644 --- a/mozilla/browser/components/shell/public/nsIWindowsShellService.idl +++ b/mozilla/browser/components/shell/public/nsIWindowsShellService.idl @@ -59,5 +59,27 @@ interface nsIWindowsShellService : nsIShellService * @return The number of unread (new) mail messages for the current user. */ readonly attribute unsigned long unreadMailCount; + + + /** + * Valid starting keys for the Windows Registry. + */ + const long HKCR = 0; // HKEY_CLASSES_ROOT + const long HKCC = 1; // HKEY_CURRENT_CONFIG + const long HKCU = 2; // HKEY_CURRENT_USER + const long HKLM = 3; // HKEY_LOCAL_MACHINE + const long HKU = 4; // HKEY_USERS + + /** + * Retrieves a Windows Registry entry value. + * + * @param aHKeyConstant The starting key, using the constants defined above. + * @param aSubKeyName The sub key to locate + * @param aValueName The value to locate in the sub key. The empty string + * returns the default value of the sub key. + * @return The value of the specified sub key/value, truncated to 4096 bytes. + */ + string getRegistryEntry(in long aHKeyConstant, in string aSubKeyName, in string aValueName); + }; diff --git a/mozilla/browser/components/shell/src/nsWindowsShellService.cpp b/mozilla/browser/components/shell/src/nsWindowsShellService.cpp index 26dc2f5dbd8..bcf4805436c 100644 --- a/mozilla/browser/components/shell/src/nsWindowsShellService.cpp +++ b/mozilla/browser/components/shell/src/nsWindowsShellService.cpp @@ -794,3 +794,50 @@ nsWindowsShellService::GetMailAccountKey(HKEY* aResult) return PR_FALSE; } +NS_IMETHODIMP +nsWindowsShellService::GetRegistryEntry(PRInt32 aHKEYConstant, + const char *aSubKeyName, + const char *aValueName, + char **aResult) +{ + HKEY hKey, fullKey; + + *aResult = 0; + // Calculate HKEY_* base key + switch (aHKEYConstant) { + case HKCR: + hKey = HKEY_CLASSES_ROOT; + break; + case HKCC: + hKey = HKEY_CURRENT_CONFIG; + break; + case HKCU: + hKey = HKEY_CURRENT_USER; + break; + case HKLM: + hKey = HKEY_LOCAL_MACHINE; + break; + case HKU: + hKey = HKEY_USERS; + break; + default: + return NS_ERROR_INVALID_ARG; + } + + // Open Key + LONG rv = ::RegOpenKeyEx(hKey, aSubKeyName, 0, KEY_READ, &fullKey); + + if (rv == ERROR_SUCCESS) { + char buffer[4096] = { 0 }; + DWORD len = sizeof buffer; + rv = ::RegQueryValueEx(fullKey, aValueName, NULL, NULL, + (LPBYTE)buffer, &len); + + if (rv == ERROR_SUCCESS) + *aResult = PL_strdup(buffer); + } + + ::RegCloseKey(fullKey); + + return *aResult ? NS_OK : NS_ERROR_OUT_OF_MEMORY; +}