migrate old DS config file to new path

This commit is contained in:
Stephen Birarda 2016-01-19 11:28:29 -08:00
parent de36f3eeb2
commit 74806d9d2b
3 changed files with 44 additions and 11 deletions

View file

@ -9,8 +9,11 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include "HifiConfigVariantMap.h"
#include <QtCore/QCoreApplication>
#include <QtCore/QDebug>
#include <QtCore/QDir>
#include <QtCore/QFile>
#include <QtCore/QJsonDocument>
#include <QtCore/QJsonArray>
@ -18,8 +21,8 @@
#include <QtCore/QStandardPaths>
#include <QtCore/QVariant>
#include "ServerPathUtils.h"
#include "SharedLogging.h"
#include "HifiConfigVariantMap.h"
QVariantMap HifiConfigVariantMap::mergeCLParametersWithJSONConfig(const QStringList& argumentList) {
@ -110,14 +113,43 @@ void HifiConfigVariantMap::loadMasterAndUserConfig(const QStringList& argumentLi
// load the user config
const QString USER_CONFIG_FILE_OPTION = "--user-config";
static const QString USER_CONFIG_FILE_NAME = "config.json";
int userConfigIndex = argumentList.indexOf(USER_CONFIG_FILE_OPTION);
if (userConfigIndex != -1) {
_userConfigFilename = argumentList[userConfigIndex + 1];
} else {
_userConfigFilename = QString("%1/%2/%3/config.json").arg(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation),
QCoreApplication::organizationName(),
QCoreApplication::applicationName());
// we weren't passed a user config path
_userConfigFilename = ServerPathUtils::getDataFilePath(USER_CONFIG_FILE_NAME);
// as of 1/19/2016 this path was moved
// figure out what the old path was
auto oldConfigFilename = QString("%1/%2/%3/%4").arg(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation),
QCoreApplication::organizationName(),
QCoreApplication::applicationName(),
USER_CONFIG_FILE_NAME);
// check if there's already a config file at the new path
QFile newConfigFile { _userConfigFilename };
if (!newConfigFile.exists()) {
QFile oldConfigFile { oldConfigFilename };
if (oldConfigFile.exists()) {
// we have the old file and not the new file - time to copy the file
// make the destination directory if it doesn't exist
QDir().mkdir(ServerPathUtils::getDataDirectory());
if (oldConfigFile.copy(_userConfigFilename)) {
qDebug() << "Migrated config file from" << oldConfigFilename << "to" << _userConfigFilename;
} else {
qWarning() << "Could not copy previous config file from" << oldConfigFilename << "to" << _userConfigFilename
<< "- please try to copy manually and restart.";
}
}
}
}
loadMapFromJSONFile(_userConfig, _userConfigFilename);

View file

@ -13,6 +13,7 @@
#define hifi_HifiConfigVariantMap_h
#include <QtCore/QStringList>
#include <QtCore/QVariantMap>
class HifiConfigVariantMap {
public:

View file

@ -16,19 +16,19 @@
#include <QDebug>
QString ServerPathUtils::getDataDirectory() {
auto homeDirectory = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation));
auto dataPath = QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
#ifdef Q_OS_WIN
homeDirectory.cd("AppData/Roaming/");
#elif Q_OS_OSX
homeDirectory.cd("Library/Application Support/");
dataPath += "/AppData/Roaming/";
#elif defined(Q_OS_OSX)
dataPath += "/Library/Application Support/";
#else
homeDirectory.cd(".local/share/");
dataPath += "/.local/share/";
#endif
homeDirectory.cd(qApp->organizationName() + "/" + qApp->applicationName());
dataPath += qApp->organizationName() + "/" + qApp->applicationName();
return homeDirectory.absolutePath();
return QDir::cleanPath(dataPath);
}
QString ServerPathUtils::getDataFilePath(QString filename) {