@@ -127,6 +127,58 @@ static void initTranslations(QTranslator &qtTranslatorBase, QTranslator &qtTrans
127
127
QApplication::installTranslator (&translator);
128
128
}
129
129
130
+ static std::string JoinErrors (const std::vector<std::string>& errors)
131
+ {
132
+ return Join (errors, " \n " , [](const std::string& error) { return " - " + error; });
133
+ }
134
+
135
+ static bool InitSettings ()
136
+ {
137
+ if (!gArgs .GetSettingsPath ()) {
138
+ return true ; // Do nothing if settings file disabled.
139
+ }
140
+
141
+ std::vector<std::string> errors;
142
+ if (!gArgs .ReadSettingsFile (&errors)) {
143
+ bilingual_str error = _ (" Settings file could not be read" );
144
+ InitError (Untranslated (strprintf (" %s:\n %s\n " , error.original , JoinErrors (errors))));
145
+
146
+ QMessageBox messagebox (QMessageBox::Critical, PACKAGE_NAME, QString::fromStdString (strprintf (" %s." , error.translated )), QMessageBox::Reset | QMessageBox::Abort);
147
+ /* : Explanatory text shown on startup when the settings file cannot be read.
148
+ Prompts user to make a choice between resetting or aborting. */
149
+ messagebox.setInformativeText (QObject::tr (" Do you want to reset settings to default values, or to abort without making changes?" ));
150
+ messagebox.setDetailedText (QString::fromStdString (JoinErrors (errors)));
151
+ messagebox.setTextFormat (Qt::PlainText);
152
+ messagebox.setDefaultButton (QMessageBox::Reset);
153
+ switch (messagebox.exec ()) {
154
+ case QMessageBox::Reset:
155
+ break ;
156
+ case QMessageBox::Abort:
157
+ return false ;
158
+ default :
159
+ assert (false );
160
+ }
161
+ }
162
+
163
+ errors.clear ();
164
+ if (!gArgs .WriteSettingsFile (&errors)) {
165
+ bilingual_str error = _ (" Settings file could not be written" );
166
+ InitError (Untranslated (strprintf (" %s:\n %s\n " , error.original , JoinErrors (errors))));
167
+
168
+ QMessageBox messagebox (QMessageBox::Critical, PACKAGE_NAME, QString::fromStdString (strprintf (" %s." , error.translated )), QMessageBox::Ok);
169
+ /* : Explanatory text shown on startup when the settings file could not be written.
170
+ Prompts user to check that we have the ability to write to the file.
171
+ Explains that the user has the option of running without a settings file.*/
172
+ messagebox.setInformativeText (QObject::tr (" A fatal error occured. Check that settings file is writable, or try running with -nosettings." ));
173
+ messagebox.setDetailedText (QString::fromStdString (JoinErrors (errors)));
174
+ messagebox.setTextFormat (Qt::PlainText);
175
+ messagebox.setDefaultButton (QMessageBox::Ok);
176
+ messagebox.exec ();
177
+ return false ;
178
+ }
179
+ return true ;
180
+ }
181
+
130
182
/* qDebug() message handler --> debug.log */
131
183
void DebugMessageHandler (QtMsgType type, const QMessageLogContext& context, const QString &msg)
132
184
{
@@ -590,9 +642,8 @@ int GuiMain(int argc, char* argv[])
590
642
// Parse URIs on command line -- this can affect Params()
591
643
PaymentServer::ipcParseCommandLine (argc, argv);
592
644
#endif
593
- if (!gArgs .InitSettings (error)) {
594
- InitError (Untranslated (error));
595
- QMessageBox::critical (nullptr , PACKAGE_NAME, QObject::tr (" Error initializing settings: %1" ).arg (QString::fromStdString (error)));
645
+
646
+ if (!InitSettings ()) {
596
647
return EXIT_FAILURE;
597
648
}
598
649
0 commit comments