mirror of
https://github.com/overte-org/overte.git
synced 2025-04-08 05:52:38 +02:00
use QStandardPaths instead of hardcoded paths
This commit is contained in:
parent
463f6454f8
commit
808973d7d2
8 changed files with 24 additions and 35 deletions
|
@ -162,7 +162,7 @@ void AssetServer::completeSetup() {
|
|||
if (assetsPath.isRelative()) {
|
||||
// if the domain settings passed us a relative path, make an absolute path that is relative to the
|
||||
// default data directory
|
||||
absoluteFilePath = PathUtils::getDataFilePath("assets/" + assetsPathString);
|
||||
absoluteFilePath = PathUtils::getAppDataFilePath("assets/" + assetsPathString);
|
||||
}
|
||||
|
||||
_resourcesDirectory = QDir(absoluteFilePath);
|
||||
|
|
|
@ -279,8 +279,7 @@ OctreeServer::~OctreeServer() {
|
|||
|
||||
void OctreeServer::initHTTPManager(int port) {
|
||||
// setup the embedded web server
|
||||
|
||||
QString documentRoot = QString("%1/web").arg(PathUtils::getDataDirectory());
|
||||
QString documentRoot = QString("%1/web").arg(PathUtils::getAppDataPath());
|
||||
|
||||
// setup an httpManager with us as the request handler and the parent
|
||||
_httpManager = new HTTPManager(QHostAddress::AnyIPv4, port, documentRoot, this, this);
|
||||
|
@ -1179,7 +1178,7 @@ void OctreeServer::domainSettingsRequestComplete() {
|
|||
if (persistPath.isRelative()) {
|
||||
// if the domain settings passed us a relative path, make an absolute path that is relative to the
|
||||
// default data directory
|
||||
persistAbsoluteFilePath = QDir(PathUtils::getDataFilePath("entities/")).absoluteFilePath(_persistFilePath);
|
||||
persistAbsoluteFilePath = QDir(PathUtils::getAppDataFilePath("entities/")).absoluteFilePath(_persistFilePath);
|
||||
}
|
||||
|
||||
static const QString ENTITY_PERSIST_EXTENSION = ".json.gz";
|
||||
|
@ -1245,7 +1244,7 @@ void OctreeServer::domainSettingsRequestComplete() {
|
|||
QDir backupDirectory { _backupDirectoryPath };
|
||||
QString absoluteBackupDirectory;
|
||||
if (backupDirectory.isRelative()) {
|
||||
absoluteBackupDirectory = QDir(PathUtils::getDataFilePath("entities/")).absoluteFilePath(_backupDirectoryPath);
|
||||
absoluteBackupDirectory = QDir(PathUtils::getAppDataFilePath("entities/")).absoluteFilePath(_backupDirectoryPath);
|
||||
absoluteBackupDirectory = QDir(absoluteBackupDirectory).absolutePath();
|
||||
} else {
|
||||
absoluteBackupDirectory = backupDirectory.absolutePath();
|
||||
|
|
|
@ -1618,7 +1618,7 @@ QJsonObject DomainServer::jsonObjectForNode(const SharedNodePointer& node) {
|
|||
QDir pathForAssignmentScriptsDirectory() {
|
||||
static const QString SCRIPTS_DIRECTORY_NAME = "/scripts/";
|
||||
|
||||
QDir directory(PathUtils::getDataDirectory() + SCRIPTS_DIRECTORY_NAME);
|
||||
QDir directory(PathUtils::getAppDataPath() + SCRIPTS_DIRECTORY_NAME);
|
||||
if (!directory.exists()) {
|
||||
directory.mkpath(".");
|
||||
qInfo() << "Created path to " << directory.path();
|
||||
|
|
|
@ -1439,7 +1439,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo
|
|||
scriptEngines->loadScript(testScript, false);
|
||||
} else {
|
||||
// Get sandbox content set version, if available
|
||||
auto acDirPath = PathUtils::getRootDataDirectory() + BuildInfo::MODIFIED_ORGANIZATION + "/assignment-client/";
|
||||
auto acDirPath = PathUtils::getAppDataPath() + "../../" + BuildInfo::MODIFIED_ORGANIZATION + "/assignment-client/";
|
||||
auto contentVersionPath = acDirPath + "content-version.txt";
|
||||
qCDebug(interfaceapp) << "Checking " << contentVersionPath << " for content version";
|
||||
auto contentVersion = 0;
|
||||
|
|
|
@ -46,7 +46,7 @@ FileCache::FileCache(const std::string& dirname, const std::string& ext, QObject
|
|||
QObject(parent),
|
||||
_ext(ext),
|
||||
_dirname(dirname),
|
||||
_dirpath(PathUtils::getDataFilePath(dirname.c_str(), false).toStdString()) {}
|
||||
_dirpath(PathUtils::getAppLocalDataFilePath(dirname.c_str()).toStdString()) {}
|
||||
|
||||
FileCache::~FileCache() {
|
||||
clear();
|
||||
|
|
|
@ -127,7 +127,7 @@ void HifiConfigVariantMap::loadConfig(const QStringList& argumentList) {
|
|||
_userConfigFilename = argumentList[userConfigIndex + 1];
|
||||
} else {
|
||||
// we weren't passed a user config path
|
||||
_userConfigFilename = PathUtils::getDataFilePath(USER_CONFIG_FILE_NAME);
|
||||
_userConfigFilename = PathUtils::getAppDataFilePath(USER_CONFIG_FILE_NAME);
|
||||
|
||||
// as of 1/19/2016 this path was moved so we attempt a migration for first run post migration here
|
||||
|
||||
|
@ -153,7 +153,7 @@ void HifiConfigVariantMap::loadConfig(const QStringList& argumentList) {
|
|||
// we have the old file and not the new file - time to copy the file
|
||||
|
||||
// make the destination directory if it doesn't exist
|
||||
auto dataDirectory = PathUtils::getDataDirectory();
|
||||
auto dataDirectory = PathUtils::getAppDataPath();
|
||||
if (QDir().mkpath(dataDirectory)) {
|
||||
if (oldConfigFile.copy(_userConfigFilename)) {
|
||||
qCDebug(shared) << "Migrated config file from" << oldConfigFilename << "to" << _userConfigFilename;
|
||||
|
|
|
@ -30,32 +30,20 @@ const QString& PathUtils::resourcesPath() {
|
|||
return staticResourcePath;
|
||||
}
|
||||
|
||||
QString PathUtils::getRootDataDirectory(bool roaming) {
|
||||
auto dataPath = QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
if (roaming) {
|
||||
dataPath += "/AppData/Roaming/";
|
||||
} else {
|
||||
dataPath += "/AppData/Local/";
|
||||
}
|
||||
#elif defined(Q_OS_OSX)
|
||||
dataPath += "/Library/Application Support/";
|
||||
#else
|
||||
dataPath += "/.local/share/";
|
||||
#endif
|
||||
|
||||
return dataPath;
|
||||
QString PathUtils::getAppDataPath() {
|
||||
return QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/";
|
||||
}
|
||||
|
||||
QString PathUtils::getDataDirectory(bool roaming) {
|
||||
auto dataPath = getRootDataDirectory(roaming);
|
||||
dataPath += qApp->organizationName() + "/" + qApp->applicationName();
|
||||
return QDir::cleanPath(dataPath);
|
||||
QString PathUtils::getAppLocalDataPath() {
|
||||
return QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + "/";
|
||||
}
|
||||
|
||||
QString PathUtils::getDataFilePath(QString filename, bool roaming) {
|
||||
return QDir(getDataDirectory(roaming)).absoluteFilePath(filename);
|
||||
QString PathUtils::getAppDataFilePath(const QString& filename) {
|
||||
return QDir(getAppDataPath()).absoluteFilePath(filename);
|
||||
}
|
||||
|
||||
QString PathUtils::getAppLocalDataFilePath(const QString& filename) {
|
||||
return QDir(getAppLocalDataPath()).absoluteFilePath(filename);
|
||||
}
|
||||
|
||||
QString fileNameWithoutExtension(const QString& fileName, const QVector<QString> possibleExtensions) {
|
||||
|
|
|
@ -27,10 +27,12 @@ class PathUtils : public QObject, public Dependency {
|
|||
Q_PROPERTY(QString resources READ resourcesPath)
|
||||
public:
|
||||
static const QString& resourcesPath();
|
||||
static QString getRootDataDirectory(bool roaming = true);
|
||||
|
||||
static QString getDataDirectory(bool roaming = true);
|
||||
static QString getDataFilePath(QString filename, bool roaming = true);
|
||||
static QString getAppDataPath();
|
||||
static QString getAppLocalDataPath();
|
||||
|
||||
static QString getAppDataFilePath(const QString& filename);
|
||||
static QString getAppLocalDataFilePath(const QString& filename);
|
||||
|
||||
static Qt::CaseSensitivity getFSCaseSensitivity();
|
||||
static QString stripFilename(const QUrl& url);
|
||||
|
|
Loading…
Reference in a new issue