diff --git a/xulrunner/stub/nsXULStub.cpp b/xulrunner/stub/nsXULStub.cpp --- a/xulrunner/stub/nsXULStub.cpp +++ b/xulrunner/stub/nsXULStub.cpp @@ -33,16 +33,17 @@ * 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 "plstr.h" #include "nsXPCOMPrivate.h" // for XP MAXPATHLEN #include "nsMemory.h" // for NS_ARRAY_LENGTH #include "nsXULAppAPI.h" #include "nsILocalFile.h" #include #ifdef XP_WIN @@ -107,16 +108,37 @@ static void Output(PRBool isError, const sizeof(wide_msg) / sizeof(wchar_t)); MessageBoxW(NULL, wide_msg, L"XULRunner", flags); #else vfprintf(stderr, fmt, ap); #endif va_end(ap); +} + +/** + * Return true if |arg| matches the given argument name. + */ +static PRBool IsArg(const char* arg, const char* s) +{ + if (*arg == '-') + { + if (*++arg == '-') + ++arg; + //return !PL_strcasecmp(arg, s); + return !strcasecmp(arg, s); + } + +#if defined(XP_WIN) || defined(XP_OS2) + if (*arg == '/') + return !PL_strcasecmp(++arg, s); +#endif + + return PR_FALSE; } class AutoAppData { public: AutoAppData(nsILocalFile* aINIFile) : mAppData(nsnull) { nsresult rv = XRE_CreateAppData(aINIFile, &mAppData); if (NS_FAILED(rv)) @@ -216,69 +238,114 @@ main(int argc, char **argv) // 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 + const char *appDataFile = getenv("XUL_APP_FILE"); + char appDataFileStrDUP[MAXPATHLEN]; + + if (!(appDataFile && *appDataFile)) { + if (argc < 2) { + //Usage(argv[0]); + return 1; + } + + if (IsArg(argv[1], "app")) { + if (argc == 2) { + //Usage(argv[0]); + return 1; + } + argv[1] = argv[0]; + ++argv; + --argc; + } + + appDataFile = argv[1]; + argv[1] = argv[0]; + ++argv; + --argc; + + static char kAppEnv[MAXPATHLEN]; + //PR_snprintf(kAppEnv, MAXPATHLEN, "XUL_APP_FILE=%s", appDataFile); + //PR_SetEnv(kAppEnv); + snprintf(kAppEnv, MAXPATHLEN, "%s", appDataFile); + setenv("XUL_APP_FILE", kAppEnv, 1); + printf("main - appDataFile = %s\n", appDataFile); + } else { 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) { sprintf(tmpPath, "%s/%s", token, argv[0]); + printf("main - tmpPath = %s\n", tmpPath); if (realpath(tmpPath, iniPath) && stat(iniPath, &fileStat) == 0) { found = PR_TRUE; break; } token = strtok(NULL, ":"); } free (pathdup); if (!found) return 1; } #endif + printf("main - argv[0] = %s\n", argv[0]); + printf("main - iniPath = %s\n", iniPath); + lastSlash = strrchr(iniPath, PATH_SEPARATOR_CHAR); if (!lastSlash) return 1; - + printf("main - lastSlash = %s\n", lastSlash); *(++lastSlash) = '\0'; // On Linux/Win, look for XULRunner in appdir/xulrunner snprintf(greDir, sizeof(greDir), "%sxulrunner" XPCOM_FILE_PATH_SEPARATOR XPCOM_DLL, iniPath); + + printf("main - greDir2 = %s\n", greDir); #ifdef WINCE wchar_t wideGreDir[MAX_PATH]; MultiByteToWideChar(CP_ACP, 0, greDir, -1, wideGreDir, MAX_PATH); DWORD fileAttrs = GetFileAttributesW(wideGreDir); greFound = fileAttrs != INVALID_FILE_ATTRIBUTES; #else greFound = (access(greDir, R_OK) == 0); #endif + strncpy(lastSlash, "application.ini", sizeof(iniPath) - (lastSlash - iniPath)); + printf("main - lastSlash2 = %s\n", lastSlash); + } #endif + if (!realpath(appDataFile, appDataFileStrDUP)) + return 1; + + printf("main - appDataFileStrDUP = %s\n", appDataFileStrDUP); + nsINIParser parser; - rv = parser.Init(iniPath); +// rv = parser.Init(iniPath); + rv = parser.Init(appDataFile); if (NS_FAILED(rv)) { fprintf(stderr, "Could not read application.ini\n"); return 1; } if (!greFound) { char minVersion[VERSION_MAXLEN]; @@ -352,17 +419,17 @@ main(int argc, char **argv) } NS_LogInit(); int retval; { // Scope COMPtr and AutoAppData nsCOMPtr iniFile; - rv = NS_NewNativeLocalFile(nsDependentCString(iniPath), PR_FALSE, + rv = NS_NewNativeLocalFile(nsDependentCString(appDataFileStrDUP), PR_FALSE, getter_AddRefs(iniFile)); if (NS_FAILED(rv)) { Output(PR_TRUE, "Couldn't find application.ini file.\n"); return 1; } AutoAppData appData(iniFile); if (!appData) {