@@ -144,6 +144,58 @@ static void initTranslations(QTranslator &qtTranslatorBase, QTranslator &qtTrans
144
144
QApplication::installTranslator (&translator);
145
145
}
146
146
147
+ static std::string JoinErrors (const std::vector<std::string>& errors)
148
+ {
149
+ return Join (errors, " \n " , [](const std::string& error) { return " - " + error; });
150
+ }
151
+
152
+ static bool InitSettings ()
153
+ {
154
+ if (!gArgs .GetSettingsPath ()) {
155
+ return true ; // Do nothing if settings file disabled.
156
+ }
157
+
158
+ std::vector<std::string> errors;
159
+ if (!gArgs .ReadSettingsFile (&errors)) {
160
+ bilingual_str error = _ (" Settings file could not be read" );
161
+ InitError (Untranslated (strprintf (" %s:\n %s\n " , error.original , JoinErrors (errors))));
162
+
163
+ QMessageBox messagebox (QMessageBox::Critical, PACKAGE_NAME, QString::fromStdString (strprintf (" %s." , error.translated )), QMessageBox::Reset | QMessageBox::Abort);
164
+ /* : Explanatory text shown on startup when the settings file cannot be read.
165
+ Prompts user to make a choice between resetting or aborting. */
166
+ messagebox.setInformativeText (QObject::tr (" Do you want to reset settings to default values, or to abort without making changes?" ));
167
+ messagebox.setDetailedText (QString::fromStdString (JoinErrors (errors)));
168
+ messagebox.setTextFormat (Qt::PlainText);
169
+ messagebox.setDefaultButton (QMessageBox::Reset);
170
+ switch (messagebox.exec ()) {
171
+ case QMessageBox::Reset:
172
+ break ;
173
+ case QMessageBox::Abort:
174
+ return false ;
175
+ default :
176
+ assert (false );
177
+ }
178
+ }
179
+
180
+ errors.clear ();
181
+ if (!gArgs .WriteSettingsFile (&errors)) {
182
+ bilingual_str error = _ (" Settings file could not be written" );
183
+ InitError (Untranslated (strprintf (" %s:\n %s\n " , error.original , JoinErrors (errors))));
184
+
185
+ QMessageBox messagebox (QMessageBox::Critical, PACKAGE_NAME, QString::fromStdString (strprintf (" %s." , error.translated )), QMessageBox::Ok);
186
+ /* : Explanatory text shown on startup when the settings file could not be written.
187
+ Prompts user to check that we have the ability to write to the file.
188
+ Explains that the user has the option of running without a settings file.*/
189
+ messagebox.setInformativeText (QObject::tr (" A fatal error occured. Check that settings file is writable, or try running with -nosettings." ));
190
+ messagebox.setDetailedText (QString::fromStdString (JoinErrors (errors)));
191
+ messagebox.setTextFormat (Qt::PlainText);
192
+ messagebox.setDefaultButton (QMessageBox::Ok);
193
+ messagebox.exec ();
194
+ return false ;
195
+ }
196
+ return true ;
197
+ }
198
+
147
199
/* qDebug() message handler --> debug.log */
148
200
void DebugMessageHandler (QtMsgType type, const QMessageLogContext& context, const QString &msg)
149
201
{
@@ -512,9 +564,8 @@ int GuiMain(int argc, char* argv[])
512
564
// Parse URIs on command line -- this can affect Params()
513
565
PaymentServer::ipcParseCommandLine (argc, argv);
514
566
#endif
515
- if (!gArgs .InitSettings (error)) {
516
- InitError (Untranslated (error));
517
- QMessageBox::critical (nullptr , PACKAGE_NAME, QObject::tr (" Error initializing settings: %1" ).arg (QString::fromStdString (error)));
567
+
568
+ if (!InitSettings ()) {
518
569
return EXIT_FAILURE;
519
570
}
520
571
0 commit comments