зеркало из https://github.com/mozilla/pjs.git
Bug 279627 Can't consistently set as default mail client r+sr=mscott
This commit is contained in:
Родитель
e18b82563c
Коммит
33a989ee14
|
@ -241,93 +241,37 @@ nsresult nsMapiRegistryUtils::recursiveDeleteKey(HKEY hKeyParent, const char* lp
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult nsMapiRegistryUtils::RegCopyKey(HKEY SrcKey, HKEY TrgKey, const char* TrgSubKeyName)
|
/* static */
|
||||||
|
void nsMapiRegistryUtils::RegCopyKey(HKEY aSrcKey, HKEY aDestKey, const char* aSubKeyName)
|
||||||
{
|
{
|
||||||
HKEY SrcSubKey;
|
HKEY srcSubKey, destSubKey;
|
||||||
HKEY TrgSubKey;
|
char valueName[MAX_PATH + 1], keyName[MAX_PATH + 1];
|
||||||
int ValEnumIndx=0;
|
BYTE valueData[MAX_PATH + 1];
|
||||||
int KeyEnumIndx=0;
|
DWORD nameSize, dataSize, keySize, valueType;
|
||||||
|
LONG Err;
|
||||||
|
|
||||||
char ValName[MAX_PATH+1];
|
// open source key
|
||||||
char KeyName[MAX_PATH+1];
|
if (::RegOpenKeyEx(aSrcKey, aSubKeyName, NULL, KEY_ALL_ACCESS, &srcSubKey) != ERROR_SUCCESS)
|
||||||
|
return;
|
||||||
|
|
||||||
DWORD VarType;
|
// create target key
|
||||||
DWORD dwSize = MAX_PATH + 1;
|
if (::RegCreateKeyEx(aDestKey, aSubKeyName, NULL, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &destSubKey, NULL) == ERROR_SUCCESS) {
|
||||||
DWORD dwBufferSize = dwSize;
|
for (DWORD valueIndex = 0;
|
||||||
unsigned char szBuffer[MAX_PATH+1];
|
nameSize = MAX_PATH + 1,
|
||||||
|
dataSize = MAX_PATH + 1,
|
||||||
|
::RegEnumValue(srcSubKey, valueIndex, valueName, &nameSize, NULL, &valueType, valueData, &dataSize) == ERROR_SUCCESS;
|
||||||
|
valueIndex++)
|
||||||
|
::RegSetValueEx(destSubKey, valueName, NULL, valueType, valueData, dataSize);
|
||||||
|
|
||||||
LONG Err;
|
for (DWORD keyIndex = 0;
|
||||||
DWORD KeyDisposition;
|
keySize = MAX_PATH + 1,
|
||||||
FILETIME LastWriteTime;
|
::RegEnumKeyEx(srcSubKey, keyIndex, keyName, &keySize, NULL, NULL, NULL, NULL) == ERROR_SUCCESS;
|
||||||
|
keyIndex++)
|
||||||
|
RegCopyKey(srcSubKey, destSubKey, keyName);
|
||||||
|
|
||||||
// create target key
|
::RegCloseKey(destSubKey);
|
||||||
if (::RegCreateKeyEx(TrgKey,TrgSubKeyName,NULL,NULL,REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,NULL,&TrgSubKey,&KeyDisposition) == ERROR_SUCCESS)
|
}
|
||||||
{
|
::RegCloseKey(srcSubKey);
|
||||||
do {
|
|
||||||
do {
|
|
||||||
// read value from source key
|
|
||||||
Err = ERROR_NOT_ENOUGH_MEMORY;
|
|
||||||
do {
|
|
||||||
dwSize=MAX_PATH+1;
|
|
||||||
Err = ::RegEnumValue(SrcKey,ValEnumIndx,ValName,&dwSize,NULL,&VarType,szBuffer,&dwBufferSize);
|
|
||||||
} while (Err == ERROR_NOT_ENOUGH_MEMORY);
|
|
||||||
|
|
||||||
// done copying this key
|
|
||||||
if (Err == ERROR_NO_MORE_ITEMS)
|
|
||||||
break;
|
|
||||||
|
|
||||||
// unknown error return
|
|
||||||
if (Err != ERROR_SUCCESS)
|
|
||||||
goto quit_err;
|
|
||||||
|
|
||||||
// write value to target key
|
|
||||||
if (::RegSetValueEx(TrgSubKey,ValName,NULL,VarType,szBuffer,dwBufferSize) != ERROR_SUCCESS)
|
|
||||||
goto quit_get_err;
|
|
||||||
|
|
||||||
// read next value
|
|
||||||
ValEnumIndx++;
|
|
||||||
} while (true);
|
|
||||||
|
|
||||||
// if copying under the same key avoid endless recursions
|
|
||||||
do {
|
|
||||||
// enum sub keys
|
|
||||||
dwSize =MAX_PATH+1; // reset dwSize
|
|
||||||
Err = ::RegEnumKeyEx(SrcKey,KeyEnumIndx++,KeyName,&dwSize,NULL,NULL,NULL,&LastWriteTime);
|
|
||||||
} while ((SrcKey == TrgKey) && !strnicmp(KeyName,TrgSubKeyName,strlen(KeyName)) && (Err == ERROR_SUCCESS));
|
|
||||||
|
|
||||||
// done copying this key
|
|
||||||
if (Err == ERROR_NO_MORE_ITEMS)
|
|
||||||
break;
|
|
||||||
|
|
||||||
// unknown error return
|
|
||||||
if (Err != ERROR_SUCCESS)
|
|
||||||
goto quit_get_err;
|
|
||||||
|
|
||||||
// open the source subkey
|
|
||||||
if (::RegOpenKeyEx(SrcKey,KeyName,NULL,KEY_ALL_ACCESS,&SrcSubKey) != ERROR_SUCCESS)
|
|
||||||
goto quit_get_err;
|
|
||||||
|
|
||||||
// recurs with the subkey
|
|
||||||
if ((Err = RegCopyKey(SrcSubKey, TrgSubKey, KeyName)) != ERROR_SUCCESS)
|
|
||||||
break;
|
|
||||||
|
|
||||||
if (::RegCloseKey(SrcSubKey) != ERROR_SUCCESS)
|
|
||||||
goto quit_get_err;
|
|
||||||
} while (true);
|
|
||||||
}
|
|
||||||
|
|
||||||
// normal quit
|
|
||||||
quit_err:
|
|
||||||
::RegCloseKey(TrgSubKey);
|
|
||||||
if (Err == ERROR_NO_MORE_ITEMS)
|
|
||||||
return NS_OK;
|
|
||||||
else
|
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
|
|
||||||
// abnormal quit
|
|
||||||
quit_get_err:
|
|
||||||
::RegCloseKey(TrgSubKey);
|
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PRBool nsMapiRegistryUtils::IsDefaultMailClient()
|
PRBool nsMapiRegistryUtils::IsDefaultMailClient()
|
||||||
|
@ -659,14 +603,10 @@ nsresult nsMapiRegistryUtils::RestoreBackedUpMapiDll()
|
||||||
// we will copy the keys into Software\Clases
|
// we will copy the keys into Software\Clases
|
||||||
nsresult nsMapiRegistryUtils::setProtocolHandler(const char * aDefaultAppRegKey, const char * protocolName)
|
nsresult nsMapiRegistryUtils::setProtocolHandler(const char * aDefaultAppRegKey, const char * protocolName)
|
||||||
{
|
{
|
||||||
nsCAutoString srcKeyName;
|
|
||||||
srcKeyName = aDefaultAppRegKey;
|
|
||||||
srcKeyName.Append(protocolName);
|
|
||||||
|
|
||||||
HKEY srcKey;
|
HKEY srcKey;
|
||||||
HKEY trgKey;
|
HKEY trgKey;
|
||||||
|
|
||||||
::RegOpenKeyEx(HKEY_LOCAL_MACHINE, srcKeyName.get(), 0, KEY_READ, &srcKey);
|
::RegOpenKeyEx(HKEY_LOCAL_MACHINE, aDefaultAppRegKey, 0, KEY_READ, &srcKey);
|
||||||
::RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Software\\Classes", 0, KEY_READ, &trgKey);
|
::RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Software\\Classes", 0, KEY_READ, &trgKey);
|
||||||
|
|
||||||
RegCopyKey(srcKey, trgKey, protocolName);
|
RegCopyKey(srcKey, trgKey, protocolName);
|
||||||
|
|
|
@ -71,7 +71,7 @@ private :
|
||||||
|
|
||||||
PRBool mRestrictedRegAccess; // cannot write to HKLM in the registry
|
PRBool mRestrictedRegAccess; // cannot write to HKLM in the registry
|
||||||
|
|
||||||
nsresult RegCopyKey(HKEY SrcKey, HKEY TrgKey, const char* TrgSubKeyName); // copies a key and all sub keys to TrgKey.
|
static void RegCopyKey(HKEY aSrcKey, HKEY aDestKey, const char* aSubKeyName); // recursively copies the given sub key from the src key to the dest key
|
||||||
nsresult recursiveDeleteKey(HKEY hKeyParent, const char* lpszKeyChild);
|
nsresult recursiveDeleteKey(HKEY hKeyParent, const char* lpszKeyChild);
|
||||||
|
|
||||||
public :
|
public :
|
||||||
|
|
Загрузка…
Ссылка в новой задаче