reintroduce getRegistryEntry (bug 237754). patch by dave532@uklinux.net, r=ben.

This commit is contained in:
bryner%brianryner.com 2004-04-20 21:31:22 +00:00
Родитель 0e8eab3dcb
Коммит 90dc121899
2 изменённых файлов: 69 добавлений и 0 удалений

Просмотреть файл

@ -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);
};

Просмотреть файл

@ -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;
}