bug 313956: expand installer .exe contents to make complete mar. r=ted.
[gecko.git] / xpcom / windbgdlg / windbgdlg.cpp
blob8c0dcdd253bc23192367dc2f36bea96f049f5724
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
3 * ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
16 * The Original Code is Mozilla Communicator client code, released
17 * March 31, 1998.
19 * The Initial Developer of the Original Code is
20 * Netscape Communications Corporation.
21 * Portions created by the Initial Developer are Copyright (C) 1999
22 * the Initial Developer. All Rights Reserved.
24 * Contributor(s):
25 * John Bandhauer <jband@netscape.com>
27 * Alternatively, the contents of this file may be used under the terms of
28 * either of the GNU General Public License Version 2 or later (the "GPL"),
29 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 * in which case the provisions of the GPL or the LGPL are applicable instead
31 * of those above. If you wish to allow use of your version of this file only
32 * under the terms of either the GPL or the LGPL, and not to allow others to
33 * use your version of this file under the terms of the MPL, indicate your
34 * decision by deleting the provisions above and replace them with the notice
35 * and other provisions required by the GPL or the LGPL. If you do not delete
36 * the provisions above, a recipient may use your version of this file under
37 * the terms of any one of the MPL, the GPL or the LGPL.
39 * ***** END LICENSE BLOCK ***** */
41 /* Windows only app to show a modal debug dialog - launched by nsDebug.cpp */
42 #include <windows.h>
43 #include <stdlib.h>
44 #ifdef _MSC_VER
45 #include <strsafe.h>
46 #endif
47 #ifdef __MINGW32__
48 /* MingW currently does not implement a wide version of the
49 startup routines. Workaround is to implement something like
50 it ourselves. See bug 472063 */
51 #include <stdio.h>
52 #include <shellapi.h>
53 int WINAPI wWinMain(HINSTANCE, HINSTANCE, LPWSTR, int);
55 #undef __argc
56 #undef __wargv
58 static int __argc;
59 static wchar_t** __wargv;
61 int WINAPI
62 WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
63 LPSTR lpszCommandLine, int nCmdShow)
65 LPWSTR commandLine = GetCommandLineW();
67 /* parse for __argc and __wargv for compatibility, since mingw
68 * doesn't claim to support it :(
70 __wargv = CommandLineToArgvW(commandLine, &__argc);
71 if (!__wargv)
72 return 127;
74 /* need to strip off any leading whitespace plus the first argument
75 * (the executable itself) to match what should be passed to wWinMain
77 while ((*commandLine <= L' ') && *commandLine) {
78 ++commandLine;
80 if (*commandLine == L'"') {
81 ++commandLine;
82 while ((*commandLine != L'"') && *commandLine) {
83 ++commandLine;
85 if (*commandLine) {
86 ++commandLine;
88 } else {
89 while (*commandLine > L' ') {
90 ++commandLine;
93 while ((*commandLine <= L' ') && *commandLine) {
94 ++commandLine;
97 int result = wWinMain(hInstance, hPrevInstance, commandLine, nCmdShow);
98 LocalFree(__wargv);
99 return result;
101 #endif /* __MINGW32__ */
104 int WINAPI
105 wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
106 LPWSTR lpszCmdLine, int nCmdShow)
108 /* support for auto answering based on words in the assertion.
109 * the assertion message is sent as a series of arguements (words) to the commandline.
110 * set a "word" to 0xffffffff to let the word not affect this code.
111 * set a "word" to 0xfffffffe to show the dialog.
112 * set a "word" to 0x5 to ignore (program should continue).
113 * set a "word" to 0x4 to retry (should fall into debugger).
114 * set a "word" to 0x3 to abort (die).
116 DWORD regType;
117 DWORD regValue = -1;
118 DWORD regLength = sizeof regValue;
119 HKEY hkeyCU, hkeyLM;
120 RegOpenKeyExW(HKEY_CURRENT_USER, L"Software\\mozilla.org\\windbgdlg", 0, KEY_READ, &hkeyCU);
121 RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"Software\\mozilla.org\\windbgdlg", 0, KEY_READ, &hkeyLM);
122 int argc =0;
123 for (int i = __argc - 1; regValue == (DWORD)-1 && i; --i) {
124 bool ok = false;
125 if (hkeyCU)
126 ok = RegQueryValueExW(hkeyCU, __wargv[i], 0, &regType, (LPBYTE)&regValue, &regLength) == ERROR_SUCCESS;
127 if (!ok && hkeyLM)
128 ok = RegQueryValueExW(hkeyLM, __wargv[i], 0, &regType, (LPBYTE)&regValue, &regLength) == ERROR_SUCCESS;
129 if (!ok)
130 regValue = -1;
132 if (hkeyCU)
133 RegCloseKey(hkeyCU);
134 if (hkeyLM)
135 RegCloseKey(hkeyLM);
136 if (regValue != (DWORD)-1 && regValue != (DWORD)-2)
137 return regValue;
138 static const int size = 4096;
139 static WCHAR msg[size];
141 #ifdef _MSC_VER
142 StringCchPrintfW(msg,
143 #else
144 snwprintf(msg,
145 #endif
146 size,
147 L"%s\n\nClick Abort to exit the Application.\n"
148 L"Click Retry to Debug the Application.\n"
149 L"Click Ignore to continue running the Application.",
150 lpszCmdLine);
151 msg[size - 1] = L'\0';
152 return MessageBoxW(NULL, msg, L"NSGlue_Assertion",
153 MB_ICONSTOP | MB_SYSTEMMODAL |
154 MB_ABORTRETRYIGNORE | MB_DEFBUTTON3);