mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-05-06 02:16:04 +08:00
Write settings, logs, cache, etc. into a installation dependent subfolder
refs #668
This commit is contained in:
@@ -18,6 +18,7 @@
|
|||||||
#include "blackcore/webdataservices.h"
|
#include "blackcore/webdataservices.h"
|
||||||
#include "blackmisc/datacache.h"
|
#include "blackmisc/datacache.h"
|
||||||
#include "blackmisc/dbusserver.h"
|
#include "blackmisc/dbusserver.h"
|
||||||
|
#include "blackmisc/directoryutils.h"
|
||||||
#include "blackmisc/filelogger.h"
|
#include "blackmisc/filelogger.h"
|
||||||
#include "blackmisc/logcategory.h"
|
#include "blackmisc/logcategory.h"
|
||||||
#include "blackmisc/logcategorylist.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)
|
bool CApplication::useContexts(const CCoreFacadeConfig &coreConfig)
|
||||||
{
|
{
|
||||||
Q_ASSERT_X(this->m_parsed, Q_FUNC_INFO, "Call this function after parsing");
|
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!
|
CLogHandler::instance()->install(); // make sure we have a log handler!
|
||||||
|
|
||||||
// File logger
|
// 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.reset(new CFileLogger(executable(), logPath));
|
||||||
this->m_fileLogger->changeLogPattern(CLogPattern().withSeverityAtOrAbove(CStatusMessage::SeverityDebug));
|
this->m_fileLogger->changeLogPattern(CLogPattern().withSeverityAtOrAbove(CStatusMessage::SeverityDebug));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -172,10 +172,6 @@ namespace BlackCore
|
|||||||
//! Clear the caches
|
//! Clear the caches
|
||||||
static QStringList clearCaches();
|
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 ----------------------------------------
|
// ----------------------- parsing ----------------------------------------
|
||||||
|
|
||||||
//! \name parsing of command line options
|
//! \name parsing of command line options
|
||||||
|
|||||||
@@ -9,10 +9,10 @@
|
|||||||
|
|
||||||
#include "blackcore/pluginmanager.h"
|
#include "blackcore/pluginmanager.h"
|
||||||
#include "blackcore/application.h"
|
#include "blackcore/application.h"
|
||||||
|
#include "blackmisc/directoryutils.h"
|
||||||
#include "blackmisc/logmessage.h"
|
#include "blackmisc/logmessage.h"
|
||||||
#include "blackmisc/statusmessage.h"
|
#include "blackmisc/statusmessage.h"
|
||||||
|
|
||||||
#include <QCoreApplication>
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QDirIterator>
|
#include <QDirIterator>
|
||||||
#include <QJsonValue>
|
#include <QJsonValue>
|
||||||
@@ -55,7 +55,7 @@ namespace BlackCore
|
|||||||
|
|
||||||
QString IPluginManager::pluginDirectory() const
|
QString IPluginManager::pluginDirectory() const
|
||||||
{
|
{
|
||||||
return sApp->applicationDirPath() % QStringLiteral("/plugins");
|
return CDirectoryUtils::applicationDirectoryPath() % QStringLiteral("/plugins");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IPluginManager::isValid(const QJsonObject &metadata) const
|
bool IPluginManager::isValid(const QJsonObject &metadata) const
|
||||||
|
|||||||
@@ -10,8 +10,8 @@
|
|||||||
#include "blackcore/application.h"
|
#include "blackcore/application.h"
|
||||||
#include "blackcore/pluginmanagersimulator.h"
|
#include "blackcore/pluginmanagersimulator.h"
|
||||||
#include "blackcore/simulator.h"
|
#include "blackcore/simulator.h"
|
||||||
|
#include "blackmisc/directoryutils.h"
|
||||||
|
|
||||||
#include <QCoreApplication>
|
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
#include <QJsonValue>
|
#include <QJsonValue>
|
||||||
#include <QStringBuilder>
|
#include <QStringBuilder>
|
||||||
@@ -103,7 +103,7 @@ namespace BlackCore
|
|||||||
|
|
||||||
QString CPluginManagerSimulator::pluginDirectory() const
|
QString CPluginManagerSimulator::pluginDirectory() const
|
||||||
{
|
{
|
||||||
return sApp->applicationDirPath() % QStringLiteral("/plugins/simulator");
|
return CDirectoryUtils::applicationDirectoryPath() % QStringLiteral("/plugins/simulator");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,8 +10,8 @@
|
|||||||
#include "blackcore/application.h"
|
#include "blackcore/application.h"
|
||||||
#include "blackcore/pluginmanagerweatherdata.h"
|
#include "blackcore/pluginmanagerweatherdata.h"
|
||||||
#include "blackcore/weatherdata.h"
|
#include "blackcore/weatherdata.h"
|
||||||
|
#include "blackmisc/directoryutils.h"
|
||||||
|
|
||||||
#include <QCoreApplication>
|
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
#include <QJsonValue>
|
#include <QJsonValue>
|
||||||
#include <QStringBuilder>
|
#include <QStringBuilder>
|
||||||
@@ -67,7 +67,7 @@ namespace BlackCore
|
|||||||
|
|
||||||
QString CPluginManagerWeatherData::pluginDirectory() const
|
QString CPluginManagerWeatherData::pluginDirectory() const
|
||||||
{
|
{
|
||||||
return sApp->applicationDirPath() % QStringLiteral("/plugins/weatherdata");
|
return CDirectoryUtils::applicationDirectoryPath() % QStringLiteral("/plugins/weatherdata");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
#include "blackmisc/atomicfile.h"
|
#include "blackmisc/atomicfile.h"
|
||||||
#include "blackmisc/datacache.h"
|
#include "blackmisc/datacache.h"
|
||||||
|
#include "blackmisc/directoryutils.h"
|
||||||
#include "blackmisc/identifier.h"
|
#include "blackmisc/identifier.h"
|
||||||
#include "blackmisc/logmessage.h"
|
#include "blackmisc/logmessage.h"
|
||||||
|
|
||||||
@@ -99,7 +100,10 @@ namespace BlackMisc
|
|||||||
|
|
||||||
const QString &CDataCache::persistentStore()
|
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;
|
return dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
54
src/blackmisc/directoryutils.cpp
Normal file
54
src/blackmisc/directoryutils.cpp
Normal file
@@ -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 <QCoreApplication>
|
||||||
|
#include <QDir>
|
||||||
|
#include <QRegularExpression>
|
||||||
|
|
||||||
|
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
|
||||||
39
src/blackmisc/directoryutils.h
Normal file
39
src/blackmisc/directoryutils.h
Normal file
@@ -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 <QString>
|
||||||
|
|
||||||
|
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
|
||||||
@@ -7,6 +7,7 @@
|
|||||||
* contained in the LICENSE file.
|
* contained in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "blackmisc/directoryutils.h"
|
||||||
#include "blackmisc/logmessage.h"
|
#include "blackmisc/logmessage.h"
|
||||||
#include "blackmisc/settingscache.h"
|
#include "blackmisc/settingscache.h"
|
||||||
|
|
||||||
@@ -26,7 +27,10 @@ namespace BlackMisc
|
|||||||
|
|
||||||
const QString &CSettingsCache::persistentStore()
|
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;
|
return dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,13 +9,13 @@
|
|||||||
|
|
||||||
#include "simulatorxplaneconfigwindow.h"
|
#include "simulatorxplaneconfigwindow.h"
|
||||||
#include "blackcore/application.h"
|
#include "blackcore/application.h"
|
||||||
|
#include "blackmisc/directoryutils.h"
|
||||||
#include "blackmisc/dbusserver.h"
|
#include "blackmisc/dbusserver.h"
|
||||||
#include "blackmisc/fileutils.h"
|
#include "blackmisc/fileutils.h"
|
||||||
#include "blackmisc/simulation/xplane/xplaneutil.h"
|
#include "blackmisc/simulation/xplane/xplaneutil.h"
|
||||||
#include "ui_simulatorxplaneconfigwindow.h"
|
#include "ui_simulatorxplaneconfigwindow.h"
|
||||||
|
|
||||||
#include <QComboBox>
|
#include <QComboBox>
|
||||||
#include <QCoreApplication>
|
|
||||||
#include <QDialogButtonBox>
|
#include <QDialogButtonBox>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
@@ -28,12 +28,13 @@
|
|||||||
class QWidget;
|
class QWidget;
|
||||||
|
|
||||||
using namespace BlackGui;
|
using namespace BlackGui;
|
||||||
|
using namespace BlackMisc;
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
QString xBusOriginDir()
|
QString xBusOriginDir()
|
||||||
{
|
{
|
||||||
return sApp->applicationDirPath() % QStringLiteral("/../xbus");
|
return CDirectoryUtils::applicationDirectoryPath() % QStringLiteral("/../xbus");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user