Write settings, logs, cache, etc. into a installation dependent subfolder

refs #668
This commit is contained in:
Roland Winklmeier
2016-06-03 13:31:03 +02:00
parent 2a99bed0cd
commit 4180a890e4
10 changed files with 117 additions and 23 deletions

View File

@@ -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;
}

View 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

View 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

View File

@@ -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;
}