From b11fd1d6b4350c5e74594d6b634784405f4e65c8 Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Mon, 8 Dec 2014 14:22:28 -0800 Subject: [PATCH] Default qtlogging.ini file is copied if it doesn't exist --- .../QLoggingCategory/qtlogging.ini | 0 qgroundcontrol.qrc | 3 ++ src/QGCApplication.cc | 30 +++++++++++++++++++ 3 files changed, 33 insertions(+) rename qtlogging.ini => files/QLoggingCategory/qtlogging.ini (100%) diff --git a/qtlogging.ini b/files/QLoggingCategory/qtlogging.ini similarity index 100% rename from qtlogging.ini rename to files/QLoggingCategory/qtlogging.ini diff --git a/qgroundcontrol.qrc b/qgroundcontrol.qrc index dd04adb54..d1ba57b8d 100644 --- a/qgroundcontrol.qrc +++ b/qgroundcontrol.qrc @@ -231,4 +231,7 @@ src/qgcunittest/MockLink.param + + files/QLoggingCategory/qtlogging.ini + diff --git a/src/QGCApplication.cc b/src/QGCApplication.cc index 469bcee53..57bb92bab 100644 --- a/src/QGCApplication.cc +++ b/src/QGCApplication.cc @@ -92,6 +92,36 @@ QGCApplication::QGCApplication(int &argc, char* argv[], bool unitTesting) : Q_ASSERT(_app == NULL); _app = this; + +#ifdef QT_DEBUG + // First thing we want to do is set up the qtlogging.ini file. If it doesn't already exist we copy + // it to the correct location. This way default debug builds will have logging turned off. + + bool loggingDirectoryOk = false; + QDir iniFileLocation(QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation)); + if (!iniFileLocation.cd("QtProjects")) { + if (!iniFileLocation.mkdir("QtProjects")) { + qDebug() << "Unable to create qtlogging.ini directory" << iniFileLocation.filePath("QtProjects"); + } else { + if (!iniFileLocation.cd("QtProjects")) { + qDebug() << "Unable to access qtlogging.ini directory" << iniFileLocation.filePath("QtProjects");; + } + loggingDirectoryOk = true; + } + } else { + loggingDirectoryOk = true; + } + + if (loggingDirectoryOk) { + qDebug () << iniFileLocation; + if (!iniFileLocation.exists("qtlogging.ini")) { + if (!QFile::copy(":QLoggingCategory/qtlogging.ini", iniFileLocation.filePath("qtlogging.ini"))) { + qDebug() << "Unable to copy qtlogging.ini to" << iniFileLocation; + } + } + } +#endif + // Set application information if (_runningUnitTests) { // We don't want unit tests to use the same QSettings space as the normal app. So we tweak the app -- 2.22.0