2005-10-26 21:17:44 +04:00
|
|
|
/* ***** 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 XULRunner.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Benjamin Smedberg <benjamin@smedbergs.us>
|
|
|
|
*
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2005
|
|
|
|
* the Mozilla Foundation <http://www.mozilla.org/>. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* 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"
|
|
|
|
#include "nsINIParser.h"
|
|
|
|
#include "prtypes.h"
|
|
|
|
#include "nsXPCOMPrivate.h" // for XP MAXPATHLEN
|
2005-12-16 17:58:57 +03:00
|
|
|
#include "nsMemory.h" // for NS_ARRAY_LENGTH
|
2006-08-17 18:22:04 +04:00
|
|
|
#include "nsXULAppAPI.h"
|
|
|
|
#include "nsILocalFile.h"
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
2005-10-26 21:17:44 +04:00
|
|
|
|
|
|
|
#ifdef XP_WIN
|
|
|
|
#include <windows.h>
|
2005-11-17 22:25:42 +03:00
|
|
|
#include <io.h>
|
2005-10-26 21:17:44 +04:00
|
|
|
#define snprintf _snprintf
|
2006-10-23 22:34:15 +04:00
|
|
|
#define vsnprintf _vsnprintf
|
2009-04-16 23:19:32 +04:00
|
|
|
#define strcasecmp _stricmp
|
2005-10-26 21:17:44 +04:00
|
|
|
#define PATH_SEPARATOR_CHAR '\\'
|
2005-11-17 22:25:42 +03:00
|
|
|
#define R_OK 04
|
2006-08-17 18:22:04 +04:00
|
|
|
#elif defined(XP_MACOSX)
|
2009-04-18 02:13:05 +04:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/stat.h>
|
2009-03-21 02:21:08 +03:00
|
|
|
#include <CoreFoundation/CoreFoundation.h>
|
2006-08-17 18:22:04 +04:00
|
|
|
#define PATH_SEPARATOR_CHAR '/'
|
2007-01-10 11:43:08 +03:00
|
|
|
#elif defined (XP_OS2)
|
|
|
|
#define INCL_DOS
|
|
|
|
#define INCL_DOSMISC
|
|
|
|
#define INCL_DOSERRORS
|
|
|
|
#include <os2.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#define PATH_SEPARATOR_CHAR '\\'
|
2005-10-26 21:17:44 +04:00
|
|
|
#else
|
2006-08-26 00:33:34 +04:00
|
|
|
#include <unistd.h>
|
2005-10-26 21:17:44 +04:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#define PATH_SEPARATOR_CHAR '/'
|
|
|
|
#endif
|
|
|
|
|
2007-12-31 18:15:43 +03:00
|
|
|
#ifdef XP_WIN
|
|
|
|
#include "nsWindowsWMain.cpp"
|
|
|
|
#endif
|
|
|
|
|
2008-04-09 10:49:41 +04:00
|
|
|
#ifdef XP_BEOS
|
|
|
|
#include <Entry.h>
|
|
|
|
#include <Path.h>
|
|
|
|
#endif
|
|
|
|
|
2005-10-26 21:17:44 +04:00
|
|
|
#define VERSION_MAXLEN 128
|
|
|
|
|
2006-08-17 18:22:04 +04:00
|
|
|
static void Output(PRBool isError, const char *fmt, ... )
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
|
|
|
|
2008-10-01 01:34:55 +04:00
|
|
|
#if (defined(XP_WIN) && !MOZ_WINCONSOLE) || defined(WINCE)
|
2006-08-17 18:22:04 +04:00
|
|
|
char msg[2048];
|
|
|
|
|
|
|
|
vsnprintf(msg, sizeof(msg), fmt, ap);
|
|
|
|
|
|
|
|
UINT flags = MB_OK;
|
|
|
|
if (isError)
|
|
|
|
flags |= MB_ICONERROR;
|
2007-11-29 20:20:54 +03:00
|
|
|
else
|
2006-08-17 18:22:04 +04:00
|
|
|
flags |= MB_ICONINFORMATION;
|
2008-10-01 01:34:55 +04:00
|
|
|
|
|
|
|
wchar_t wide_msg[1024];
|
|
|
|
MultiByteToWideChar(CP_ACP,
|
|
|
|
0,
|
|
|
|
msg,
|
|
|
|
-1,
|
|
|
|
wide_msg,
|
|
|
|
sizeof(wide_msg) / sizeof(wchar_t));
|
|
|
|
|
|
|
|
MessageBoxW(NULL, wide_msg, L"XULRunner", flags);
|
2006-08-17 18:22:04 +04:00
|
|
|
#else
|
|
|
|
vfprintf(stderr, fmt, ap);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
2009-04-16 23:19:32 +04:00
|
|
|
/**
|
|
|
|
* Return true if |arg| matches the given argument name.
|
|
|
|
*/
|
|
|
|
static PRBool IsArg(const char* arg, const char* s)
|
|
|
|
{
|
|
|
|
if (*arg == '-')
|
|
|
|
{
|
|
|
|
if (*++arg == '-')
|
|
|
|
++arg;
|
|
|
|
return !strcasecmp(arg, s);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(XP_WIN) || defined(XP_OS2)
|
|
|
|
if (*arg == '/')
|
|
|
|
return !strcasecmp(++arg, s);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return true if |aDir| is a valid file/directory.
|
|
|
|
*/
|
|
|
|
static PRBool FolderExists(const char* aDir)
|
|
|
|
{
|
|
|
|
#ifdef XP_WIN
|
|
|
|
wchar_t wideDir[MAX_PATH];
|
|
|
|
MultiByteToWideChar(CP_UTF8, 0, aDir, -1, wideDir, MAX_PATH);
|
|
|
|
DWORD fileAttrs = GetFileAttributesW(wideDir);
|
|
|
|
return fileAttrs != INVALID_FILE_ATTRIBUTES;
|
|
|
|
#else
|
|
|
|
return access(aDir, R_OK) == 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static nsresult GetRealPath(const char* appDataFile, char* *aResult)
|
|
|
|
{
|
|
|
|
#ifdef XP_WIN
|
|
|
|
wchar_t wAppDataFile[MAX_PATH];
|
|
|
|
wchar_t wIniPath[MAX_PATH];
|
|
|
|
MultiByteToWideChar(CP_UTF8, 0, appDataFile, -1, wAppDataFile, MAX_PATH);
|
|
|
|
_wfullpath(wIniPath, wAppDataFile, MAX_PATH);
|
|
|
|
WideCharToMultiByte(CP_UTF8, 0, wIniPath, -1, *aResult, MAX_PATH, 0, 0);
|
|
|
|
#else
|
|
|
|
struct stat fileStat;
|
|
|
|
if (!realpath(appDataFile, *aResult) || stat(*aResult, &fileStat))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
#endif
|
|
|
|
if (!*aResult || !**aResult)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-08-17 18:22:04 +04:00
|
|
|
class AutoAppData
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
AutoAppData(nsILocalFile* aINIFile) : mAppData(nsnull) {
|
|
|
|
nsresult rv = XRE_CreateAppData(aINIFile, &mAppData);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
mAppData = nsnull;
|
|
|
|
}
|
|
|
|
~AutoAppData() {
|
|
|
|
if (mAppData)
|
|
|
|
XRE_FreeAppData(mAppData);
|
|
|
|
}
|
|
|
|
|
|
|
|
operator nsXREAppData*() const { return mAppData; }
|
|
|
|
nsXREAppData* operator -> () const { return mAppData; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsXREAppData* mAppData;
|
|
|
|
};
|
|
|
|
|
|
|
|
XRE_CreateAppDataType XRE_CreateAppData;
|
|
|
|
XRE_FreeAppDataType XRE_FreeAppData;
|
|
|
|
XRE_mainType XRE_main;
|
|
|
|
|
2005-10-26 21:17:44 +04:00
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
char *lastSlash;
|
|
|
|
|
|
|
|
char iniPath[MAXPATHLEN];
|
2006-02-02 20:23:26 +03:00
|
|
|
char tmpPath[MAXPATHLEN];
|
2006-08-17 18:22:04 +04:00
|
|
|
char greDir[MAXPATHLEN];
|
|
|
|
PRBool greFound = PR_FALSE;
|
|
|
|
|
|
|
|
#if defined(XP_MACOSX)
|
|
|
|
CFBundleRef appBundle = CFBundleGetMainBundle();
|
|
|
|
if (!appBundle)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(appBundle);
|
|
|
|
if (!resourcesURL)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
CFURLRef absResourcesURL = CFURLCopyAbsoluteURL(resourcesURL);
|
|
|
|
CFRelease(resourcesURL);
|
|
|
|
if (!absResourcesURL)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
CFURLRef iniFileURL =
|
|
|
|
CFURLCreateCopyAppendingPathComponent(kCFAllocatorDefault,
|
|
|
|
absResourcesURL,
|
|
|
|
CFSTR("application.ini"),
|
|
|
|
false);
|
|
|
|
CFRelease(absResourcesURL);
|
|
|
|
if (!iniFileURL)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
CFStringRef iniPathStr =
|
|
|
|
CFURLCopyFileSystemPath(iniFileURL, kCFURLPOSIXPathStyle);
|
|
|
|
CFRelease(iniFileURL);
|
|
|
|
if (!iniPathStr)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
CFStringGetCString(iniPathStr, iniPath, sizeof(iniPath),
|
|
|
|
kCFStringEncodingUTF8);
|
|
|
|
CFRelease(iniPathStr);
|
|
|
|
|
|
|
|
#else
|
2005-10-26 21:17:44 +04:00
|
|
|
|
|
|
|
#ifdef XP_WIN
|
2008-10-01 01:34:55 +04:00
|
|
|
wchar_t wide_path[MAX_PATH];
|
|
|
|
if (!::GetModuleFileNameW(NULL, wide_path, MAX_PATH))
|
2005-10-26 21:17:44 +04:00
|
|
|
return 1;
|
|
|
|
|
2009-04-16 23:19:32 +04:00
|
|
|
WideCharToMultiByte(CP_UTF8, 0, wide_path,-1,
|
2008-10-14 19:28:43 +04:00
|
|
|
iniPath, MAX_PATH, NULL, NULL);
|
|
|
|
|
2007-01-10 11:43:08 +03:00
|
|
|
#elif defined(XP_OS2)
|
|
|
|
PPIB ppib;
|
|
|
|
PTIB ptib;
|
2007-11-29 20:20:54 +03:00
|
|
|
|
2007-01-10 11:43:08 +03:00
|
|
|
DosGetInfoBlocks(&ptib, &ppib);
|
|
|
|
DosQueryModuleName(ppib->pib_hmte, sizeof(iniPath), iniPath);
|
|
|
|
|
2008-04-09 10:49:41 +04:00
|
|
|
#elif defined(XP_BEOS)
|
|
|
|
BEntry e((const char *)argv[0], true); // traverse symlink
|
|
|
|
BPath p;
|
|
|
|
status_t err;
|
|
|
|
err = e.GetPath(&p);
|
|
|
|
NS_ASSERTION(err == B_OK, "realpath failed");
|
|
|
|
|
|
|
|
if (err == B_OK)
|
|
|
|
// p.Path returns a pointer, so use strcpy to store path in iniPath
|
|
|
|
strcpy(iniPath, p.Path());
|
|
|
|
|
2005-10-26 21:17:44 +04:00
|
|
|
#else
|
|
|
|
// on unix, there is no official way to get the path of the current binary.
|
|
|
|
// instead of using the MOZILLA_FIVE_HOME hack, which doesn't scale to
|
|
|
|
// multiple applications, we will try a series of techniques:
|
|
|
|
//
|
|
|
|
// 1) use realpath() on argv[0], which works unless we're loaded from the
|
|
|
|
// PATH
|
|
|
|
// 2) manually walk through the PATH and look for ourself
|
|
|
|
// 3) give up
|
|
|
|
|
|
|
|
struct stat fileStat;
|
|
|
|
|
|
|
|
if (!realpath(argv[0], iniPath) || stat(iniPath, &fileStat)) {
|
|
|
|
const char *path = getenv("PATH");
|
|
|
|
if (!path)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
char *pathdup = strdup(path);
|
|
|
|
if (!pathdup)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
PRBool found = PR_FALSE;
|
|
|
|
char *token = strtok(pathdup, ":");
|
|
|
|
while (token) {
|
2006-02-02 20:23:26 +03:00
|
|
|
sprintf(tmpPath, "%s/%s", token, argv[0]);
|
|
|
|
if (realpath(tmpPath, iniPath) && stat(iniPath, &fileStat) == 0) {
|
2005-10-26 21:17:44 +04:00
|
|
|
found = PR_TRUE;
|
|
|
|
break;
|
|
|
|
}
|
2006-02-02 20:23:26 +03:00
|
|
|
token = strtok(NULL, ":");
|
2005-10-26 21:17:44 +04:00
|
|
|
}
|
|
|
|
free (pathdup);
|
|
|
|
if (!found)
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
lastSlash = strrchr(iniPath, PATH_SEPARATOR_CHAR);
|
|
|
|
if (!lastSlash)
|
|
|
|
return 1;
|
|
|
|
|
2005-11-17 22:25:42 +03:00
|
|
|
*(++lastSlash) = '\0';
|
|
|
|
|
2006-08-17 18:22:04 +04:00
|
|
|
// On Linux/Win, look for XULRunner in appdir/xulrunner
|
|
|
|
|
2005-11-17 22:25:42 +03:00
|
|
|
snprintf(greDir, sizeof(greDir),
|
|
|
|
"%sxulrunner" XPCOM_FILE_PATH_SEPARATOR XPCOM_DLL,
|
|
|
|
iniPath);
|
|
|
|
|
2009-04-16 23:19:32 +04:00
|
|
|
greFound = FolderExists(greDir);
|
|
|
|
|
2005-11-17 22:25:42 +03:00
|
|
|
strncpy(lastSlash, "application.ini", sizeof(iniPath) - (lastSlash - iniPath));
|
2005-10-26 21:17:44 +04:00
|
|
|
|
2006-08-17 18:22:04 +04:00
|
|
|
#endif
|
|
|
|
|
2009-04-16 23:19:32 +04:00
|
|
|
// If -app parameter was passed in, it is now time to take it under
|
|
|
|
// consideration.
|
|
|
|
const char *appDataFile;
|
|
|
|
appDataFile = getenv("XUL_APP_FILE");
|
|
|
|
if (!appDataFile || !*appDataFile)
|
|
|
|
if (argc > 1 && IsArg(argv[1], "app")) {
|
|
|
|
if (argc == 2) {
|
|
|
|
Output(PR_FALSE, "specify APP-FILE (optional)\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
argv[1] = argv[0];
|
|
|
|
++argv;
|
|
|
|
--argc;
|
|
|
|
|
|
|
|
appDataFile = argv[1];
|
|
|
|
argv[1] = argv[0];
|
|
|
|
++argv;
|
|
|
|
--argc;
|
|
|
|
|
|
|
|
char kAppEnv[MAXPATHLEN];
|
|
|
|
snprintf(kAppEnv, MAXPATHLEN, "XUL_APP_FILE=%s", appDataFile);
|
|
|
|
if (putenv(kAppEnv))
|
|
|
|
Output(PR_FALSE, "Couldn't set %s.\n", kAppEnv);
|
|
|
|
|
|
|
|
char *result = (char*) calloc(sizeof(char), MAXPATHLEN);
|
|
|
|
if (NS_FAILED(GetRealPath(appDataFile, &result))) {
|
|
|
|
Output(PR_TRUE, "Invalid application.ini path.\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We have a valid application.ini path passed in to the -app parameter
|
|
|
|
// but not yet a valid greDir, so lets look for it also on the same folder
|
|
|
|
// as the stub.
|
|
|
|
if (!greFound) {
|
|
|
|
lastSlash = strrchr(iniPath, PATH_SEPARATOR_CHAR);
|
|
|
|
if (!lastSlash)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
*(++lastSlash) = '\0';
|
|
|
|
|
|
|
|
snprintf(greDir, sizeof(greDir), "%s" XPCOM_DLL, iniPath);
|
|
|
|
greFound = FolderExists(greDir);
|
|
|
|
}
|
|
|
|
|
|
|
|
// copy it back.
|
|
|
|
strcpy(iniPath, result);
|
|
|
|
}
|
|
|
|
|
2005-10-26 21:17:44 +04:00
|
|
|
nsINIParser parser;
|
|
|
|
rv = parser.Init(iniPath);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
fprintf(stderr, "Could not read application.ini\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2006-08-17 18:22:04 +04:00
|
|
|
if (!greFound) {
|
2005-11-17 22:25:42 +03:00
|
|
|
char minVersion[VERSION_MAXLEN];
|
2005-10-26 21:17:44 +04:00
|
|
|
|
2005-11-17 22:25:42 +03:00
|
|
|
// If a gecko maxVersion is not specified, we assume that the app uses only
|
|
|
|
// frozen APIs, and is therefore compatible with any xulrunner 1.x.
|
2006-08-17 18:22:04 +04:00
|
|
|
char maxVersion[VERSION_MAXLEN] = "1.*";
|
2005-10-26 21:17:44 +04:00
|
|
|
|
2005-11-17 22:25:42 +03:00
|
|
|
GREVersionRange range = {
|
|
|
|
minVersion,
|
|
|
|
PR_TRUE,
|
|
|
|
maxVersion,
|
2006-08-17 18:22:04 +04:00
|
|
|
PR_TRUE
|
2005-11-17 22:25:42 +03:00
|
|
|
};
|
2005-10-26 21:17:44 +04:00
|
|
|
|
2005-11-17 22:25:42 +03:00
|
|
|
rv = parser.GetString("Gecko", "MinVersion", minVersion, sizeof(minVersion));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"The application.ini does not specify a [Gecko] MinVersion\n");
|
|
|
|
return 1;
|
|
|
|
}
|
2005-10-26 21:17:44 +04:00
|
|
|
|
2005-11-17 22:25:42 +03:00
|
|
|
rv = parser.GetString("Gecko", "MaxVersion", maxVersion, sizeof(maxVersion));
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
range.upperInclusive = PR_TRUE;
|
2005-10-26 21:17:44 +04:00
|
|
|
|
2005-12-16 17:58:57 +03:00
|
|
|
static const GREProperty kProperties[] = {
|
|
|
|
{ "xulrunner", "true" }
|
|
|
|
};
|
|
|
|
|
|
|
|
rv = GRE_GetGREPathWithProperties(&range, 1,
|
|
|
|
kProperties, NS_ARRAY_LENGTH(kProperties),
|
|
|
|
greDir, sizeof(greDir));
|
2005-11-17 22:25:42 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
// XXXbsmedberg: Do something much smarter here: notify the
|
|
|
|
// user/offer to download/?
|
2005-10-26 21:17:44 +04:00
|
|
|
|
2006-08-17 18:22:04 +04:00
|
|
|
Output(PR_FALSE,
|
2007-11-29 20:20:54 +03:00
|
|
|
"Could not find compatible GRE between version %s and %s.\n",
|
2006-08-17 18:22:04 +04:00
|
|
|
range.lower, range.upper);
|
2005-11-17 22:25:42 +03:00
|
|
|
return 1;
|
|
|
|
}
|
2005-10-26 21:17:44 +04:00
|
|
|
}
|
2007-01-10 11:43:08 +03:00
|
|
|
#ifdef XP_OS2
|
|
|
|
// On OS/2 we need to set BEGINLIBPATH to be able to find XULRunner DLLs
|
|
|
|
strcpy(tmpPath, greDir);
|
|
|
|
lastSlash = strrchr(tmpPath, PATH_SEPARATOR_CHAR);
|
|
|
|
if (lastSlash) {
|
|
|
|
*lastSlash = '\0';
|
|
|
|
}
|
|
|
|
DosSetExtLIBPATH(tmpPath, BEGIN_LIBPATH);
|
|
|
|
#endif
|
2005-10-26 21:17:44 +04:00
|
|
|
|
2006-08-17 18:22:04 +04:00
|
|
|
rv = XPCOMGlueStartup(greDir);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
Output(PR_TRUE, "Couldn't load XPCOM.\n");
|
|
|
|
return 1;
|
2005-10-26 21:17:44 +04:00
|
|
|
}
|
|
|
|
|
2006-08-17 18:22:04 +04:00
|
|
|
static const nsDynamicFunctionLoad kXULFuncs[] = {
|
|
|
|
{ "XRE_CreateAppData", (NSFuncPtr*) &XRE_CreateAppData },
|
|
|
|
{ "XRE_FreeAppData", (NSFuncPtr*) &XRE_FreeAppData },
|
|
|
|
{ "XRE_main", (NSFuncPtr*) &XRE_main },
|
|
|
|
{ nsnull, nsnull }
|
|
|
|
};
|
|
|
|
|
|
|
|
rv = XPCOMGlueLoadXULFunctions(kXULFuncs);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
Output(PR_TRUE, "Couldn't load XRE functions.\n");
|
2005-10-26 21:17:44 +04:00
|
|
|
return 1;
|
2006-08-17 18:22:04 +04:00
|
|
|
}
|
2005-10-26 21:17:44 +04:00
|
|
|
|
2006-08-17 18:22:04 +04:00
|
|
|
NS_LogInit();
|
2005-10-26 21:17:44 +04:00
|
|
|
|
2006-08-17 18:22:04 +04:00
|
|
|
int retval;
|
2005-10-26 21:17:44 +04:00
|
|
|
|
2006-08-17 18:22:04 +04:00
|
|
|
{ // Scope COMPtr and AutoAppData
|
|
|
|
nsCOMPtr<nsILocalFile> iniFile;
|
|
|
|
rv = NS_NewNativeLocalFile(nsDependentCString(iniPath), PR_FALSE,
|
|
|
|
getter_AddRefs(iniFile));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
Output(PR_TRUE, "Couldn't find application.ini file.\n");
|
|
|
|
return 1;
|
|
|
|
}
|
2005-10-26 21:17:44 +04:00
|
|
|
|
2006-08-17 18:22:04 +04:00
|
|
|
AutoAppData appData(iniFile);
|
|
|
|
if (!appData) {
|
|
|
|
Output(PR_TRUE, "Error: couldn't parse application.ini.\n");
|
|
|
|
return 1;
|
|
|
|
}
|
2005-10-26 21:17:44 +04:00
|
|
|
|
2007-08-31 02:04:08 +04:00
|
|
|
NS_ASSERTION(appData->directory, "Failed to get app directory.");
|
2006-08-17 18:22:04 +04:00
|
|
|
|
|
|
|
if (!appData->xreDirectory) {
|
|
|
|
// chop "libxul.so" off the GRE path
|
|
|
|
lastSlash = strrchr(greDir, PATH_SEPARATOR_CHAR);
|
|
|
|
if (lastSlash) {
|
|
|
|
*lastSlash = '\0';
|
|
|
|
}
|
|
|
|
NS_NewNativeLocalFile(nsDependentCString(greDir), PR_FALSE,
|
|
|
|
&appData->xreDirectory);
|
|
|
|
}
|
2005-10-26 21:17:44 +04:00
|
|
|
|
2006-08-17 18:22:04 +04:00
|
|
|
retval = XRE_main(argc, argv, appData);
|
|
|
|
}
|
2005-10-26 21:17:44 +04:00
|
|
|
|
2006-08-17 18:22:04 +04:00
|
|
|
NS_LogTerm();
|
2005-10-26 21:17:44 +04:00
|
|
|
|
2006-08-17 18:22:04 +04:00
|
|
|
XPCOMGlueShutdown();
|
2009-04-14 06:49:06 +04:00
|
|
|
|
2006-08-17 18:22:04 +04:00
|
|
|
return retval;
|
2005-10-26 21:17:44 +04:00
|
|
|
}
|