From 0b903ef40b727181fcf38356fd2486212973dae9 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 31 May 2019 17:43:04 +0200 Subject: Fix .conf file reading, add messages/warnings --- src/config.cpp | 18 +++++++++++++++--- src/main.cpp | 1 + 2 files changed, 16 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/config.cpp b/src/config.cpp index 63630d0..1689b00 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -5,6 +5,7 @@ #include #include #include +#include static QCommandLineParser parser; static QSettings* configFile = nullptr; @@ -81,8 +82,16 @@ bool Config::isSet(const ConfigOption* const option) return false; if (parser.isSet(option->cmdLine)) return true; - if (configFile != nullptr && !option->iniKey.isEmpty()) - return !configFile->value(option->iniKey, option->defaultValue).isNull(); + if (configFile != nullptr && !option->iniKey.isEmpty() && configFile->contains(option->iniKey)) { + // Option present in ini... + if (option->withArgument) // ...and needs an argument -> set either way + return true; + // If it doesn't require an argument, special case + QString val = configFile->value(option->iniKey).toString().toLower(); + if (!val.isEmpty() && val != QLatin1String("false") && val != QLatin1String("0") && val != QLatin1String("no") && val != QLatin1String("off")) + return true; // Everything except empty string, "false", "0", "no" and "off" is considered as "is set" + // Fall though otherwise + } return false; } @@ -93,10 +102,13 @@ bool Config::init(const QCoreApplication& app, const ConfigOption* const configF parser.process(app); if (configFileName != nullptr && parser.isSet(configFileName->cmdLine)) { QString file(parser.value(configFileName->cmdLine)); - if (!QFileInfo(file).exists()) + if (!QFileInfo(file).exists()) { + qDebug() << "--config file" << file << "does not exist!"; return false; + } configFile = new QSettings(file, QSettings::IniFormat); configFile->setIniCodec("UTF-8"); + qDebug() << "Using config file" << file; } return true; } diff --git a/src/main.cpp b/src/main.cpp index 0e3229b..3390101 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -31,6 +31,7 @@ int main(int argc, char *argv[]) { } if (Config::isSet(Config::INSECURE)) { + qDebug() << "Warning: Certificate validation disabled"; QSslConfiguration sslConf = QSslConfiguration::defaultConfiguration(); sslConf.setPeerVerifyMode(QSslSocket::VerifyNone); QSslConfiguration::setDefaultConfiguration(sslConf); -- cgit v1.2.3-55-g7522