move resource paths to PathUtils

This commit is contained in:
Zach Pomerantz 2017-03-12 20:44:17 -04:00
parent 02189812da
commit 172a638ef0
11 changed files with 33 additions and 72 deletions

View file

@ -24,7 +24,7 @@
#include <QtCore/QString>
#include <SharedUtil.h>
#include <ServerPathUtils.h>
#include <PathUtils.h>
#include "NetworkLogging.h"
#include "NodeType.h"
@ -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 = ServerPathUtils::getDataFilePath("assets/" + assetsPathString);
absoluteFilePath = PathUtils::getDataFilePath("assets/" + assetsPathString);
}
_resourcesDirectory = QDir(absoluteFilePath);

View file

@ -29,7 +29,7 @@
#include "OctreeQueryNode.h"
#include "OctreeServerConsts.h"
#include <QtCore/QStandardPaths>
#include <ServerPathUtils.h>
#include <PathUtils.h>
#include <QtCore/QDir>
int OctreeServer::_clientCount = 0;
@ -280,7 +280,7 @@ OctreeServer::~OctreeServer() {
void OctreeServer::initHTTPManager(int port) {
// setup the embedded web server
QString documentRoot = QString("%1/web").arg(ServerPathUtils::getDataDirectory());
QString documentRoot = QString("%1/web").arg(PathUtils::getDataDirectory());
// setup an httpManager with us as the request handler and the parent
_httpManager = new HTTPManager(QHostAddress::AnyIPv4, port, documentRoot, this, this);
@ -1179,7 +1179,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(ServerPathUtils::getDataFilePath("entities/")).absoluteFilePath(_persistFilePath);
persistAbsoluteFilePath = QDir(PathUtils::getDataFilePath("entities/")).absoluteFilePath(_persistFilePath);
}
static const QString ENTITY_PERSIST_EXTENSION = ".json.gz";
@ -1245,7 +1245,7 @@ void OctreeServer::domainSettingsRequestComplete() {
QDir backupDirectory { _backupDirectoryPath };
QString absoluteBackupDirectory;
if (backupDirectory.isRelative()) {
absoluteBackupDirectory = QDir(ServerPathUtils::getDataFilePath("entities/")).absoluteFilePath(_backupDirectoryPath);
absoluteBackupDirectory = QDir(PathUtils::getDataFilePath("entities/")).absoluteFilePath(_backupDirectoryPath);
absoluteBackupDirectory = QDir(absoluteBackupDirectory).absolutePath();
} else {
absoluteBackupDirectory = backupDirectory.absolutePath();

View file

@ -38,7 +38,7 @@
#include <ShutdownEventListener.h>
#include <UUID.h>
#include <LogHandler.h>
#include <ServerPathUtils.h>
#include <PathUtils.h>
#include <NumericalConstants.h>
#include "DomainServerNodeData.h"
@ -1618,7 +1618,7 @@ QJsonObject DomainServer::jsonObjectForNode(const SharedNodePointer& node) {
QDir pathForAssignmentScriptsDirectory() {
static const QString SCRIPTS_DIRECTORY_NAME = "/scripts/";
QDir directory(ServerPathUtils::getDataDirectory() + SCRIPTS_DIRECTORY_NAME);
QDir directory(PathUtils::getDataDirectory() + SCRIPTS_DIRECTORY_NAME);
if (!directory.exists()) {
directory.mkpath(".");
qInfo() << "Created path to " << directory.path();

View file

@ -35,8 +35,6 @@
#include <shared/NsightHelpers.h>
#include <Finally.h>
#include <PathUtils.h>
#include <ServerPathUtils.h>
#include "ModelNetworkingLogging.h"
#include <Trace.h>

View file

@ -12,7 +12,6 @@
#include "udt/PacketHeaders.h"
#include "SharedUtil.h"
#include "UUID.h"
#include "ServerPathUtils.h"
#include <QtCore/QDataStream>

View file

@ -18,7 +18,7 @@
#include <QDir>
#include <ServerPathUtils.h>
#include <PathUtils.h>
Q_LOGGING_CATEGORY(file_cache, "hifi.file_cache", QtWarningMsg)
@ -46,7 +46,7 @@ FileCache::FileCache(const std::string& dirname, const std::string& ext, QObject
QObject(parent),
_ext(ext),
_dirname(dirname),
_dirpath(ServerPathUtils::getDataFilePath(dirname.c_str()).toStdString()) {}
_dirpath(PathUtils::getDataFilePath(dirname.c_str()).toStdString()) {}
FileCache::~FileCache() {
clear();

View file

@ -21,7 +21,7 @@
#include <QtCore/QStandardPaths>
#include <QtCore/QVariant>
#include "ServerPathUtils.h"
#include "PathUtils.h"
#include "SharedLogging.h"
QVariantMap HifiConfigVariantMap::mergeCLParametersWithJSONConfig(const QStringList& argumentList) {
@ -127,7 +127,7 @@ void HifiConfigVariantMap::loadConfig(const QStringList& argumentList) {
_userConfigFilename = argumentList[userConfigIndex + 1];
} else {
// we weren't passed a user config path
_userConfigFilename = ServerPathUtils::getDataFilePath(USER_CONFIG_FILE_NAME);
_userConfigFilename = PathUtils::getDataFilePath(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 = ServerPathUtils::getDataDirectory();
auto dataDirectory = PathUtils::getDataDirectory();
if (QDir().mkpath(dataDirectory)) {
if (oldConfigFile.copy(_userConfigFilename)) {
qCDebug(shared) << "Migrated config file from" << oldConfigFilename << "to" << _userConfigFilename;

View file

@ -30,11 +30,15 @@ const QString& PathUtils::resourcesPath() {
return staticResourcePath;
}
QString PathUtils::getRootDataDirectory() {
QString PathUtils::getRootDataDirectory(bool roaming) {
auto dataPath = QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
#ifdef Q_OS_WIN
dataPath += "/AppData/Roaming/";
if (roaming) {
dataPath += "/AppData/Roaming/";
} else {
dataPath += "/AppData/Local/";
}
#elif defined(Q_OS_OSX)
dataPath += "/Library/Application Support/";
#else
@ -44,6 +48,16 @@ QString PathUtils::getRootDataDirectory() {
return dataPath;
}
QString PathUtils::getDataDirectory(bool roaming) {
auto dataPath = getRootDataDirectory(roaming);
dataPath += qApp->organizationName() + "/" + qApp->applicationName();
return QDir::cleanPath(dataPath);
}
QString PathUtils::getDataFilePath(QString filename, bool roaming) {
return QDir(getDataDirectory(roaming)).absoluteFilePath(filename);
}
QString fileNameWithoutExtension(const QString& fileName, const QVector<QString> possibleExtensions) {
QString fileNameLowered = fileName.toLower();
foreach (const QString possibleExtension, possibleExtensions) {

View file

@ -27,7 +27,10 @@ class PathUtils : public QObject, public Dependency {
Q_PROPERTY(QString resources READ resourcesPath)
public:
static const QString& resourcesPath();
static QString getRootDataDirectory();
static QString getRootDataDirectory(bool roaming = true);
static QString getDataDirectory(bool roaming = true);
static QString getDataFilePath(QString filename, bool roaming = true);
static Qt::CaseSensitivity getFSCaseSensitivity();
static QString stripFilename(const QUrl& url);

View file

@ -1,31 +0,0 @@
//
// ServerPathUtils.cpp
// libraries/shared/src
//
// Created by Ryan Huffman on 01/12/16.
// Copyright 2016 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include "ServerPathUtils.h"
#include <QStandardPaths>
#include <QtCore/QDir>
#include <QtWidgets/qapplication.h>
#include <QDebug>
#include "PathUtils.h"
QString ServerPathUtils::getDataDirectory() {
auto dataPath = PathUtils::getRootDataDirectory();
dataPath += qApp->organizationName() + "/" + qApp->applicationName();
return QDir::cleanPath(dataPath);
}
QString ServerPathUtils::getDataFilePath(QString filename) {
return QDir(getDataDirectory()).absoluteFilePath(filename);
}

View file

@ -1,22 +0,0 @@
//
// ServerPathUtils.h
// libraries/shared/src
//
// Created by Ryan Huffman on 01/12/16.
// Copyright 2016 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#ifndef hifi_ServerPathUtils_h
#define hifi_ServerPathUtils_h
#include <QString>
namespace ServerPathUtils {
QString getDataDirectory();
QString getDataFilePath(QString filename);
}
#endif // hifi_ServerPathUtils_h