From 74806d9d2bb08a1a6fbf91e3199a9eaad2400109 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 19 Jan 2016 11:28:29 -0800 Subject: [PATCH] migrate old DS config file to new path --- libraries/shared/src/HifiConfigVariantMap.cpp | 40 +++++++++++++++++-- libraries/shared/src/HifiConfigVariantMap.h | 1 + libraries/shared/src/ServerPathUtils.cpp | 14 +++---- 3 files changed, 44 insertions(+), 11 deletions(-) diff --git a/libraries/shared/src/HifiConfigVariantMap.cpp b/libraries/shared/src/HifiConfigVariantMap.cpp index 4f9a741aad..b8743c8dfc 100644 --- a/libraries/shared/src/HifiConfigVariantMap.cpp +++ b/libraries/shared/src/HifiConfigVariantMap.cpp @@ -9,8 +9,11 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include "HifiConfigVariantMap.h" + #include #include +#include #include #include #include @@ -18,8 +21,8 @@ #include #include +#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); diff --git a/libraries/shared/src/HifiConfigVariantMap.h b/libraries/shared/src/HifiConfigVariantMap.h index 75b8be1984..bf1e84dffc 100644 --- a/libraries/shared/src/HifiConfigVariantMap.h +++ b/libraries/shared/src/HifiConfigVariantMap.h @@ -13,6 +13,7 @@ #define hifi_HifiConfigVariantMap_h #include +#include class HifiConfigVariantMap { public: diff --git a/libraries/shared/src/ServerPathUtils.cpp b/libraries/shared/src/ServerPathUtils.cpp index 0f9ebabbbe..ca87a28610 100644 --- a/libraries/shared/src/ServerPathUtils.cpp +++ b/libraries/shared/src/ServerPathUtils.cpp @@ -16,19 +16,19 @@ #include 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) {