@@ -161,22 +161,23 @@ void DebugMessageHandler(QtMsgType type, const QMessageLogContext& context, cons
161
161
#ifndef BITCOIN_QT_TEST
162
162
int main (int argc, char *argv[])
163
163
{
164
- bool fMissingDatadir = false ;
165
164
bool fSelParFromCLFailed = false ;
166
-
165
+ // / 1. Parse command-line options. These take precedence over anything else.
167
166
// Command-line options take precedence:
168
167
ParseParameters (argc, argv);
169
- // ... then bitcoin.conf:
170
- if (!boost::filesystem::is_directory (GetDataDir (false ))) {
171
- fMissingDatadir = true ;
172
- } else {
173
- ReadConfigFile (mapArgs, mapMultiArgs);
174
- }
175
168
// Check for -testnet or -regtest parameter (TestNet() calls are only valid after this clause)
176
169
if (!SelectParamsFromCommandLine ()) {
177
170
fSelParFromCLFailed = true ;
178
171
}
172
+ // Parse URIs on command line -- this can affect TestNet() / RegTest() mode
173
+ if (!PaymentServer::ipcParseCommandLine (argc, argv))
174
+ exit (0 );
175
+
176
+ bool isaTestNet = TestNet () || RegTest ();
177
+
178
+ // Do not refer to data directory yet, this can be overridden by Intro::pickDataDirectory
179
179
180
+ // / 2. Basic Qt initialization (not dependent on parameters or configuration)
180
181
#if QT_VERSION < 0x050000
181
182
// Internal string conversion is all UTF-8
182
183
QTextCodec::setCodecForTr (QTextCodec::codecForName (" UTF-8" ));
@@ -196,44 +197,62 @@ int main(int argc, char *argv[])
196
197
// Register meta types used for QMetaObject::invokeMethod
197
198
qRegisterMetaType< bool * >();
198
199
199
- // Application identification (must be set before OptionsModel is initialized,
200
- // as it is used to locate QSettings)
201
- bool isaTestNet = TestNet () || RegTest ();
200
+ // / 3. Application identification
201
+ // must be set before OptionsModel is initialized or translations are loaded,
202
+ // as it is used to locate QSettings
202
203
QApplication::setOrganizationName (" Bitcoin" );
203
204
QApplication::setOrganizationDomain (" bitcoin.org" );
204
205
if (isaTestNet) // Separate UI settings for testnets
205
206
QApplication::setApplicationName (" Bitcoin-Qt-testnet" );
206
207
else
207
208
QApplication::setApplicationName (" Bitcoin-Qt" );
208
209
210
+ // / 4. Initialization of translations, so that intro dialog is in user's language
209
211
// Now that QSettings are accessible, initialize translations
210
212
QTranslator qtTranslatorBase, qtTranslator, translatorBase, translator;
211
213
initTranslations (qtTranslatorBase, qtTranslator, translatorBase, translator);
212
214
213
- // Do this early as we don't want to bother initializing if we are just calling IPC
214
- // ... but do it after creating app and setting up translations, so errors are
215
- // translated properly.
216
- if (PaymentServer::ipcSendCommandLine (argc, argv))
217
- exit (0 );
218
-
219
- // Now that translations are initialized check for errors and allow a translatable error message
220
- if (fMissingDatadir ) {
221
- QMessageBox::critical (0 , QObject::tr (" Bitcoin" ),
222
- QObject::tr (" Error: Specified data directory \" %1\" does not exist." ).arg (QString::fromStdString (mapArgs[" -datadir" ])));
215
+ // Show help message immediately after parsing command-line options (for "-lang") and setting locale,
216
+ // but before showing splash screen.
217
+ if (mapArgs.count (" -?" ) || mapArgs.count (" --help" ))
218
+ {
219
+ GUIUtil::HelpMessageBox help;
220
+ help.showOrPrint ();
223
221
return 1 ;
224
222
}
225
- else if (fSelParFromCLFailed ) {
223
+ // Now that translations are initialized, check for earlier errors and show a translatable error message
224
+ if (fSelParFromCLFailed ) {
226
225
QMessageBox::critical (0 , QObject::tr (" Bitcoin" ), QObject::tr (" Error: Invalid combination of -regtest and -testnet." ));
227
226
return 1 ;
228
227
}
229
228
229
+ // / 5. Now that settings and translations are available, ask user for data directory
230
+ // User language is set up: pick a data directory
231
+ Intro::pickDataDirectory (isaTestNet);
232
+
233
+ // / 6. Determine availability of data directory and parse bitcoin.conf
234
+ if (!boost::filesystem::is_directory (GetDataDir (false )))
235
+ {
236
+ QMessageBox::critical (0 , QObject::tr (" Bitcoin" ),
237
+ QObject::tr (" Error: Specified data directory \" %1\" does not exist." ).arg (QString::fromStdString (mapArgs[" -datadir" ])));
238
+ return 1 ;
239
+ }
240
+ ReadConfigFile (mapArgs, mapMultiArgs);
241
+
242
+ // / 7. URI IPC sending
243
+ // - Do this early as we don't want to bother initializing if we are just calling IPC
244
+ // - Do this *after* setting up the data directory, as the data directory hash is used in the name
245
+ // of the server.
246
+ // - Do this after creating app and setting up translations, so errors are
247
+ // translated properly.
248
+ if (PaymentServer::ipcSendCommandLine ())
249
+ exit (0 );
250
+
230
251
// Start up the payment server early, too, so impatient users that click on
231
252
// bitcoin: links repeatedly have their payment requests routed to this process:
232
253
PaymentServer* paymentServer = new PaymentServer (&app);
233
254
234
- // User language is set up: pick a data directory
235
- Intro::pickDataDirectory (isaTestNet);
236
-
255
+ // / 8. Main GUI initialization
237
256
// Install global event filter that makes sure that long tooltips can be word-wrapped
238
257
app.installEventFilter (new GUIUtil::ToolTipToRichTextFilter (TOOLTIP_WRAP_THRESHOLD, &app));
239
258
// Install qDebug() message handler to route to debug.log
@@ -242,24 +261,15 @@ int main(int argc, char *argv[])
242
261
#else
243
262
qInstallMessageHandler (DebugMessageHandler);
244
263
#endif
245
-
246
- // ... now GUI settings:
264
+ // Load GUI settings from QSettings
247
265
OptionsModel optionsModel;
248
266
249
267
// Subscribe to global signals from core
250
268
uiInterface.ThreadSafeMessageBox .connect (ThreadSafeMessageBox);
251
269
uiInterface.InitMessage .connect (InitMessage);
252
270
uiInterface.Translate .connect (Translate);
253
271
254
- // Show help message immediately after parsing command-line options (for "-lang") and setting locale,
255
- // but before showing splash screen.
256
- if (mapArgs.count (" -?" ) || mapArgs.count (" --help" ))
257
- {
258
- GUIUtil::HelpMessageBox help;
259
- help.showOrPrint ();
260
- return 1 ;
261
- }
262
-
272
+ // Show splash screen if appropriate
263
273
SplashScreen splash (QPixmap (), 0 , isaTestNet);
264
274
if (GetBoolArg (" -splash" , true ) && !GetBoolArg (" -min" , false ))
265
275
{
0 commit comments