mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 09:15:34 +08:00
Write settings, logs, cache, etc. into a installation dependent subfolder
refs #668
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
#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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user