Bug 457737 - Convert nsRegisterGREWin to Wide calls r=bsmedberg

This commit is contained in:
Brad Lassey 2008-10-20 16:15:32 -04:00
Родитель 4e913c5dcd
Коммит 8dea3437fd
1 изменённых файлов: 53 добавлений и 43 удалений

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

@ -49,19 +49,21 @@
#include "prio.h" #include "prio.h"
#include <windows.h> #include <windows.h>
#include "malloc.h"
static const char kRegKeyRoot[] = "Software\\mozilla.org\\GRE"; static const wchar_t kRegKeyRoot[] = L"Software\\mozilla.org\\GRE";
static const char kRegFileGlobal[] = "global.reginfo"; static const wchar_t kRegFileGlobal[] = L"global.reginfo";
static const char kRegFileUser[] = "user.reginfo"; static const wchar_t kRegFileUser[] = L"user.reginfo";
static nsresult static nsresult
MakeVersionKey(HKEY root, const char* keyname, const nsCString &grehome, MakeVersionKey(HKEY root, const wchar_t* keyname, const nsString &grehome,
const GREProperty *aProperties, PRUint32 aPropertiesLen, const GREProperty *aProperties, PRUint32 aPropertiesLen,
const char *aGREMilestone) const wchar_t *aGREMilestone)
{ {
HKEY subkey; HKEY subkey;
DWORD disp; DWORD disp;
if (::RegCreateKeyEx(root, keyname, NULL, NULL, 0, KEY_WRITE, NULL,
if (::RegCreateKeyExW(root, keyname, NULL, NULL, 0, KEY_WRITE, NULL,
&subkey, &disp) != ERROR_SUCCESS) &subkey, &disp) != ERROR_SUCCESS)
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
@ -71,24 +73,30 @@ MakeVersionKey(HKEY root, const char* keyname, const nsCString &grehome,
} }
PRBool failed = PR_FALSE; PRBool failed = PR_FALSE;
failed |= ::RegSetValueEx(subkey, "Version", NULL, REG_SZ, failed |= ::RegSetValueExW(subkey, L"Version", NULL, REG_SZ,
(BYTE*) aGREMilestone, (BYTE*) aGREMilestone,
strlen(aGREMilestone)) != ERROR_SUCCESS; sizeof(PRUnichar) * (wcslen(aGREMilestone) + 1))
failed |= ::RegSetValueEx(subkey, "GreHome", NULL, REG_SZ, != ERROR_SUCCESS;
(BYTE*) grehome.get(), failed |= ::RegSetValueExW(subkey, L"GreHome", NULL, REG_SZ,
grehome.Length()) != ERROR_SUCCESS; (BYTE*) grehome.get(),
sizeof(PRUnichar) * (grehome.Length() + 1))
!= ERROR_SUCCESS;
for (PRUint32 i = 0; i < aPropertiesLen; ++i) { for (PRUint32 i = 0; i < aPropertiesLen; ++i) {
failed |= ::RegSetValueEx(subkey, aProperties[i].property, NULL, REG_SZ, // Properties should be ascii only
(BYTE*) aProperties[i].value, NS_ConvertASCIItoUTF16 prop(aProperties[i].property);
strlen(aProperties[i].value)) != ERROR_SUCCESS; NS_ConvertASCIItoUTF16 val(aProperties[i].value);
failed |= ::RegSetValueExW(subkey, prop.get(), NULL, REG_SZ,
(BYTE*) val.get(),
sizeof(wchar_t)*(val.Length()+1)
) != ERROR_SUCCESS;
} }
::RegCloseKey(subkey); ::RegCloseKey(subkey);
if (failed) { if (failed) {
// we created a key but couldn't fill it properly: delete it // we created a key but couldn't fill it properly: delete it
::RegDeleteKey(root, keyname); ::RegDeleteKeyW(root, keyname);
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
@ -98,7 +106,7 @@ MakeVersionKey(HKEY root, const char* keyname, const nsCString &grehome,
int int
RegisterXULRunner(PRBool aRegisterGlobally, nsIFile* aLocation, RegisterXULRunner(PRBool aRegisterGlobally, nsIFile* aLocation,
const GREProperty *aProperties, PRUint32 aPropertiesLen, const GREProperty *aProperties, PRUint32 aPropertiesLen,
const char *aGREMilestone) const char *aGREMilestoneAscii)
{ {
// Register ourself in the windows registry, and record what key we created // Register ourself in the windows registry, and record what key we created
// for future unregistration. // for future unregistration.
@ -106,9 +114,9 @@ RegisterXULRunner(PRBool aRegisterGlobally, nsIFile* aLocation,
nsresult rv; nsresult rv;
PRBool irv; PRBool irv;
int i; int i;
NS_ConvertASCIItoUTF16 aGREMilestone(aGREMilestoneAscii);
nsCString greHome; nsString greHome;
rv = aLocation->GetNativePath(greHome); rv = aLocation->GetPath(greHome);
if (NS_FAILED(rv)) if (NS_FAILED(rv))
return rv; return rv;
@ -118,8 +126,8 @@ RegisterXULRunner(PRBool aRegisterGlobally, nsIFile* aLocation,
if (!localSaved) if (!localSaved)
return PR_FALSE; return PR_FALSE;
const char *infoname = aRegisterGlobally ? kRegFileGlobal : kRegFileUser; const wchar_t *infoname = aRegisterGlobally ? kRegFileGlobal : kRegFileUser;
localSaved->AppendNative(nsDependentCString(infoname)); localSaved->Append(nsDependentString(infoname));
PRFileDesc* fd = nsnull; PRFileDesc* fd = nsnull;
rv = localSaved->OpenNSPRFileDesc(PR_CREATE_FILE | PR_RDWR, 0664, &fd); rv = localSaved->OpenNSPRFileDesc(PR_CREATE_FILE | PR_RDWR, 0664, &fd);
@ -129,13 +137,13 @@ RegisterXULRunner(PRBool aRegisterGlobally, nsIFile* aLocation,
} }
HKEY rootKey = NULL; HKEY rootKey = NULL;
char keyName[MAXPATHLEN]; wchar_t keyName[MAXPATHLEN];
PRInt32 r; PRInt32 r;
if (::RegCreateKeyEx(aRegisterGlobally ? HKEY_LOCAL_MACHINE : if (::RegCreateKeyExW(aRegisterGlobally ? HKEY_LOCAL_MACHINE :
HKEY_CURRENT_USER, HKEY_CURRENT_USER,
kRegKeyRoot, NULL, NULL, 0, KEY_WRITE, kRegKeyRoot, NULL, NULL, 0, KEY_WRITE,
NULL, &rootKey, NULL) != ERROR_SUCCESS) { NULL, &rootKey, NULL) != ERROR_SUCCESS) {
irv = PR_FALSE; irv = PR_FALSE;
goto reg_end; goto reg_end;
} }
@ -152,7 +160,7 @@ RegisterXULRunner(PRBool aRegisterGlobally, nsIFile* aLocation,
// There was already a .reginfo file, let's see if we are already // There was already a .reginfo file, let's see if we are already
// registered. // registered.
HKEY existing = NULL; HKEY existing = NULL;
if (::RegOpenKeyEx(rootKey, keyName, NULL, KEY_QUERY_VALUE, &existing) == if (::RegOpenKeyExW(rootKey, keyName, NULL, KEY_QUERY_VALUE, &existing) ==
ERROR_SUCCESS) { ERROR_SUCCESS) {
fprintf(stderr, "Warning: Registry key Software\\mozilla.org\\GRE\\%s already exists.\n" fprintf(stderr, "Warning: Registry key Software\\mozilla.org\\GRE\\%s already exists.\n"
"No action was performed.\n", "No action was performed.\n",
@ -172,22 +180,24 @@ RegisterXULRunner(PRBool aRegisterGlobally, nsIFile* aLocation,
} }
} }
strcpy(keyName, aGREMilestone); wcscpy(keyName, aGREMilestone.get());
rv = MakeVersionKey(rootKey, keyName, greHome, aProperties, aPropertiesLen, rv = MakeVersionKey(rootKey, keyName, greHome, aProperties, aPropertiesLen,
aGREMilestone); aGREMilestone.get());
if (NS_SUCCEEDED(rv)) { if (NS_SUCCEEDED(rv)) {
PR_Write(fd, keyName, strlen(keyName)); NS_ConvertUTF16toUTF8 keyNameAscii(keyName);
PR_Write(fd, keyNameAscii.get(), sizeof(char)*keyNameAscii.Length());
irv = PR_TRUE; irv = PR_TRUE;
goto reg_end; goto reg_end;
} }
for (i = 0; i < 1000; ++i) { for (i = 0; i < 1000; ++i) {
sprintf(keyName, "%s_%i", aGREMilestone, i); swprintf(keyName, L"%s_%i", aGREMilestone.get(), i);
rv = MakeVersionKey(rootKey, keyName, greHome, rv = MakeVersionKey(rootKey, keyName, greHome,
aProperties, aPropertiesLen, aProperties, aPropertiesLen,
aGREMilestone); aGREMilestone.get());
if (NS_SUCCEEDED(rv)) { if (NS_SUCCEEDED(rv)) {
PR_Write(fd, keyName, strlen(keyName)); NS_ConvertUTF16toUTF8 keyNameAscii(keyName);
PR_Write(fd, keyNameAscii.get(), sizeof(char)*keyNameAscii.Length());
irv = PR_TRUE; irv = PR_TRUE;
goto reg_end; goto reg_end;
} }
@ -215,8 +225,8 @@ UnregisterXULRunner(PRBool aGlobal, nsIFile* aLocation,
if (!localSaved) if (!localSaved)
return; return;
const char *infoname = aGlobal ? kRegFileGlobal : kRegFileUser; const wchar_t *infoname = aGlobal ? kRegFileGlobal : kRegFileUser;
localSaved->AppendNative(nsDependentCString(infoname)); localSaved->Append(nsDependentString(infoname));
PRFileDesc* fd = nsnull; PRFileDesc* fd = nsnull;
nsresult rv = localSaved->OpenNSPRFileDesc(PR_RDONLY, 0, &fd); nsresult rv = localSaved->OpenNSPRFileDesc(PR_RDONLY, 0, &fd);
@ -225,7 +235,7 @@ UnregisterXULRunner(PRBool aGlobal, nsIFile* aLocation,
return; return;
} }
char keyName[MAXPATHLEN]; wchar_t keyName[MAXPATHLEN];
PRInt32 r = PR_Read(fd, keyName, MAXPATHLEN); PRInt32 r = PR_Read(fd, keyName, MAXPATHLEN);
PR_Close(fd); PR_Close(fd);
@ -237,17 +247,17 @@ UnregisterXULRunner(PRBool aGlobal, nsIFile* aLocation,
keyName[r] = '\0'; keyName[r] = '\0';
HKEY rootKey = NULL; HKEY rootKey = NULL;
if (::RegOpenKeyEx(aGlobal ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, if (::RegOpenKeyExW(aGlobal ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER,
kRegKeyRoot, 0, KEY_READ, &rootKey) != ERROR_SUCCESS) kRegKeyRoot, 0, KEY_READ, &rootKey) != ERROR_SUCCESS)
return; return;
HKEY subKey = NULL; HKEY subKey = NULL;
if (::RegOpenKeyEx(rootKey, keyName, 0, KEY_READ, &subKey) == ERROR_SUCCESS) { if (::RegOpenKeyExW(rootKey, keyName, 0, KEY_READ, &subKey) == ERROR_SUCCESS) {
char regpath[MAXPATHLEN]; char regpath[MAXPATHLEN];
DWORD reglen = MAXPATHLEN; DWORD reglen = MAXPATHLEN;
if (::RegQueryValueEx(subKey, "GreHome", NULL, NULL, if (::RegQueryValueExW(subKey, L"GreHome", NULL, NULL,
(BYTE*) regpath, &reglen) == ERROR_SUCCESS) { (BYTE*) regpath, &reglen) == ERROR_SUCCESS) {
nsCOMPtr<nsILocalFile> regpathfile; nsCOMPtr<nsILocalFile> regpathfile;
@ -273,6 +283,6 @@ UnregisterXULRunner(PRBool aGlobal, nsIFile* aLocation,
::RegCloseKey(subKey); ::RegCloseKey(subKey);
} }
::RegDeleteKey(rootKey, keyName); ::RegDeleteKeyW(rootKey, keyName);
::RegCloseKey(rootKey); ::RegCloseKey(rootKey);
} }