2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2005-10-26 21:17:44 +04:00
|
|
|
|
|
|
|
#include "nsXPCOMGlue.h"
|
|
|
|
#include "nsINIParser.h"
|
|
|
|
#include "nsXPCOMPrivate.h" // for XP MAXPATHLEN
|
2006-08-17 18:22:04 +04:00
|
|
|
#include "nsXULAppAPI.h"
|
2012-06-06 06:08:30 +04:00
|
|
|
#include "nsIFile.h"
|
2006-08-17 18:22:04 +04:00
|
|
|
|
|
|
|
#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 '/'
|
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
|
2010-11-15 18:19:57 +03:00
|
|
|
#define XRE_DONT_PROTECT_DLL_LOAD
|
2007-12-31 18:15:43 +03:00
|
|
|
#include "nsWindowsWMain.cpp"
|
|
|
|
#endif
|
|
|
|
|
2005-10-26 21:17:44 +04:00
|
|
|
#define VERSION_MAXLEN 128
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static void Output(bool isError, const char *fmt, ... )
|
2006-08-17 18:22:04 +04:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
|
|
|
|
2011-05-05 20:40:04 +04:00
|
|
|
#if (defined(XP_WIN) && !MOZ_WINCONSOLE)
|
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));
|
|
|
|
|
2013-10-24 00:36:09 +04:00
|
|
|
MessageBoxW(nullptr, 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.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool IsArg(const char* arg, const char* s)
|
2009-04-16 23:19:32 +04:00
|
|
|
{
|
|
|
|
if (*arg == '-')
|
|
|
|
{
|
|
|
|
if (*++arg == '-')
|
|
|
|
++arg;
|
|
|
|
return !strcasecmp(arg, s);
|
|
|
|
}
|
|
|
|
|
2014-02-11 02:57:01 +04:00
|
|
|
#if defined(XP_WIN)
|
2009-04-16 23:19:32 +04:00
|
|
|
if (*arg == '/')
|
|
|
|
return !strcasecmp(++arg, s);
|
|
|
|
#endif
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2009-04-16 23:19:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return true if |aDir| is a valid file/directory.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool FolderExists(const char* aDir)
|
2009-04-16 23:19:32 +04:00
|
|
|
{
|
|
|
|
#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:
|
2012-07-30 18:20:58 +04:00
|
|
|
AutoAppData(nsIFile* aINIFile) : mAppData(nullptr) {
|
2006-08-17 18:22:04 +04:00
|
|
|
nsresult rv = XRE_CreateAppData(aINIFile, &mAppData);
|
|
|
|
if (NS_FAILED(rv))
|
2012-07-30 18:20:58 +04:00
|
|
|
mAppData = nullptr;
|
2006-08-17 18:22:04 +04:00
|
|
|
}
|
|
|
|
~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];
|
2011-09-29 10:19:26 +04:00
|
|
|
bool greFound = false;
|
2006-08-17 18:22:04 +04:00
|
|
|
|
|
|
|
#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];
|
2013-10-24 00:36:09 +04:00
|
|
|
if (!::GetModuleFileNameW(nullptr, 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,
|
2013-10-24 00:36:09 +04:00
|
|
|
iniPath, MAX_PATH, nullptr, nullptr);
|
2008-10-14 19:28:43 +04:00
|
|
|
|
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;
|
2011-07-01 12:42:28 +04:00
|
|
|
strncpy(tmpPath, argv[0], sizeof(tmpPath));
|
|
|
|
lastSlash = strrchr(tmpPath, '/');
|
|
|
|
if (lastSlash) {
|
|
|
|
*lastSlash = 0;
|
|
|
|
realpath(tmpPath, iniPath);
|
|
|
|
} else {
|
2005-10-26 21:17:44 +04:00
|
|
|
const char *path = getenv("PATH");
|
|
|
|
if (!path)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
char *pathdup = strdup(path);
|
|
|
|
if (!pathdup)
|
|
|
|
return 1;
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool found = false;
|
2005-10-26 21:17:44 +04:00
|
|
|
char *token = strtok(pathdup, ":");
|
|
|
|
while (token) {
|
2006-02-02 20:23:26 +03:00
|
|
|
sprintf(tmpPath, "%s/%s", token, argv[0]);
|
2011-07-01 12:42:28 +04:00
|
|
|
if (stat(tmpPath, &fileStat) == 0) {
|
2011-10-17 18:59:28 +04:00
|
|
|
found = true;
|
2011-07-01 12:42:28 +04:00
|
|
|
lastSlash = strrchr(tmpPath, '/');
|
|
|
|
*lastSlash = 0;
|
|
|
|
realpath(tmpPath, iniPath);
|
2005-10-26 21:17:44 +04:00
|
|
|
break;
|
|
|
|
}
|
2013-10-24 00:36:09 +04:00
|
|
|
token = strtok(nullptr, ":");
|
2005-10-26 21:17:44 +04:00
|
|
|
}
|
|
|
|
free (pathdup);
|
|
|
|
if (!found)
|
|
|
|
return 1;
|
|
|
|
}
|
2011-07-01 12:42:28 +04:00
|
|
|
lastSlash = iniPath + strlen(iniPath);
|
|
|
|
*lastSlash = '/';
|
2005-10-26 21:17:44 +04:00
|
|
|
#endif
|
|
|
|
|
2011-07-01 12:42:28 +04:00
|
|
|
#ifndef XP_UNIX
|
2005-10-26 21:17:44 +04:00
|
|
|
lastSlash = strrchr(iniPath, PATH_SEPARATOR_CHAR);
|
|
|
|
if (!lastSlash)
|
|
|
|
return 1;
|
2011-07-01 12:42:28 +04:00
|
|
|
#endif
|
2005-10-26 21:17:44 +04:00
|
|
|
|
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);
|
|
|
|
|
2011-07-28 11:03:49 +04:00
|
|
|
#ifdef XP_UNIX
|
|
|
|
if (greFound) {
|
|
|
|
char resolved_greDir[MAXPATHLEN] = "";
|
|
|
|
if (realpath(greDir, resolved_greDir) && *resolved_greDir) {
|
|
|
|
strncpy(greDir, resolved_greDir, MAXPATHLEN);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
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) {
|
2011-10-17 18:59:28 +04:00
|
|
|
Output(false, "specify APP-FILE (optional)\n");
|
2009-04-16 23:19:32 +04:00
|
|
|
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))
|
2011-10-17 18:59:28 +04:00
|
|
|
Output(false, "Couldn't set %s.\n", kAppEnv);
|
2009-04-16 23:19:32 +04:00
|
|
|
|
|
|
|
char *result = (char*) calloc(sizeof(char), MAXPATHLEN);
|
|
|
|
if (NS_FAILED(GetRealPath(appDataFile, &result))) {
|
2011-10-17 18:59:28 +04:00
|
|
|
Output(true, "Invalid application.ini path.\n");
|
2009-04-16 23:19:32 +04:00
|
|
|
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) {
|
2011-07-02 18:47:55 +04:00
|
|
|
#ifdef XP_MACOSX
|
2013-10-25 16:11:36 +04:00
|
|
|
// Check for <bundle>/Contents/Frameworks/XUL.framework/Versions/Current/libmozglue.dylib
|
2011-07-02 18:47:55 +04:00
|
|
|
CFURLRef fwurl = CFBundleCopyPrivateFrameworksURL(appBundle);
|
2012-07-30 18:20:58 +04:00
|
|
|
CFURLRef absfwurl = nullptr;
|
2011-07-02 18:47:55 +04:00
|
|
|
if (fwurl) {
|
|
|
|
absfwurl = CFURLCopyAbsoluteURL(fwurl);
|
|
|
|
CFRelease(fwurl);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (absfwurl) {
|
|
|
|
CFURLRef xulurl =
|
2013-10-24 00:36:09 +04:00
|
|
|
CFURLCreateCopyAppendingPathComponent(nullptr, absfwurl,
|
2013-10-25 16:11:36 +04:00
|
|
|
CFSTR("XUL.framework/Versions/Current"),
|
2011-10-17 18:59:28 +04:00
|
|
|
true);
|
2011-07-02 18:47:55 +04:00
|
|
|
|
|
|
|
if (xulurl) {
|
|
|
|
CFURLRef xpcomurl =
|
2013-10-24 00:36:09 +04:00
|
|
|
CFURLCreateCopyAppendingPathComponent(nullptr, xulurl,
|
2013-10-25 16:11:36 +04:00
|
|
|
CFSTR("libmozglue.dylib"),
|
2011-10-17 18:59:28 +04:00
|
|
|
false);
|
2011-07-02 18:47:55 +04:00
|
|
|
|
|
|
|
if (xpcomurl) {
|
|
|
|
char tbuffer[MAXPATHLEN];
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
if (CFURLGetFileSystemRepresentation(xpcomurl, true,
|
2011-07-02 18:47:55 +04:00
|
|
|
(UInt8*) tbuffer,
|
|
|
|
sizeof(tbuffer)) &&
|
|
|
|
access(tbuffer, R_OK | X_OK) == 0) {
|
|
|
|
if (realpath(tbuffer, greDir)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
greFound = true;
|
2011-07-02 18:47:55 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
greDir[0] = '\0';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CFRelease(xpcomurl);
|
|
|
|
}
|
|
|
|
|
|
|
|
CFRelease(xulurl);
|
|
|
|
}
|
|
|
|
|
|
|
|
CFRelease(absfwurl);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (!greFound) {
|
2011-10-17 18:59:28 +04:00
|
|
|
Output(false, "Could not find the Mozilla runtime.\n");
|
2005-11-17 22:25:42 +03:00
|
|
|
return 1;
|
2011-07-02 18:47:55 +04:00
|
|
|
}
|
2005-10-26 21:17:44 +04:00
|
|
|
}
|
2009-11-24 06:17:06 +03:00
|
|
|
|
2006-08-17 18:22:04 +04:00
|
|
|
rv = XPCOMGlueStartup(greDir);
|
|
|
|
if (NS_FAILED(rv)) {
|
2009-08-08 07:34:10 +04:00
|
|
|
if (rv == NS_ERROR_OUT_OF_MEMORY) {
|
|
|
|
char applicationName[2000] = "this application";
|
|
|
|
parser.GetString("App", "Name", applicationName, sizeof(applicationName));
|
2011-10-17 18:59:28 +04:00
|
|
|
Output(true, "Not enough memory available to start %s.\n",
|
2009-08-08 07:34:10 +04:00
|
|
|
applicationName);
|
|
|
|
} else {
|
2011-10-17 18:59:28 +04:00
|
|
|
Output(true, "Couldn't load XPCOM.\n");
|
2009-08-08 07:34:10 +04:00
|
|
|
}
|
2006-08-17 18:22:04 +04:00
|
|
|
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 },
|
2012-07-30 18:20:58 +04:00
|
|
|
{ nullptr, nullptr }
|
2006-08-17 18:22:04 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
rv = XPCOMGlueLoadXULFunctions(kXULFuncs);
|
|
|
|
if (NS_FAILED(rv)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
Output(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
|
2012-06-06 06:08:30 +04:00
|
|
|
nsCOMPtr<nsIFile> iniFile;
|
2009-05-13 14:16:45 +04:00
|
|
|
#ifdef XP_WIN
|
2011-05-05 20:40:04 +04:00
|
|
|
// On Windows iniPath is UTF-8 encoded so we need to convert it.
|
2011-10-17 18:59:28 +04:00
|
|
|
rv = NS_NewLocalFile(NS_ConvertUTF8toUTF16(iniPath), false,
|
2009-05-13 14:16:45 +04:00
|
|
|
getter_AddRefs(iniFile));
|
|
|
|
#else
|
2011-10-17 18:59:28 +04:00
|
|
|
rv = NS_NewNativeLocalFile(nsDependentCString(iniPath), false,
|
2006-08-17 18:22:04 +04:00
|
|
|
getter_AddRefs(iniFile));
|
2009-05-13 14:16:45 +04:00
|
|
|
#endif
|
2006-08-17 18:22:04 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
Output(true, "Couldn't find application.ini file.\n");
|
2006-08-17 18:22:04 +04:00
|
|
|
return 1;
|
|
|
|
}
|
2005-10-26 21:17:44 +04:00
|
|
|
|
2006-08-17 18:22:04 +04:00
|
|
|
AutoAppData appData(iniFile);
|
|
|
|
if (!appData) {
|
2011-10-17 18:59:28 +04:00
|
|
|
Output(true, "Error: couldn't parse application.ini.\n");
|
2006-08-17 18:22:04 +04:00
|
|
|
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';
|
|
|
|
}
|
2009-05-13 14:16:45 +04:00
|
|
|
#ifdef XP_WIN
|
|
|
|
// same as iniPath.
|
2011-10-17 18:59:28 +04:00
|
|
|
NS_NewLocalFile(NS_ConvertUTF8toUTF16(greDir), false,
|
2009-05-13 14:16:45 +04:00
|
|
|
&appData->xreDirectory);
|
|
|
|
#else
|
2011-10-17 18:59:28 +04:00
|
|
|
NS_NewNativeLocalFile(nsDependentCString(greDir), false,
|
2006-08-17 18:22:04 +04:00
|
|
|
&appData->xreDirectory);
|
2009-05-13 14:16:45 +04:00
|
|
|
#endif
|
2006-08-17 18:22:04 +04:00
|
|
|
}
|
2005-10-26 21:17:44 +04:00
|
|
|
|
2012-05-25 14:01:29 +04:00
|
|
|
retval = XRE_main(argc, argv, appData, 0);
|
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_LogTerm();
|
2005-10-26 21:17:44 +04:00
|
|
|
|
2006-08-17 18:22:04 +04:00
|
|
|
return retval;
|
2005-10-26 21:17:44 +04:00
|
|
|
}
|