Bug 320449 - Make properties of GRE_GetGREPathWithProperties useful, r=darin; nsGREGlue.cpp supplementary logic fix r=#developers, earlier testing would have been good :-(

git-svn-id: svn://10.0.0.236/trunk@186161 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
bsmedberg%covad.net 2005-12-16 14:58:57 +00:00
parent 5231833194
commit 9888e5eb9a
8 changed files with 77 additions and 26 deletions

View File

@ -619,8 +619,9 @@ GRE_GetPathFromRegKey(HKEY aRegKey,
const GREProperty *propsEnd = properties + propertiesLength;
for (; ok && props < propsEnd; ++props) {
pathlen = sizeof(pathbuf);
if (!::RegQueryValueEx(subKey, props->property, NULL, &pathtype,
(BYTE*) pathbuf, &pathlen) ||
if (::RegQueryValueEx(subKey, props->property, NULL, &pathtype,
(BYTE*) pathbuf, &pathlen) != ERROR_SUCCESS ||
strcmp(pathbuf, props->value))
ok = PR_FALSE;
}

View File

@ -63,6 +63,10 @@ PROGRAM = xulrunner-bin$(BIN_SUFFIX)
endif
DEFINES += -DXULRUNNER_PROGNAME=\"xulrunner\"
ifdef MOZ_JAVAXPCOM
DEFINES += -DMOZ_JAVAXPCOM
endif
REQUIRES = \
xpcom \
string \

View File

@ -40,12 +40,14 @@
#include "nscore.h"
class nsIFile;
struct GREProperty;
/**
* @return PR_TRUE on success
*/
NS_HIDDEN_(PRBool)
RegisterXULRunner(PRBool aRegisterGlobally, nsIFile* aLocation);
RegisterXULRunner(PRBool aRegisterGlobally, nsIFile* aLocation,
const GREProperty *aProperties, PRUint32 aPropertiesLen);
NS_HIDDEN_(void)
UnregisterXULRunner(PRBool aUnregisterGlobally, nsIFile* aLocation);

View File

@ -36,6 +36,7 @@
* ***** END LICENSE BLOCK ***** */
#include "nsRegisterGRE.h"
#include "nsXPCOMGlue.h"
#include "nsIFile.h"
#include "nsILocalFile.h"
@ -81,7 +82,8 @@ private:
};
static PRBool
MakeConfFile(const char *regfile, const nsCString &greHome)
MakeConfFile(const char *regfile, const nsCString &greHome,
const GREProperty *aProperties, PRUint32 aPropertiesLen)
{
// If the file exists, don't create it again!
if (access(regfile, R_OK) == 0)
@ -106,6 +108,12 @@ MakeConfFile(const char *regfile, const nsCString &greHome)
if (PR_Write(fd, greHome.get(), greHome.Length()) != greHome.Length())
ok = PR_FALSE;
for (PRUint32 i = 0; i < aPropertiesLen; ++i) {
if (PR_fprintf(fd, "\n%s=%s",
aProperties[i].property, aProperties[i].value) <= 0)
ok = PR_FALSE;
}
PR_Write(fd, "\n", 1);
}
@ -117,7 +125,8 @@ MakeConfFile(const char *regfile, const nsCString &greHome)
PRBool
RegisterXULRunner(PRBool aRegisterGlobally, nsIFile* aLocation)
RegisterXULRunner(PRBool aRegisterGlobally, nsIFile* aLocation,
const GREProperty *aProperties, PRUint32 aPropertiesLen)
{
// Register ourself in /etc/gre.d or ~/.gre.d/ and record what key we created
// for future unregistration.
@ -188,7 +197,7 @@ RegisterXULRunner(PRBool aRegisterGlobally, nsIFile* aLocation)
}
PR_snprintf(regfile, MAXPATHLEN, "%s/%s.conf", root, kGREBuildID);
if (MakeConfFile(regfile, greHome)) {
if (MakeConfFile(regfile, greHome, aProperties, aPropertiesLen)) {
PR_Write(fd, kGREBuildID, sizeof(kGREBuildID) - 1);
return PR_TRUE;
}
@ -199,7 +208,7 @@ RegisterXULRunner(PRBool aRegisterGlobally, nsIFile* aLocation)
PR_snprintf(regfile, MAXPATHLEN, "%s/%s.conf", root, buildID);
if (MakeConfFile(regfile, greHome)) {
if (MakeConfFile(regfile, greHome, aProperties, aPropertiesLen)) {
PR_Write(fd, buildID, strlen(buildID));
return PR_TRUE;
}

View File

@ -41,7 +41,8 @@
#include <stdio.h>
int
RegisterXULRunner(PRBool aRegisterGlobally, nsIFile* aLocation)
RegisterXULRunner(PRBool aRegisterGlobally, nsIFile* aLocation,
const GREProperty *aProperties, PRUint32 aPropertiesLen)
{
fprintf(stderr, "Registration not implemented on this platform!\n");
return 1;

View File

@ -43,6 +43,7 @@
#include "nsBuildID.h"
#include "nsAppRunner.h" // for MAXPATHLEN
#include "nsString.h"
#include "nsXPCOMGlue.h"
#include "prio.h"
@ -53,7 +54,8 @@ static const char kRegFileGlobal[] = "global.reginfo";
static const char kRegFileUser[] = "user.reginfo";
static nsresult
MakeVersionKey(HKEY root, const char* keyname, const nsCAutoString &grehome)
MakeVersionKey(HKEY root, const char* keyname, const nsCAutoString &grehome,
const GREProperty *aProperties, PRUint32 aPropertiesLen)
{
HKEY subkey;
DWORD disp;
@ -66,23 +68,34 @@ MakeVersionKey(HKEY root, const char* keyname, const nsCAutoString &grehome)
return NS_ERROR_FAILURE;
}
if (::RegSetValueEx(subkey, "Version", NULL, REG_SZ, (BYTE*) GRE_BUILD_ID,
sizeof(GRE_BUILD_ID) - 1) == ERROR_SUCCESS &&
::RegSetValueEx(subkey, "GreHome", NULL, REG_SZ, (BYTE*) grehome.get(),
grehome.Length()) == ERROR_SUCCESS) {
::RegCloseKey(subkey);
return NS_OK;
PRBool failed = PR_FALSE;
failed |= ::RegSetValueEx(subkey, "Version", NULL, REG_SZ,
(BYTE*) GRE_BUILD_ID,
sizeof(GRE_BUILD_ID) - 1) != ERROR_SUCCESS;
failed |= ::RegSetValueEx(subkey, "GreHome", NULL, REG_SZ,
(BYTE*) grehome.get(),
grehome.Length()) != ERROR_SUCCESS;
for (PRUint32 i = 0; i < aPropertiesLen; ++i) {
failed |= ::RegSetValueEx(subkey, aProperties[i].property, NULL, REG_SZ,
(BYTE*) aProperties[i].value,
strlen(aProperties[i].value)) != ERROR_SUCCESS;
}
// we created a key but couldn't fill it properly: delete it
::RegCloseKey(subkey);
::RegDeleteKey(root, keyname);
return NS_ERROR_FAILURE;
if (failed) {
// we created a key but couldn't fill it properly: delete it
::RegDeleteKey(root, keyname);
return NS_ERROR_FAILURE;
}
return NS_OK;
}
int
RegisterXULRunner(PRBool aRegisterGlobally, nsIFile* aLocation)
RegisterXULRunner(PRBool aRegisterGlobally, nsIFile* aLocation,
const GREProperty *aProperties, PRUint32 aPropertiesLen)
{
// Register ourself in the windows registry, and record what key we created
// for future unregistration.
@ -157,7 +170,7 @@ RegisterXULRunner(PRBool aRegisterGlobally, nsIFile* aLocation)
}
strcpy(keyName, GRE_BUILD_ID);
rv = MakeVersionKey(rootKey, keyName, greHome);
rv = MakeVersionKey(rootKey, keyName, greHome, aProperties, aPropertiesLen);
if (NS_SUCCEEDED(rv)) {
PR_Write(fd, keyName, strlen(keyName));
irv = PR_TRUE;
@ -166,7 +179,8 @@ RegisterXULRunner(PRBool aRegisterGlobally, nsIFile* aLocation)
for (i = 0; i < 1000; ++i) {
sprintf(keyName, GRE_BUILD_ID "_%i", i);
rv = MakeVersionKey(rootKey, keyName, greHome);
rv = MakeVersionKey(rootKey, keyName, greHome,
aProperties, aPropertiesLen);
if (NS_SUCCEEDED(rv)) {
PR_Write(fd, keyName, strlen(keyName));
irv = PR_TRUE;

View File

@ -349,6 +349,13 @@ InstallXULApp(nsIFile* aXULRunnerDir,
return 0;
}
static const GREProperty kGREProperties[] = {
{ "xulrunner", "true" }
#ifdef MOZ_JAVAXPCOM
, { "javaxpcom", "1" }
#endif
};
int main(int argc, char* argv[])
{
if (argc > 1 && (IsArg(argv[1], "h") ||
@ -379,7 +386,9 @@ int main(int argc, char* argv[])
if (NS_FAILED(rv))
return 2;
return RegisterXULRunner(registerGlobal, regDir) ? 0 : 2;
return RegisterXULRunner(registerGlobal, regDir,
kGREProperties,
NS_ARRAY_LENGTH(kGREProperties)) ? 0 : 2;
}
registerGlobal = IsArg(argv[1], "unregister-global");
@ -405,11 +414,16 @@ int main(int argc, char* argv[])
}
char path[MAXPATHLEN];
const GREVersionRange vr = {
static const GREVersionRange vr = {
argv[2], PR_TRUE,
argv[2], PR_TRUE
};
nsresult rv = GRE_GetGREPathWithProperties(&vr, 1, nsnull, 0,
static const GREProperty kProperties[] = {
{ "xulrunner", "true" }
};
nsresult rv = GRE_GetGREPathWithProperties(&vr, 1, kProperties,
NS_ARRAY_LENGTH(kProperties),
path, sizeof(path));
if (NS_FAILED(rv))
return 1;

View File

@ -39,6 +39,7 @@
#include "nsINIParser.h"
#include "prtypes.h"
#include "nsXPCOMPrivate.h" // for XP MAXPATHLEN
#include "nsMemory.h" // for NS_ARRAY_LENGTH
#ifdef XP_WIN
#include <windows.h>
@ -153,8 +154,13 @@ main(int argc, char **argv)
if (NS_SUCCEEDED(rv))
range.upperInclusive = PR_TRUE;
rv = GRE_GetGREPathWithProperties(&range, 1, nsnull, 0,
greDir, sizeof(greDir));
static const GREProperty kProperties[] = {
{ "xulrunner", "true" }
};
rv = GRE_GetGREPathWithProperties(&range, 1,
kProperties, NS_ARRAY_LENGTH(kProperties),
greDir, sizeof(greDir));
if (NS_FAILED(rv)) {
// XXXbsmedberg: Do something much smarter here: notify the
// user/offer to download/?