2005-06-10 23:21:27 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Communicator.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corp.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2003
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Sean Su <ssu@netscape.com>
|
|
|
|
* Benjamin Smedberg <benjamin@smedbergs.us>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#include "nsXPCOMGlue.h"
|
|
|
|
|
2009-05-21 01:00:45 +04:00
|
|
|
#include "nsAutoPtr.h"
|
2005-09-01 16:33:47 +04:00
|
|
|
#include "nsINIParser.h"
|
|
|
|
#include "nsVersionComparator.h"
|
|
|
|
#include "nsXPCOMPrivate.h"
|
|
|
|
|
2005-06-10 23:21:27 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2005-06-13 20:45:22 +04:00
|
|
|
#include <string.h>
|
2008-12-03 16:41:12 +03:00
|
|
|
#include <wchar.h>
|
2005-06-10 23:21:27 +04:00
|
|
|
|
|
|
|
#ifdef XP_WIN32
|
|
|
|
# include <windows.h>
|
|
|
|
# include <mbstring.h>
|
|
|
|
# include <io.h>
|
|
|
|
# define snprintf _snprintf
|
|
|
|
# define R_OK 04
|
|
|
|
#elif defined(XP_OS2)
|
|
|
|
# define INCL_DOS
|
|
|
|
# include <os2.h>
|
|
|
|
#elif defined(XP_MACOSX)
|
2009-03-19 20:41:13 +03:00
|
|
|
# include <CoreFoundation/CoreFoundation.h>
|
2005-06-23 20:55:52 +04:00
|
|
|
# include <unistd.h>
|
2005-09-01 16:33:47 +04:00
|
|
|
# include <dirent.h>
|
2005-06-10 23:21:27 +04:00
|
|
|
#elif defined(XP_UNIX)
|
|
|
|
# include <unistd.h>
|
|
|
|
# include <sys/param.h>
|
2005-07-01 16:24:07 +04:00
|
|
|
# include <dirent.h>
|
2005-06-10 23:21:27 +04:00
|
|
|
#elif defined(XP_BEOS)
|
|
|
|
# include <FindDirectory.h>
|
|
|
|
# include <Path.h>
|
|
|
|
# include <unistd.h>
|
|
|
|
# include <sys/param.h>
|
|
|
|
# include <OS.h>
|
|
|
|
# include <image.h>
|
2006-09-27 20:07:06 +04:00
|
|
|
# include <dirent.h>
|
|
|
|
# include <FindDirectory.h>
|
2005-06-10 23:21:27 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
2005-09-15 21:49:51 +04:00
|
|
|
/**
|
|
|
|
* Like strncat, appends a buffer to another buffer. This is where the
|
|
|
|
* similarity ends. Firstly, the "count" here is the total size of the buffer
|
|
|
|
* (not the number of chars to append. Secondly, the function returns PR_FALSE
|
|
|
|
* if the buffer is not long enough to hold the concatenated string.
|
|
|
|
*/
|
|
|
|
static PRBool safe_strncat(char *dest, const char *append, PRUint32 count)
|
|
|
|
{
|
|
|
|
char *end = dest + count - 1;
|
|
|
|
|
|
|
|
// skip to the end of dest
|
|
|
|
while (*dest)
|
|
|
|
++dest;
|
|
|
|
|
|
|
|
while (*append && dest < end) {
|
|
|
|
*dest = *append;
|
|
|
|
++dest, ++append;
|
|
|
|
}
|
|
|
|
|
|
|
|
*dest = '\0';
|
|
|
|
|
|
|
|
return *append == '\0';
|
|
|
|
}
|
|
|
|
|
2008-12-03 16:41:12 +03:00
|
|
|
#ifdef XP_WIN
|
|
|
|
static PRBool
|
|
|
|
CheckVersion(const PRUnichar* toCheck,
|
|
|
|
const GREVersionRange *versions,
|
|
|
|
PRUint32 versionsLength);
|
|
|
|
#endif
|
2005-09-01 16:33:47 +04:00
|
|
|
static PRBool
|
|
|
|
CheckVersion(const char* toCheck,
|
|
|
|
const GREVersionRange *versions,
|
|
|
|
PRUint32 versionsLength);
|
2005-06-23 20:55:52 +04:00
|
|
|
|
2008-12-03 16:41:12 +03:00
|
|
|
|
2005-06-23 20:55:52 +04:00
|
|
|
#if defined(XP_MACOSX)
|
|
|
|
|
|
|
|
static PRBool
|
2005-09-01 16:33:47 +04:00
|
|
|
GRE_FindGREFramework(const char* rootPath,
|
|
|
|
const GREVersionRange *versions,
|
|
|
|
PRUint32 versionsLength,
|
|
|
|
const GREProperty *properties,
|
|
|
|
PRUint32 propertiesLength,
|
2005-06-23 20:55:52 +04:00
|
|
|
char* buffer, PRUint32 buflen);
|
|
|
|
|
2006-09-27 20:07:06 +04:00
|
|
|
#elif defined(XP_UNIX) || defined(XP_BEOS)
|
2005-06-23 20:55:52 +04:00
|
|
|
|
2005-06-10 23:21:27 +04:00
|
|
|
static PRBool
|
2005-09-01 16:33:47 +04:00
|
|
|
GRE_GetPathFromConfigDir(const char* dirname,
|
|
|
|
const GREVersionRange *versions,
|
|
|
|
PRUint32 versionsLength,
|
|
|
|
const GREProperty *properties,
|
|
|
|
PRUint32 propertiesLength,
|
2005-06-10 23:21:27 +04:00
|
|
|
char* buffer, PRUint32 buflen);
|
2005-09-01 16:33:47 +04:00
|
|
|
|
2005-06-10 23:21:27 +04:00
|
|
|
static PRBool
|
2005-09-01 16:33:47 +04:00
|
|
|
GRE_GetPathFromConfigFile(const char* filename,
|
|
|
|
const GREVersionRange *versions,
|
|
|
|
PRUint32 versionsLength,
|
|
|
|
const GREProperty *properties,
|
|
|
|
PRUint32 propertiesLength,
|
2005-06-10 23:21:27 +04:00
|
|
|
char* buffer, PRUint32 buflen);
|
|
|
|
|
2005-06-23 20:55:52 +04:00
|
|
|
#elif defined(XP_WIN)
|
|
|
|
|
2005-06-10 23:21:27 +04:00
|
|
|
static PRBool
|
2005-09-01 16:33:47 +04:00
|
|
|
GRE_GetPathFromRegKey(HKEY aRegKey,
|
|
|
|
const GREVersionRange *versions,
|
|
|
|
PRUint32 versionsLength,
|
|
|
|
const GREProperty *properties,
|
|
|
|
PRUint32 propertiesLength,
|
2009-05-21 01:00:45 +04:00
|
|
|
char* buffer, PRUint32 buflen);
|
2005-06-23 20:55:52 +04:00
|
|
|
|
2005-06-10 23:21:27 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
nsresult
|
2005-09-01 16:33:47 +04:00
|
|
|
GRE_GetGREPathWithProperties(const GREVersionRange *versions,
|
|
|
|
PRUint32 versionsLength,
|
|
|
|
const GREProperty *properties,
|
|
|
|
PRUint32 propertiesLength,
|
|
|
|
char *aBuffer, PRUint32 aBufLen)
|
2005-06-10 23:21:27 +04:00
|
|
|
{
|
2008-03-22 07:25:34 +03:00
|
|
|
#ifdef TARGET_XPCOM_ABI
|
|
|
|
// append the ABI to the properties to match only binary
|
|
|
|
// compatible GREs
|
|
|
|
static const GREProperty kExtraProperty =
|
|
|
|
{ "abi", TARGET_XPCOM_ABI };
|
|
|
|
|
|
|
|
GREProperty *allProperties = new GREProperty[propertiesLength + 1];
|
|
|
|
if (!allProperties)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
for (PRUint32 i=0; i<propertiesLength; i++) {
|
|
|
|
allProperties[i].property = properties[i].property;
|
|
|
|
allProperties[i].value = properties[i].value;
|
|
|
|
}
|
|
|
|
allProperties[propertiesLength].property = kExtraProperty.property;
|
|
|
|
allProperties[propertiesLength].value = kExtraProperty.value;
|
|
|
|
PRUint32 allPropertiesLength = propertiesLength + 1;
|
|
|
|
#else
|
2008-04-01 18:13:27 +04:00
|
|
|
const GREProperty *allProperties = properties;
|
2008-03-22 07:25:34 +03:00
|
|
|
PRUint32 allPropertiesLength = propertiesLength;
|
|
|
|
#endif
|
|
|
|
|
2005-06-10 23:21:27 +04:00
|
|
|
// if GRE_HOME is in the environment, use that GRE
|
2005-07-01 16:24:07 +04:00
|
|
|
const char* env = getenv("GRE_HOME");
|
2005-06-10 23:21:27 +04:00
|
|
|
if (env && *env) {
|
2006-03-28 22:48:21 +04:00
|
|
|
char p[MAXPATHLEN];
|
|
|
|
snprintf(p, sizeof(p), "%s" XPCOM_FILE_PATH_SEPARATOR XPCOM_DLL, env);
|
|
|
|
p[sizeof(p) - 1] = '\0';
|
|
|
|
|
2005-06-10 23:21:27 +04:00
|
|
|
#if XP_UNIX
|
2006-03-28 22:48:21 +04:00
|
|
|
if (realpath(p, aBuffer))
|
2005-06-10 23:21:27 +04:00
|
|
|
return NS_OK;
|
2008-12-03 16:42:03 +03:00
|
|
|
#elif WINCE
|
|
|
|
if (p[0] != '\\')
|
|
|
|
{
|
|
|
|
unsigned short dir[MAX_PATH];
|
|
|
|
unsigned short path[MAX_PATH];
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, p, -1, path, MAX_PATH);
|
|
|
|
_wfullpath(dir,path,MAX_PATH);
|
|
|
|
WideCharToMultiByte(CP_ACP, 0, dir, -1, aBuffer, MAX_PATH, NULL, NULL);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
strcpy(aBuffer, p);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
2005-06-23 20:55:52 +04:00
|
|
|
#elif XP_WIN
|
2006-03-28 22:48:21 +04:00
|
|
|
if (_fullpath(aBuffer, p, aBufLen))
|
2005-06-10 23:21:27 +04:00
|
|
|
return NS_OK;
|
2007-01-10 11:43:08 +03:00
|
|
|
#elif XP_OS2
|
|
|
|
// realpath on OS/2 returns a unix-ized path, so re-native-ize
|
|
|
|
if (realpath(p, aBuffer)) {
|
|
|
|
for (char* ptr = strchr(aBuffer, '/'); ptr; ptr = strchr(ptr, '/'))
|
|
|
|
*ptr = '\\';
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2006-09-27 20:07:06 +04:00
|
|
|
#elif XP_BEOS
|
|
|
|
BPath path;
|
|
|
|
status_t result;
|
|
|
|
result = path.SetTo(p,0,true);
|
|
|
|
if (result == B_OK)
|
|
|
|
{
|
|
|
|
sprintf(aBuffer, path.Path());
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2005-06-10 23:21:27 +04:00
|
|
|
#else
|
|
|
|
// hope for the best
|
|
|
|
// xxxbsmedberg: other platforms should have a "make absolute" function
|
|
|
|
#endif
|
|
|
|
|
2006-03-28 22:48:21 +04:00
|
|
|
if (strlen(p) >= aBufLen)
|
2005-06-10 23:21:27 +04:00
|
|
|
return NS_ERROR_FILE_NAME_TOO_LONG;
|
|
|
|
|
2006-03-28 22:48:21 +04:00
|
|
|
strcpy(aBuffer, p);
|
2005-06-10 23:21:27 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// the Gecko bits that sit next to the application or in the LD_LIBRARY_PATH
|
2005-07-01 16:24:07 +04:00
|
|
|
env = getenv("USE_LOCAL_GRE");
|
2005-06-10 23:21:27 +04:00
|
|
|
if (env && *env) {
|
|
|
|
*aBuffer = nsnull;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-06-23 20:55:52 +04:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
aBuffer[0] = '\0';
|
|
|
|
|
2005-10-09 22:20:03 +04:00
|
|
|
// Check the bundle first, for <bundle>/Contents/Frameworks/XUL.framework/libxpcom.dylib
|
2005-06-23 20:55:52 +04:00
|
|
|
CFBundleRef appBundle = CFBundleGetMainBundle();
|
|
|
|
if (appBundle) {
|
|
|
|
CFURLRef fwurl = CFBundleCopyPrivateFrameworksURL(appBundle);
|
2005-07-26 02:16:56 +04:00
|
|
|
CFURLRef absfwurl = nsnull;
|
2005-06-23 20:55:52 +04:00
|
|
|
if (fwurl) {
|
2005-07-26 02:16:56 +04:00
|
|
|
absfwurl = CFURLCopyAbsoluteURL(fwurl);
|
|
|
|
CFRelease(fwurl);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (absfwurl) {
|
2005-06-23 20:55:52 +04:00
|
|
|
CFURLRef xulurl =
|
2005-07-26 02:16:56 +04:00
|
|
|
CFURLCreateCopyAppendingPathComponent(NULL, absfwurl,
|
2005-10-09 22:20:03 +04:00
|
|
|
CFSTR(GRE_FRAMEWORK_NAME),
|
|
|
|
PR_TRUE);
|
2005-06-23 20:55:52 +04:00
|
|
|
|
|
|
|
if (xulurl) {
|
|
|
|
CFURLRef xpcomurl =
|
|
|
|
CFURLCreateCopyAppendingPathComponent(NULL, xulurl,
|
|
|
|
CFSTR("libxpcom.dylib"),
|
|
|
|
PR_FALSE);
|
|
|
|
|
|
|
|
if (xpcomurl) {
|
2005-07-26 02:16:56 +04:00
|
|
|
char tbuffer[MAXPATHLEN];
|
|
|
|
|
|
|
|
if (CFURLGetFileSystemRepresentation(xpcomurl, PR_TRUE,
|
|
|
|
(UInt8*) tbuffer,
|
|
|
|
sizeof(tbuffer)) &&
|
2006-03-02 18:23:17 +03:00
|
|
|
access(tbuffer, R_OK | X_OK) == 0) {
|
|
|
|
if (!realpath(tbuffer, aBuffer)) {
|
|
|
|
aBuffer[0] = '\0';
|
|
|
|
}
|
2005-07-26 02:16:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
CFRelease(xpcomurl);
|
2005-06-23 20:55:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
CFRelease(xulurl);
|
|
|
|
}
|
|
|
|
|
2005-07-26 02:16:56 +04:00
|
|
|
CFRelease(absfwurl);
|
2005-06-23 20:55:52 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aBuffer[0])
|
|
|
|
return NS_OK;
|
|
|
|
|
2005-10-09 22:20:03 +04:00
|
|
|
// Check ~/Library/Frameworks/XUL.framework/Versions/<version>/libxpcom.dylib
|
2005-07-01 16:24:07 +04:00
|
|
|
const char *home = getenv("HOME");
|
2005-09-01 16:33:47 +04:00
|
|
|
if (home && *home && GRE_FindGREFramework(home,
|
|
|
|
versions, versionsLength,
|
2008-03-22 07:25:34 +03:00
|
|
|
allProperties, allPropertiesLength,
|
2005-09-01 16:33:47 +04:00
|
|
|
aBuffer, aBufLen)) {
|
2005-06-23 20:55:52 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-10-09 22:20:03 +04:00
|
|
|
// Check /Library/Frameworks/XUL.framework/Versions/<version>/libxpcom.dylib
|
2005-09-01 16:33:47 +04:00
|
|
|
if (GRE_FindGREFramework("",
|
|
|
|
versions, versionsLength,
|
2008-03-22 07:25:34 +03:00
|
|
|
allProperties, allPropertiesLength,
|
2005-09-01 16:33:47 +04:00
|
|
|
aBuffer, aBufLen)) {
|
2005-06-23 20:55:52 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-07-01 16:24:07 +04:00
|
|
|
#elif defined(XP_UNIX)
|
|
|
|
env = getenv("MOZ_GRE_CONF");
|
2005-09-01 16:33:47 +04:00
|
|
|
if (env && GRE_GetPathFromConfigFile(env,
|
|
|
|
versions, versionsLength,
|
2008-03-22 07:25:34 +03:00
|
|
|
allProperties, allPropertiesLength,
|
2005-09-01 16:33:47 +04:00
|
|
|
aBuffer, aBufLen)) {
|
2005-06-10 23:21:27 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-07-01 16:24:07 +04:00
|
|
|
env = getenv("HOME");
|
2005-06-10 23:21:27 +04:00
|
|
|
if (env && *env) {
|
|
|
|
char buffer[MAXPATHLEN];
|
|
|
|
|
2005-06-16 17:29:45 +04:00
|
|
|
// Look in ~/.gre.config
|
|
|
|
|
|
|
|
snprintf(buffer, sizeof(buffer),
|
|
|
|
"%s" XPCOM_FILE_PATH_SEPARATOR GRE_CONF_NAME, env);
|
2005-06-10 23:21:27 +04:00
|
|
|
|
2005-09-01 16:33:47 +04:00
|
|
|
if (GRE_GetPathFromConfigFile(buffer,
|
|
|
|
versions, versionsLength,
|
2008-03-22 07:25:34 +03:00
|
|
|
allProperties, allPropertiesLength,
|
2005-09-01 16:33:47 +04:00
|
|
|
aBuffer, aBufLen)) {
|
2005-06-10 23:21:27 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2005-06-16 17:29:45 +04:00
|
|
|
|
|
|
|
// Look in ~/.gre.d/*.conf
|
|
|
|
|
|
|
|
snprintf(buffer, sizeof(buffer),
|
|
|
|
"%s" XPCOM_FILE_PATH_SEPARATOR GRE_USER_CONF_DIR, env);
|
|
|
|
|
2005-09-01 16:33:47 +04:00
|
|
|
if (GRE_GetPathFromConfigDir(buffer,
|
|
|
|
versions, versionsLength,
|
2008-03-22 07:25:34 +03:00
|
|
|
allProperties, allPropertiesLength,
|
2005-09-01 16:33:47 +04:00
|
|
|
aBuffer, aBufLen)) {
|
2005-06-16 17:29:45 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2005-06-10 23:21:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Look for a global /etc/gre.conf file
|
2005-09-01 16:33:47 +04:00
|
|
|
if (GRE_GetPathFromConfigFile(GRE_CONF_PATH,
|
|
|
|
versions, versionsLength,
|
2008-03-22 07:25:34 +03:00
|
|
|
allProperties, allPropertiesLength,
|
2005-09-01 16:33:47 +04:00
|
|
|
aBuffer, aBufLen)) {
|
2005-06-10 23:21:27 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Look for a group of config files in /etc/gre.d/
|
2005-09-01 16:33:47 +04:00
|
|
|
if (GRE_GetPathFromConfigDir(GRE_CONF_DIR,
|
|
|
|
versions, versionsLength,
|
2008-03-22 07:25:34 +03:00
|
|
|
allProperties, allPropertiesLength,
|
2005-09-01 16:33:47 +04:00
|
|
|
aBuffer, aBufLen)) {
|
2005-06-10 23:21:27 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-09-27 20:07:06 +04:00
|
|
|
#elif defined(XP_BEOS)
|
|
|
|
env = getenv("MOZ_GRE_CONF");
|
|
|
|
if (env && GRE_GetPathFromConfigFile(env,
|
|
|
|
versions, versionsLength,
|
2008-03-22 07:25:34 +03:00
|
|
|
allProperties, allPropertiesLength,
|
2006-09-27 20:07:06 +04:00
|
|
|
aBuffer, aBufLen)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
char p[MAXPATHLEN];
|
|
|
|
if (find_directory(B_USER_SETTINGS_DIRECTORY, 0, 0, p, MAXPATHLEN)) {
|
|
|
|
char buffer[MAXPATHLEN];
|
|
|
|
|
|
|
|
// Look in B_USER_SETTINGS_DIRECTORY/gre.config
|
|
|
|
snprintf(buffer, sizeof(buffer),
|
|
|
|
"%s" XPCOM_FILE_PATH_SEPARATOR GRE_CONF_NAME, p);
|
|
|
|
|
|
|
|
if (GRE_GetPathFromConfigFile(buffer,
|
|
|
|
versions, versionsLength,
|
2008-03-22 07:25:34 +03:00
|
|
|
allProperties, allPropertiesLength,
|
2006-09-27 20:07:06 +04:00
|
|
|
aBuffer, aBufLen)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Look in B_USER_SETTINGS_DIRECTORY/gre.d/*.conf
|
|
|
|
snprintf(buffer, sizeof(buffer),
|
|
|
|
"%s" XPCOM_FILE_PATH_SEPARATOR GRE_CONF_DIR, p);
|
|
|
|
|
|
|
|
if (GRE_GetPathFromConfigDir(buffer,
|
|
|
|
versions, versionsLength,
|
2008-03-22 07:25:34 +03:00
|
|
|
allProperties, allPropertiesLength,
|
2006-09-27 20:07:06 +04:00
|
|
|
aBuffer, aBufLen)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Hope Zeta OS and Haiku OS multiuser versions will respect BeBook,
|
|
|
|
// for BeOS R5 COMMON and USER are equal
|
|
|
|
if (find_directory(B_COMMON_SETTINGS_DIRECTORY, 0, 0, p, MAXPATHLEN)) {
|
|
|
|
char buffer[MAXPATHLEN];
|
|
|
|
|
|
|
|
// Look for a B_COMMON_SETTINGS_DIRECTORY/gre.conf file
|
|
|
|
snprintf(buffer, sizeof(buffer),
|
|
|
|
"%s" XPCOM_FILE_PATH_SEPARATOR GRE_CONF_PATH, p);
|
|
|
|
if (GRE_GetPathFromConfigFile(buffer,
|
|
|
|
versions, versionsLength,
|
2008-03-22 07:25:34 +03:00
|
|
|
allProperties, allPropertiesLength,
|
2006-09-27 20:07:06 +04:00
|
|
|
aBuffer, aBufLen)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Look for a group of config files in B_COMMON_SETTINGS_DIRECTORY/gre.d/
|
|
|
|
snprintf(buffer, sizeof(buffer),
|
|
|
|
"%s" XPCOM_FILE_PATH_SEPARATOR GRE_CONF_DIR, p);
|
|
|
|
if (GRE_GetPathFromConfigDir(buffer,
|
|
|
|
versions, versionsLength,
|
2008-03-22 07:25:34 +03:00
|
|
|
allProperties, allPropertiesLength,
|
2006-09-27 20:07:06 +04:00
|
|
|
aBuffer, aBufLen)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-23 20:55:52 +04:00
|
|
|
#elif defined(XP_WIN)
|
2005-06-10 23:21:27 +04:00
|
|
|
HKEY hRegKey = NULL;
|
|
|
|
|
|
|
|
// A couple of key points here:
|
2005-11-21 22:40:46 +03:00
|
|
|
// 1. Note the usage of the "Software\\mozilla.org\\GRE" subkey - this allows
|
2005-06-10 23:21:27 +04:00
|
|
|
// us to have multiple versions of GREs on the same machine by having
|
|
|
|
// subkeys such as 1.0, 1.1, 2.0 etc. under it.
|
|
|
|
// 2. In this sample below we're looking for the location of GRE version 1.2
|
|
|
|
// i.e. we're compatible with GRE 1.2 and we're trying to find it's install
|
|
|
|
// location.
|
|
|
|
//
|
|
|
|
// Please see http://www.mozilla.org/projects/embedding/GRE.html for
|
|
|
|
// more info.
|
|
|
|
//
|
2008-12-03 16:41:12 +03:00
|
|
|
if (::RegOpenKeyExW(HKEY_CURRENT_USER, GRE_WIN_REG_LOC, 0,
|
|
|
|
KEY_READ, &hRegKey) == ERROR_SUCCESS) {
|
|
|
|
PRBool ok = GRE_GetPathFromRegKey(hRegKey,
|
|
|
|
versions, versionsLength,
|
|
|
|
allProperties, allPropertiesLength,
|
2009-05-21 01:00:45 +04:00
|
|
|
aBuffer, aBufLen);
|
2008-12-03 16:41:12 +03:00
|
|
|
::RegCloseKey(hRegKey);
|
|
|
|
|
|
|
|
if (ok)
|
|
|
|
return NS_OK;
|
2005-06-10 23:21:27 +04:00
|
|
|
}
|
|
|
|
|
2008-12-03 16:41:12 +03:00
|
|
|
if (::RegOpenKeyExW(HKEY_LOCAL_MACHINE, GRE_WIN_REG_LOC, 0,
|
|
|
|
KEY_ENUMERATE_SUB_KEYS, &hRegKey) == ERROR_SUCCESS) {
|
|
|
|
PRBool ok = GRE_GetPathFromRegKey(hRegKey,
|
|
|
|
versions, versionsLength,
|
|
|
|
allProperties, allPropertiesLength,
|
2009-05-21 01:00:45 +04:00
|
|
|
aBuffer, aBufLen);
|
2008-12-03 16:41:12 +03:00
|
|
|
::RegCloseKey(hRegKey);
|
2005-06-10 23:21:27 +04:00
|
|
|
|
2008-12-03 16:41:12 +03:00
|
|
|
if (ok)
|
|
|
|
return NS_OK;
|
2005-06-10 23:21:27 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2005-09-01 16:33:47 +04:00
|
|
|
static PRBool
|
|
|
|
CheckVersion(const char* toCheck,
|
|
|
|
const GREVersionRange *versions,
|
|
|
|
PRUint32 versionsLength)
|
|
|
|
{
|
|
|
|
|
|
|
|
for (const GREVersionRange *versionsEnd = versions + versionsLength;
|
|
|
|
versions < versionsEnd;
|
|
|
|
++versions) {
|
|
|
|
PRInt32 c = NS_CompareVersions(toCheck, versions->lower);
|
|
|
|
if (c < 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!c && !versions->lowerInclusive)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
c = NS_CompareVersions(toCheck, versions->upper);
|
|
|
|
if (c > 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!c && !versions->upperInclusive)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2008-12-03 16:41:12 +03:00
|
|
|
#ifdef XP_WIN
|
2009-05-21 01:00:45 +04:00
|
|
|
|
|
|
|
// Allocate an array of characters using new[], converting from UTF8 to UTF-16.
|
|
|
|
// @note Use nsAutoArrayPtr for this result.
|
|
|
|
|
|
|
|
static PRUnichar*
|
|
|
|
ConvertUTF8toNewUTF16(const char *cstr)
|
|
|
|
{
|
|
|
|
int len = MultiByteToWideChar(CP_UTF8, 0, cstr, -1, NULL, 0);
|
|
|
|
WCHAR *wstr = new WCHAR[len];
|
|
|
|
MultiByteToWideChar(CP_UTF8, 0, cstr, -1, wstr, len);
|
|
|
|
return wstr;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef nsAutoArrayPtr<PRUnichar> AutoWString;
|
|
|
|
|
2008-12-03 16:41:12 +03:00
|
|
|
static PRBool
|
|
|
|
CheckVersion(const PRUnichar* toCheck,
|
|
|
|
const GREVersionRange *versions,
|
|
|
|
PRUint32 versionsLength)
|
|
|
|
{
|
|
|
|
for (const GREVersionRange *versionsEnd = versions + versionsLength;
|
|
|
|
versions < versionsEnd;
|
|
|
|
++versions) {
|
2009-05-21 01:00:45 +04:00
|
|
|
AutoWString wlower(ConvertUTF8toNewUTF16(versions->lower));
|
|
|
|
PRInt32 c = NS_CompareVersions(toCheck, wlower);
|
2008-12-03 16:41:12 +03:00
|
|
|
if (c < 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!c && !versions->lowerInclusive)
|
|
|
|
continue;
|
|
|
|
|
2009-05-21 01:00:45 +04:00
|
|
|
AutoWString wupper(ConvertUTF8toNewUTF16(versions->upper));
|
|
|
|
c = NS_CompareVersions(toCheck, wupper);
|
2008-12-03 16:41:12 +03:00
|
|
|
if (c > 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!c && !versions->upperInclusive)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2005-06-23 20:55:52 +04:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
PRBool
|
2005-09-01 16:33:47 +04:00
|
|
|
GRE_FindGREFramework(const char* rootPath,
|
|
|
|
const GREVersionRange *versions,
|
|
|
|
PRUint32 versionsLength,
|
|
|
|
const GREProperty *properties,
|
|
|
|
PRUint32 propertiesLength,
|
2005-06-23 20:55:52 +04:00
|
|
|
char* buffer, PRUint32 buflen)
|
|
|
|
{
|
2005-09-01 16:33:47 +04:00
|
|
|
PRBool found = PR_FALSE;
|
|
|
|
|
2005-06-23 20:55:52 +04:00
|
|
|
snprintf(buffer, buflen,
|
2005-09-01 16:33:47 +04:00
|
|
|
"%s/Library/Frameworks/" GRE_FRAMEWORK_NAME "/Versions", rootPath);
|
|
|
|
DIR *dir = opendir(buffer);
|
|
|
|
if (dir) {
|
|
|
|
struct dirent *entry;
|
|
|
|
while (!found && (entry = readdir(dir))) {
|
|
|
|
if (CheckVersion(entry->d_name, versions, versionsLength)) {
|
|
|
|
snprintf(buffer, buflen,
|
|
|
|
"%s/Library/Frameworks/" GRE_FRAMEWORK_NAME
|
|
|
|
"/Versions/%s/" XPCOM_DLL, rootPath, entry->d_name);
|
|
|
|
if (access(buffer, R_OK | X_OK) == 0)
|
|
|
|
found = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
2005-06-23 20:55:52 +04:00
|
|
|
|
2005-09-01 16:33:47 +04:00
|
|
|
closedir(dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (found)
|
2005-06-23 20:55:52 +04:00
|
|
|
return PR_TRUE;
|
|
|
|
|
|
|
|
buffer[0] = '\0';
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2006-09-27 20:07:06 +04:00
|
|
|
#elif defined(XP_UNIX) || defined(XP_BEOS)
|
2005-06-23 20:55:52 +04:00
|
|
|
|
2005-07-01 16:24:07 +04:00
|
|
|
static PRBool IsConfFile(const char *filename)
|
|
|
|
{
|
|
|
|
const char *dot = strrchr(filename, '.');
|
|
|
|
|
|
|
|
return (dot && strcmp(dot, ".conf") == 0);
|
|
|
|
}
|
|
|
|
|
2005-06-10 23:21:27 +04:00
|
|
|
PRBool
|
2005-09-01 16:33:47 +04:00
|
|
|
GRE_GetPathFromConfigDir(const char* dirname,
|
|
|
|
const GREVersionRange *versions,
|
|
|
|
PRUint32 versionsLength,
|
|
|
|
const GREProperty *properties,
|
|
|
|
PRUint32 propertiesLength,
|
2005-06-10 23:21:27 +04:00
|
|
|
char* buffer, PRUint32 buflen)
|
|
|
|
{
|
|
|
|
// Open the directory provided and try to read any files in that
|
|
|
|
// directory that end with .conf. We look for an entry that might
|
|
|
|
// point to the GRE that we're interested in.
|
2005-07-01 16:24:07 +04:00
|
|
|
DIR *dir = opendir(dirname);
|
2005-06-10 23:21:27 +04:00
|
|
|
if (!dir)
|
|
|
|
return nsnull;
|
|
|
|
|
|
|
|
PRBool found = PR_FALSE;
|
2005-07-01 16:24:07 +04:00
|
|
|
struct dirent *entry;
|
2005-06-10 23:21:27 +04:00
|
|
|
|
2005-07-01 16:24:07 +04:00
|
|
|
while (!found && (entry = readdir(dir))) {
|
2005-06-10 23:21:27 +04:00
|
|
|
|
|
|
|
// Only look for files that end in .conf
|
2005-07-01 16:24:07 +04:00
|
|
|
// IsConfFile will skip "." and ".."
|
|
|
|
if (!IsConfFile(entry->d_name))
|
2005-06-10 23:21:27 +04:00
|
|
|
continue;
|
|
|
|
|
|
|
|
char fullPath[MAXPATHLEN];
|
2005-06-16 17:29:45 +04:00
|
|
|
snprintf(fullPath, sizeof(fullPath), "%s" XPCOM_FILE_PATH_SEPARATOR "%s",
|
2005-07-01 16:24:07 +04:00
|
|
|
dirname, entry->d_name);
|
2005-06-10 23:21:27 +04:00
|
|
|
|
2005-09-01 16:33:47 +04:00
|
|
|
found = GRE_GetPathFromConfigFile(fullPath,
|
|
|
|
versions, versionsLength,
|
|
|
|
properties, propertiesLength,
|
|
|
|
buffer, buflen);
|
2005-06-10 23:21:27 +04:00
|
|
|
}
|
|
|
|
|
2005-07-01 16:24:07 +04:00
|
|
|
closedir(dir);
|
2005-06-10 23:21:27 +04:00
|
|
|
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define READ_BUFFER_SIZE 1024
|
|
|
|
|
2005-09-01 16:33:47 +04:00
|
|
|
struct INIClosure
|
2005-06-10 23:21:27 +04:00
|
|
|
{
|
2005-10-11 19:08:23 +04:00
|
|
|
nsINIParser *parser;
|
2005-09-01 16:33:47 +04:00
|
|
|
const GREVersionRange *versions;
|
|
|
|
PRUint32 versionsLength;
|
|
|
|
const GREProperty *properties;
|
|
|
|
PRUint32 propertiesLength;
|
|
|
|
char *pathBuffer;
|
|
|
|
PRUint32 buflen;
|
|
|
|
PRBool found;
|
|
|
|
};
|
2005-06-16 17:29:45 +04:00
|
|
|
|
2005-09-01 16:33:47 +04:00
|
|
|
static PRBool
|
|
|
|
CheckINIHeader(const char *aHeader, void *aClosure)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
2005-06-10 23:21:27 +04:00
|
|
|
|
2007-07-08 11:08:04 +04:00
|
|
|
INIClosure *c = reinterpret_cast<INIClosure *>(aClosure);
|
2005-06-10 23:21:27 +04:00
|
|
|
|
2005-09-01 16:33:47 +04:00
|
|
|
if (!CheckVersion(aHeader, c->versions, c->versionsLength))
|
|
|
|
return PR_TRUE;
|
2005-06-10 23:21:27 +04:00
|
|
|
|
2005-09-01 16:33:47 +04:00
|
|
|
const GREProperty *properties = c->properties;
|
|
|
|
const GREProperty *endProperties = properties + c->propertiesLength;
|
|
|
|
for (; properties < endProperties; ++properties) {
|
|
|
|
char buffer[MAXPATHLEN];
|
2005-10-11 19:08:23 +04:00
|
|
|
rv = c->parser->GetString(aHeader, properties->property,
|
2005-09-01 16:33:47 +04:00
|
|
|
buffer, sizeof(buffer));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return PR_TRUE;
|
2005-06-10 23:21:27 +04:00
|
|
|
|
2005-09-01 16:33:47 +04:00
|
|
|
if (strcmp(buffer, properties->value))
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
2005-06-16 17:29:45 +04:00
|
|
|
|
2005-10-11 19:08:23 +04:00
|
|
|
rv = c->parser->GetString(aHeader, "GRE_PATH", c->pathBuffer, c->buflen);
|
2005-09-01 16:33:47 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return PR_TRUE;
|
2005-06-10 23:21:27 +04:00
|
|
|
|
2005-09-15 21:49:51 +04:00
|
|
|
if (!safe_strncat(c->pathBuffer, "/" XPCOM_DLL, c->buflen) ||
|
|
|
|
access(c->pathBuffer, R_OK))
|
|
|
|
return PR_TRUE;
|
|
|
|
|
2005-09-01 16:33:47 +04:00
|
|
|
// We found a good GRE! Stop looking.
|
|
|
|
c->found = PR_TRUE;
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
GRE_GetPathFromConfigFile(const char* filename,
|
|
|
|
const GREVersionRange *versions,
|
|
|
|
PRUint32 versionsLength,
|
|
|
|
const GREProperty *properties,
|
|
|
|
PRUint32 propertiesLength,
|
|
|
|
char* pathBuffer, PRUint32 buflen)
|
|
|
|
{
|
|
|
|
nsINIParser parser;
|
|
|
|
nsresult rv = parser.Init(filename);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
INIClosure c = {
|
2005-10-11 19:08:23 +04:00
|
|
|
&parser,
|
2005-09-01 16:33:47 +04:00
|
|
|
versions, versionsLength,
|
|
|
|
properties, propertiesLength,
|
|
|
|
pathBuffer, buflen,
|
|
|
|
PR_FALSE
|
|
|
|
};
|
|
|
|
|
|
|
|
parser.GetSections(CheckINIHeader, &c);
|
|
|
|
return c.found;
|
2005-06-10 23:21:27 +04:00
|
|
|
}
|
|
|
|
|
2005-06-23 20:55:52 +04:00
|
|
|
#elif defined(XP_WIN)
|
|
|
|
|
2005-06-10 23:21:27 +04:00
|
|
|
static PRBool
|
2008-12-03 16:41:12 +03:00
|
|
|
CopyWithEnvExpansion(PRUnichar* aDest, const PRUnichar* aSource, PRUint32 aBufLen,
|
2005-06-10 23:21:27 +04:00
|
|
|
DWORD aType)
|
|
|
|
{
|
|
|
|
switch (aType) {
|
|
|
|
case REG_SZ:
|
2008-12-03 16:41:12 +03:00
|
|
|
if (wcslen(aSource) >= aBufLen)
|
2005-06-10 23:21:27 +04:00
|
|
|
return PR_FALSE;
|
|
|
|
|
2008-12-03 16:41:12 +03:00
|
|
|
wcscpy(aDest, aSource);
|
2005-06-10 23:21:27 +04:00
|
|
|
return PR_TRUE;
|
|
|
|
|
|
|
|
case REG_EXPAND_SZ:
|
2008-12-03 16:41:12 +03:00
|
|
|
if (ExpandEnvironmentStringsW(aSource, aDest, aBufLen) > aBufLen)
|
2005-06-10 23:21:27 +04:00
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Whoops! We expected REG_SZ or REG_EXPAND_SZ, what happened here?
|
|
|
|
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
2005-09-01 16:33:47 +04:00
|
|
|
GRE_GetPathFromRegKey(HKEY aRegKey,
|
|
|
|
const GREVersionRange *versions,
|
|
|
|
PRUint32 versionsLength,
|
|
|
|
const GREProperty *properties,
|
|
|
|
PRUint32 propertiesLength,
|
2009-05-21 01:00:45 +04:00
|
|
|
char* aBuffer, PRUint32 aBufLen)
|
2005-06-10 23:21:27 +04:00
|
|
|
{
|
2005-11-21 22:40:46 +03:00
|
|
|
// Formerly, GREs were registered at the registry key
|
|
|
|
// HKLM/Software/mozilla.org/GRE/<version> valuepair GreHome=Path.
|
|
|
|
// Nowadays, they are registered in any subkey of
|
|
|
|
// Software/mozilla.org/GRE, with the following valuepairs:
|
2005-06-10 23:21:27 +04:00
|
|
|
// Version=<version> (REG_SZ)
|
|
|
|
// GreHome=<path> (REG_SZ or REG_EXPAND_SZ)
|
2005-09-01 16:33:47 +04:00
|
|
|
// <Property>=<value> (REG_SZ)
|
2005-06-10 23:21:27 +04:00
|
|
|
//
|
|
|
|
// Additional meta-info may be available in the future, including
|
2008-03-22 07:25:34 +03:00
|
|
|
// localization info and other information which might be pertinent
|
2005-06-10 23:21:27 +04:00
|
|
|
// to selecting one GRE over another.
|
|
|
|
//
|
|
|
|
// When a GRE is being registered, it should try to register itself at
|
2005-11-21 22:40:46 +03:00
|
|
|
// HKLM/Software/mozilla.org/GRE/<Version> first, to preserve compatibility
|
2005-06-10 23:21:27 +04:00
|
|
|
// with older glue. If this key is already taken (i.e. there is more than
|
|
|
|
// one GRE of that version installed), it should append a unique number to
|
|
|
|
// the version, for example:
|
|
|
|
// 1.1 (already in use), 1.1_1, 1.1_2, etc...
|
|
|
|
|
|
|
|
DWORD i = 0;
|
2009-05-21 01:00:45 +04:00
|
|
|
PRUnichar buffer[MAXPATHLEN + 1];
|
2005-06-10 23:21:27 +04:00
|
|
|
|
|
|
|
while (PR_TRUE) {
|
2008-12-03 16:41:12 +03:00
|
|
|
PRUnichar name[MAXPATHLEN + 1];
|
2005-06-10 23:21:27 +04:00
|
|
|
DWORD nameLen = MAXPATHLEN;
|
2008-12-03 16:41:12 +03:00
|
|
|
if (::RegEnumKeyExW(aRegKey, i, name, &nameLen, NULL, NULL, NULL, NULL) !=
|
|
|
|
ERROR_SUCCESS) {
|
|
|
|
break;
|
2005-06-10 23:21:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
HKEY subKey = NULL;
|
2008-12-03 16:41:12 +03:00
|
|
|
if (::RegOpenKeyExW(aRegKey, name, 0, KEY_QUERY_VALUE, &subKey) !=
|
|
|
|
ERROR_SUCCESS) {
|
|
|
|
continue;
|
2005-06-10 23:21:27 +04:00
|
|
|
}
|
|
|
|
|
2008-12-03 16:41:12 +03:00
|
|
|
PRUnichar version[40];
|
2005-06-10 23:21:27 +04:00
|
|
|
DWORD versionlen = 40;
|
2009-05-21 01:00:45 +04:00
|
|
|
PRUnichar pathbuf[MAXPATHLEN + 1];
|
2005-09-01 16:33:47 +04:00
|
|
|
DWORD pathlen;
|
2005-06-10 23:21:27 +04:00
|
|
|
DWORD pathtype;
|
|
|
|
|
2005-09-01 16:33:47 +04:00
|
|
|
PRBool ok = PR_FALSE;
|
|
|
|
|
2008-12-03 16:41:12 +03:00
|
|
|
if (::RegQueryValueExW(subKey, L"Version", NULL, NULL,
|
|
|
|
(BYTE*) version, &versionlen) == ERROR_SUCCESS &&
|
|
|
|
CheckVersion(version, versions, versionsLength)) {
|
2005-09-01 16:33:47 +04:00
|
|
|
|
|
|
|
ok = PR_TRUE;
|
|
|
|
const GREProperty *props = properties;
|
|
|
|
const GREProperty *propsEnd = properties + propertiesLength;
|
|
|
|
for (; ok && props < propsEnd; ++props) {
|
2009-05-21 01:00:45 +04:00
|
|
|
pathlen = MAXPATHLEN + 1;
|
2005-12-16 17:58:57 +03:00
|
|
|
|
2009-05-21 01:00:45 +04:00
|
|
|
AutoWString wproperty(ConvertUTF8toNewUTF16(props->property));
|
|
|
|
AutoWString wvalue(ConvertUTF8toNewUTF16(props->value));
|
|
|
|
if (::RegQueryValueExW(subKey, wproperty, NULL, &pathtype,
|
2008-12-03 16:41:12 +03:00
|
|
|
(BYTE*) pathbuf, &pathlen) != ERROR_SUCCESS ||
|
2009-05-21 01:00:45 +04:00
|
|
|
wcscmp(pathbuf, wvalue))
|
2008-12-03 16:41:12 +03:00
|
|
|
ok = PR_FALSE;
|
2005-09-01 16:33:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
pathlen = sizeof(pathbuf);
|
|
|
|
if (ok &&
|
2008-12-03 16:41:12 +03:00
|
|
|
(!::RegQueryValueExW(subKey, L"GreHome", NULL, &pathtype,
|
2005-09-01 16:33:47 +04:00
|
|
|
(BYTE*) pathbuf, &pathlen) == ERROR_SUCCESS ||
|
|
|
|
!*pathbuf ||
|
2009-05-21 01:00:45 +04:00
|
|
|
!CopyWithEnvExpansion(buffer, pathbuf, MAXPATHLEN, pathtype))) {
|
2005-09-15 21:49:51 +04:00
|
|
|
ok = PR_FALSE;
|
|
|
|
}
|
2009-05-21 01:00:45 +04:00
|
|
|
else if (!wcsncat(buffer, L"\\" LXPCOM_DLL, aBufLen)
|
2008-12-03 16:42:03 +03:00
|
|
|
#ifdef WINCE
|
2009-05-21 01:00:45 +04:00
|
|
|
|| (GetFileAttributesW(buffer) != INVALID_FILE_ATTRIBUTES)
|
2008-12-03 16:42:03 +03:00
|
|
|
#else
|
2009-05-21 01:00:45 +04:00
|
|
|
|| _waccess(buffer, R_OK)
|
2008-12-03 16:42:03 +03:00
|
|
|
#endif
|
|
|
|
) {
|
2005-09-01 16:33:47 +04:00
|
|
|
ok = PR_FALSE;
|
2005-06-10 23:21:27 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RegCloseKey(subKey);
|
|
|
|
|
2009-05-21 01:00:45 +04:00
|
|
|
if (ok) {
|
|
|
|
WideCharToMultiByte(CP_UTF8, 0, buffer, -1, aBuffer, aBufLen, NULL, NULL);
|
2005-09-01 16:33:47 +04:00
|
|
|
return PR_TRUE;
|
2009-05-21 01:00:45 +04:00
|
|
|
}
|
2005-09-01 16:33:47 +04:00
|
|
|
|
2005-06-10 23:21:27 +04:00
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
2005-09-15 21:49:51 +04:00
|
|
|
aBuffer[0] = '\0';
|
|
|
|
|
2005-06-10 23:21:27 +04:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
#endif // XP_WIN
|