1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 2002
20 * the Initial Developer. All Rights Reserved.
23 * Brian Ryner <bryner@brianryner.com>
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 #include "nsXULAppAPI.h"
53 #include "nsILocalFile.h"
54 #include "nsStringGlue.h"
57 // we want to use the DLL blocklist if possible
58 #define XRE_WANT_DLL_BLOCKLIST
59 // we want a wmain entry point
60 #include "nsWindowsWMain.cpp"
63 static void Output(const char *fmt
, ... )
68 #if defined(XP_WIN) && !MOZ_WINCONSOLE
70 _vsnwprintf(msg
, sizeof(msg
)/sizeof(msg
[0]), NS_ConvertUTF8toUTF16(fmt
).get(), ap
);
71 MessageBoxW(NULL
, msg
, L
"XULRunner", MB_OK
| MB_ICONERROR
);
73 vfprintf(stderr
, fmt
, ap
);
80 * Return true if |arg| matches the given argument name.
82 static PRBool
IsArg(const char* arg
, const char* s
)
88 return !PL_strcasecmp(arg
, s
);
91 #if defined(XP_WIN) || defined(XP_OS2)
93 return !PL_strcasecmp(++arg
, s
);
100 * A helper class which calls NS_LogInit/NS_LogTerm in its scope.
105 ScopedLogging() { NS_LogInit(); }
106 ~ScopedLogging() { NS_LogTerm(); }
109 int main(int argc
, char* argv
[])
113 nsCOMPtr
<nsILocalFile
> appini
;
114 nsresult rv
= XRE_GetBinaryPath(argv
[0], getter_AddRefs(appini
));
116 Output("Couldn't calculate the application directory.");
119 appini
->SetNativeLeafName(NS_LITERAL_CSTRING("application.ini"));
121 // Allow firefox.exe to launch XULRunner apps via -app <application.ini>
122 // Note that -app must be the *first* argument.
123 char *appEnv
= nsnull
;
124 const char *appDataFile
= PR_GetEnv("XUL_APP_FILE");
125 if (appDataFile
&& *appDataFile
) {
126 rv
= XRE_GetFileFromPath(appDataFile
, getter_AddRefs(appini
));
128 Output("Invalid path found: '%s'", appDataFile
);
132 else if (argc
> 1 && IsArg(argv
[1], "app")) {
134 Output("Incorrect number of arguments passed to -app");
138 rv
= XRE_GetFileFromPath(argv
[2], getter_AddRefs(appini
));
140 Output("application.ini path not recognized: '%s'", argv
[2]);
144 appEnv
= PR_smprintf("XUL_APP_FILE=%s", argv
[2]);
151 nsXREAppData
*appData
;
152 rv
= XRE_CreateAppData(appini
, &appData
);
154 Output("Couldn't read application.ini");
158 int result
= XRE_main(argc
, argv
, appData
);
159 XRE_FreeAppData(appData
);
161 PR_smprintf_free(appEnv
);