diff --git a/src/blackcore/application.cpp b/src/blackcore/application.cpp index e1173d8de..9337feedd 100644 --- a/src/blackcore/application.cpp +++ b/src/blackcore/application.cpp @@ -18,6 +18,7 @@ #include "blackcore/webdataservices.h" #include "blackmisc/datacache.h" #include "blackmisc/dbusserver.h" +#include "blackmisc/directoryutils.h" #include "blackmisc/filelogger.h" #include "blackmisc/logcategory.h" #include "blackmisc/logcategorylist.h" @@ -456,14 +457,6 @@ namespace BlackCore } } - QString CApplication::applicationDirPath() - { - QString appDirectoryString(qApp->applicationDirPath()); - if (appDirectoryString.endsWith("Contents/MacOS")) { appDirectoryString += "/../../.."; } - QDir appDirectory(appDirectoryString); - return appDirectory.absolutePath(); - } - bool CApplication::useContexts(const CCoreFacadeConfig &coreConfig) { Q_ASSERT_X(this->m_parsed, Q_FUNC_INFO, "Call this function after parsing"); @@ -535,7 +528,10 @@ namespace BlackCore CLogHandler::instance()->install(); // make sure we have a log handler! // File logger - static const QString logPath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/org.swift-project/logs"; + static const QString logPath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + + "/org.swift-project/" + + CDirectoryUtils::normalizedApplicationDirectory() + + "/logs"; this->m_fileLogger.reset(new CFileLogger(executable(), logPath)); this->m_fileLogger->changeLogPattern(CLogPattern().withSeverityAtOrAbove(CStatusMessage::SeverityDebug)); } diff --git a/src/blackcore/application.h b/src/blackcore/application.h index c1e2e4154..66eabcf92 100644 --- a/src/blackcore/application.h +++ b/src/blackcore/application.h @@ -172,10 +172,6 @@ namespace BlackCore //! Clear the caches static QStringList clearCaches(); - //! Returns the directory of the application. In contrast to QCoreApplication::applicationDirPath() - //! it takes Mac OS X app bundles into account and returns the directory of the bundle. - static QString applicationDirPath(); - // ----------------------- parsing ---------------------------------------- //! \name parsing of command line options diff --git a/src/blackcore/pluginmanager.cpp b/src/blackcore/pluginmanager.cpp index 7c821f976..3bba69f9d 100644 --- a/src/blackcore/pluginmanager.cpp +++ b/src/blackcore/pluginmanager.cpp @@ -9,10 +9,10 @@ #include "blackcore/pluginmanager.h" #include "blackcore/application.h" +#include "blackmisc/directoryutils.h" #include "blackmisc/logmessage.h" #include "blackmisc/statusmessage.h" -#include #include #include #include @@ -55,7 +55,7 @@ namespace BlackCore QString IPluginManager::pluginDirectory() const { - return sApp->applicationDirPath() % QStringLiteral("/plugins"); + return CDirectoryUtils::applicationDirectoryPath() % QStringLiteral("/plugins"); } bool IPluginManager::isValid(const QJsonObject &metadata) const diff --git a/src/blackcore/pluginmanagersimulator.cpp b/src/blackcore/pluginmanagersimulator.cpp index 2d8735ebd..126025604 100644 --- a/src/blackcore/pluginmanagersimulator.cpp +++ b/src/blackcore/pluginmanagersimulator.cpp @@ -10,8 +10,8 @@ #include "blackcore/application.h" #include "blackcore/pluginmanagersimulator.h" #include "blackcore/simulator.h" +#include "blackmisc/directoryutils.h" -#include #include #include #include @@ -103,7 +103,7 @@ namespace BlackCore QString CPluginManagerSimulator::pluginDirectory() const { - return sApp->applicationDirPath() % QStringLiteral("/plugins/simulator"); + return CDirectoryUtils::applicationDirectoryPath() % QStringLiteral("/plugins/simulator"); } } diff --git a/src/blackcore/pluginmanagerweatherdata.cpp b/src/blackcore/pluginmanagerweatherdata.cpp index 5d36783ed..cec901d40 100644 --- a/src/blackcore/pluginmanagerweatherdata.cpp +++ b/src/blackcore/pluginmanagerweatherdata.cpp @@ -10,8 +10,8 @@ #include "blackcore/application.h" #include "blackcore/pluginmanagerweatherdata.h" #include "blackcore/weatherdata.h" +#include "blackmisc/directoryutils.h" -#include #include #include #include @@ -67,7 +67,7 @@ namespace BlackCore QString CPluginManagerWeatherData::pluginDirectory() const { - return sApp->applicationDirPath() % QStringLiteral("/plugins/weatherdata"); + return CDirectoryUtils::applicationDirectoryPath() % QStringLiteral("/plugins/weatherdata"); } } diff --git a/src/blackmisc/datacache.cpp b/src/blackmisc/datacache.cpp index 5283a9265..94b96eb0a 100644 --- a/src/blackmisc/datacache.cpp +++ b/src/blackmisc/datacache.cpp @@ -11,6 +11,7 @@ #include "blackmisc/atomicfile.h" #include "blackmisc/datacache.h" +#include "blackmisc/directoryutils.h" #include "blackmisc/identifier.h" #include "blackmisc/logmessage.h" @@ -99,7 +100,10 @@ namespace BlackMisc const QString &CDataCache::persistentStore() { - static const QString dir = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/org.swift-project/data/cache/core"; + static const QString dir = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + + "/org.swift-project/" + + CDirectoryUtils::normalizedApplicationDirectory() + + "/data/cache/core"; return dir; } diff --git a/src/blackmisc/directoryutils.cpp b/src/blackmisc/directoryutils.cpp new file mode 100644 index 000000000..d8bf41d45 --- /dev/null +++ b/src/blackmisc/directoryutils.cpp @@ -0,0 +1,54 @@ +/* Copyright (C) 2016 + * swift project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +//! \cond PRIVATE + +#include "blackmisc/directoryutils.h" + +#include +#include +#include + +namespace BlackMisc +{ + + QString applicationDirectoryPathImpl() + { + QString appDirectoryString(qApp->applicationDirPath()); + if (appDirectoryString.endsWith("Contents/MacOS")) { appDirectoryString += "/../../.."; } + QDir appDirectory(appDirectoryString); + return appDirectory.absolutePath(); + } + + QString CDirectoryUtils::applicationDirectoryPath() + { + static const QString appDirectory(applicationDirectoryPathImpl()); + return appDirectory; + } + + QString normalizedApplicationDirectoryImpl() + { + QString appDir = CDirectoryUtils::applicationDirectoryPath().toLower(); + Q_ASSERT(appDir.size() > 0); + // Remove leading '/' on Unix + if (appDir.at(0) == '/') { appDir.remove(0, 1); } + const QRegularExpression re("[:\\\\\\/]"); + appDir = appDir.replace(re, "_"); + return appDir; + } + + const QString &CDirectoryUtils::normalizedApplicationDirectory() + { + static const QString appDir(normalizedApplicationDirectoryImpl()); + return appDir; + } + +} // ns + +//! \endcond diff --git a/src/blackmisc/directoryutils.h b/src/blackmisc/directoryutils.h new file mode 100644 index 000000000..04bc76a94 --- /dev/null +++ b/src/blackmisc/directoryutils.h @@ -0,0 +1,39 @@ +/* Copyright (C) 2016 + * swift project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +//! \file + +#ifndef BLACKMISC_DIRECTORYUTILS_H +#define BLACKMISC_DIRECTORYUTILS_H + +#include "blackmisc/blackmiscexport.h" + +#include + +namespace BlackMisc +{ + /*! + * Utility class for directory operations + */ + class BLACKMISC_EXPORT CDirectoryUtils + { + public: + //! Returns the directory of the application. In contrast to QCoreApplication::applicationDirPath() + //! it takes Mac OS X app bundles into account and returns the directory of the bundle. + static QString applicationDirectoryPath(); + + //! Returns the application directory of the calling executable as normalized string. + //! \note There is no trailing '/'. + //! \warning The normalization rules are implementation specific and could change over time. + static const QString &normalizedApplicationDirectory(); + }; + +} // ns + +#endif // guard diff --git a/src/blackmisc/settingscache.cpp b/src/blackmisc/settingscache.cpp index cdd05aea3..292886323 100644 --- a/src/blackmisc/settingscache.cpp +++ b/src/blackmisc/settingscache.cpp @@ -7,6 +7,7 @@ * contained in the LICENSE file. */ +#include "blackmisc/directoryutils.h" #include "blackmisc/logmessage.h" #include "blackmisc/settingscache.h" @@ -26,7 +27,10 @@ namespace BlackMisc const QString &CSettingsCache::persistentStore() { - static const QString dir = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/org.swift-project/settings/core"; + static const QString dir = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + + "/org.swift-project/" + + CDirectoryUtils::normalizedApplicationDirectory() + + "/settings/core"; return dir; } diff --git a/src/plugins/simulator/xplaneconfig/simulatorxplaneconfigwindow.cpp b/src/plugins/simulator/xplaneconfig/simulatorxplaneconfigwindow.cpp index d629a35ce..7d0f0dcaf 100644 --- a/src/plugins/simulator/xplaneconfig/simulatorxplaneconfigwindow.cpp +++ b/src/plugins/simulator/xplaneconfig/simulatorxplaneconfigwindow.cpp @@ -9,13 +9,13 @@ #include "simulatorxplaneconfigwindow.h" #include "blackcore/application.h" +#include "blackmisc/directoryutils.h" #include "blackmisc/dbusserver.h" #include "blackmisc/fileutils.h" #include "blackmisc/simulation/xplane/xplaneutil.h" #include "ui_simulatorxplaneconfigwindow.h" #include -#include #include #include #include @@ -28,12 +28,13 @@ class QWidget; using namespace BlackGui; +using namespace BlackMisc; namespace { QString xBusOriginDir() { - return sApp->applicationDirPath() % QStringLiteral("/../xbus"); + return CDirectoryUtils::applicationDirectoryPath() % QStringLiteral("/../xbus"); } }