From d137ca3bec13f0c4205672c65a9f0ccfec684ce0 Mon Sep 17 00:00:00 2001 From: Isabell Pflug Date: Tue, 23 May 2023 23:07:45 +0200 Subject: [PATCH] :wrench: Improved search for config file --- assignments/06/ThinkPink/main.cpp | 22 +++++++++++++++++++--- assignments/06/ThinkPink/thinkpink.ini | 1 - 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/assignments/06/ThinkPink/main.cpp b/assignments/06/ThinkPink/main.cpp index 5f0cb49..a02b611 100644 --- a/assignments/06/ThinkPink/main.cpp +++ b/assignments/06/ThinkPink/main.cpp @@ -11,9 +11,25 @@ std::unique_ptr settings; // funktioniert komplett plattformunabhängig! // sogar auf Android, wenn man wahnsinnig sein sollte! -void initialise_settings() { - QString config_string = QStandardPaths::locate( QStandardPaths::ConfigLocation, "ThinkPink.ini"); - settings.reset( new QSettings( config_string, QSettings::IniFormat ) ); +void initialise_settings() { // sucht für die Config Datei an diversen sinnvollen Orten + QString config_filename = "ThinkPink.ini"; + QString config_path = ""; + + // priorisiert Config Datei, die direkt neben der Binary liegt, falls vorhanden + QString prio_path = QDir(QCoreApplication::applicationDirPath()).filePath(config_filename); + if (QFileInfo::exists(prio_path)) { + config_path = prio_path; + } + else {// schaut an den gängigen Orten (abhängig vom Betriebssystem) nach der Config-Datei + QList locations{ QStandardPaths::ConfigLocation, QStandardPaths::AppConfigLocation}; + for (long long i = 0; i < locations.size(); i++) { + config_path = QStandardPaths::locate( locations.value(i), config_filename); + if (config_path != "") // config found + break; + } + } + + settings.reset( new QSettings( config_path, QSettings::IniFormat ) ); } diff --git a/assignments/06/ThinkPink/thinkpink.ini b/assignments/06/ThinkPink/thinkpink.ini index 2b0e150..32f689a 100644 --- a/assignments/06/ThinkPink/thinkpink.ini +++ b/assignments/06/ThinkPink/thinkpink.ini @@ -4,4 +4,3 @@ rows = 9 [colors] colors = 0xBD005E, 0xFFC0CB, 0xDB7093, 0xF7A8B8, 0x660033 -;, 0xDB7093