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

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