diff --git a/i2p-controller.cpp b/i2p-controller.cpp index a9eebb4..461bd28 100644 --- a/i2p-controller.cpp +++ b/i2p-controller.cpp @@ -4,6 +4,39 @@ I2PController::I2PController(QObject *parent) : QObject(parent) { + this->isFatalErrored = false; + + connect(&i2p, &QProcess::errorOccurred, + this, &I2PController::onProcessError); + + connect(&i2p, QOverload::of(&QProcess::finished), + this, &I2PController::onProcessFinished); + + connect(&i2p, &QProcess::readyReadStandardOutput, this, [this]() { + qDebug() << "[i2pd]" << i2p.readAllStandardOutput(); + }); + + connect(&i2p, &QProcess::readyReadStandardError, this, [this]() { + QString msg = i2p.readAllStandardError(); + qDebug() << "[i2pd ERROR]" << msg; + if (msg.contains("missing/unreadable config file:")) { + emit fatalError(msg); + } + }); + + // Close the launcher + connect(this, &I2PController::fatalError, [this](QString msg) { + this->isFatalErrored = true; + qCritical() << msg; + QMessageBox::critical( + nullptr, + "I2P Error", + "A fatal error occurred while running i2pd:\n\n" + msg + + "\n\nThe launcher will now close.", + QMessageBox::Ok + ); + qApp->exit(1); + }); } void I2PController::start() { @@ -72,6 +105,8 @@ void I2PController::onProcessFinished(int exitCode, QProcess::ExitStatus status) void I2PController::restartI2P() { + if (isFatalErrored) return; + static int restartCount = 0; if (restartCount > 5) diff --git a/i2p-controller.h b/i2p-controller.h index 429529d..df74ffe 100644 --- a/i2p-controller.h +++ b/i2p-controller.h @@ -4,6 +4,8 @@ #include #include #include +#include +#include class I2PController : public QObject { @@ -14,6 +16,7 @@ public: private: QProcess i2p; void restartI2P(); + bool isFatalErrored; public slots: void onProcessError(QProcess::ProcessError error); void onProcessFinished(int exitCode, QProcess::ExitStatus status); diff --git a/locales.cpp b/locales.cpp index 490badd..769e6b2 100644 --- a/locales.cpp +++ b/locales.cpp @@ -25,6 +25,10 @@ LocaleMap ru_RU = { {"welcome.showPassword", "Показать пароль"}, {"welcome.logIn", "Войти"}, {"welcome.register", "Зарегистрироваться"}, + // I2PD + {"i2pd.errorTitle", "Ошибка I2P"}, + {"i2pd.errorDescription.p1", "I2P Завершилась с фатальной ошибкой:\n\n"}, + {"i2pd.errorDescription.p2", "\n\nЛаунчер будет закрыт."}, }; // English @@ -50,6 +54,10 @@ LocaleMap en_US = { {"welcome.showPassword", "Show the password"}, {"welcome.logIn", "LogIn"}, {"welcome.register", "Registration"}, + // I2PD + {"i2pd.errorTitle", "I2P Error"}, + {"i2pd.errorDescription.p1", "A fatal error occurred while running i2pd:\n\n"}, + {"i2pd.errorDescription.p2", "\n\nThe launcher will now close."}, }; void initLocales () { @@ -58,3 +66,12 @@ void initLocales () { locales["en_US"] = &en_US; //locales["en_UK"] = &en_US; } + +LocaleMap* getLocale () { + std::string locale = (QLocale::system()).name().toStdString(); + if (locales.find(locale) == locales.end()) { + locale = "en_US"; + } + LocaleMap* localeMap = locales[locale]; + return localeMap; +} diff --git a/locales.h b/locales.h index 00a6ad4..571a87b 100644 --- a/locales.h +++ b/locales.h @@ -3,9 +3,11 @@ #include #include +#include using LocaleMap = std::map; extern std::map locales; extern void initLocales (); +LocaleMap* getLocale (); #endif // LOCALES_H