Migrate the DS config version to the config file

This commit is contained in:
Atlante45 2017-10-31 16:09:26 -07:00
parent b8370128ce
commit 7616fe193c
5 changed files with 42 additions and 32 deletions

View file

@ -29,6 +29,7 @@
#include <NLPacketList.h> #include <NLPacketList.h>
#include <NumericalConstants.h> #include <NumericalConstants.h>
#include <SettingHandle.h> #include <SettingHandle.h>
#include <SettingHelpers.h>
#include <AvatarData.h> //for KillAvatarReason #include <AvatarData.h> //for KillAvatarReason
#include <FingerprintUtils.h> #include <FingerprintUtils.h>
#include "DomainServerNodeData.h" #include "DomainServerNodeData.h"
@ -43,12 +44,7 @@ const QString DESCRIPTION_COLUMNS_KEY = "columns";
const QString SETTINGS_VIEWPOINT_KEY = "viewpoint"; const QString SETTINGS_VIEWPOINT_KEY = "viewpoint";
static Setting::Handle<double> JSON_SETTING_VERSION("json-settings/version", 0.0); DomainServerSettingsManager::DomainServerSettingsManager() {
DomainServerSettingsManager::DomainServerSettingsManager() :
_descriptionArray(),
_configMap()
{
// load the description object from the settings description // load the description object from the settings description
QFile descriptionFile(QCoreApplication::applicationDirPath() + SETTINGS_DESCRIPTION_RELATIVE_PATH); QFile descriptionFile(QCoreApplication::applicationDirPath() + SETTINGS_DESCRIPTION_RELATIVE_PATH);
descriptionFile.open(QIODevice::ReadOnly); descriptionFile.open(QIODevice::ReadOnly);
@ -102,9 +98,32 @@ void DomainServerSettingsManager::setupConfigMap(const QStringList& argumentList
_configMap.loadConfig(_argumentList); _configMap.loadConfig(_argumentList);
static const auto VERSION_SETTINGS_KEYPATH = "version";
QVariant* versionVariant = _configMap.valueForKeyPath(VERSION_SETTINGS_KEYPATH);
if (!versionVariant) {
versionVariant = _configMap.valueForKeyPath(VERSION_SETTINGS_KEYPATH, true);
*versionVariant = _descriptionVersion;
persistToFile();
qDebug() << "No version in config file, setting to current version" << _descriptionVersion;
}
{
// Backward compatibility migration code
// The config version used to be stored in a different file
// This moves it to the actual config file.
Setting::Handle<double> JSON_SETTING_VERSION("json-settings/version", 0.0);
if (JSON_SETTING_VERSION.isSet()) {
auto version = JSON_SETTING_VERSION.get();
*versionVariant = version;
persistToFile();
QFile::remove(settingsFilename());
}
}
// What settings version were we before and what are we using now? // What settings version were we before and what are we using now?
// Do we need to do any re-mapping? // Do we need to do any re-mapping?
double oldVersion = JSON_SETTING_VERSION.get(); double oldVersion = versionVariant->toDouble();
if (oldVersion != _descriptionVersion) { if (oldVersion != _descriptionVersion) {
const QString ALLOWED_USERS_SETTINGS_KEYPATH = "security.allowed_users"; const QString ALLOWED_USERS_SETTINGS_KEYPATH = "security.allowed_users";
@ -136,9 +155,6 @@ void DomainServerSettingsManager::setupConfigMap(const QStringList& argumentList
QVariant* restrictedAccess = _configMap.valueForKeyPath(RESTRICTED_ACCESS_SETTINGS_KEYPATH, true); QVariant* restrictedAccess = _configMap.valueForKeyPath(RESTRICTED_ACCESS_SETTINGS_KEYPATH, true);
*restrictedAccess = QVariant(true); *restrictedAccess = QVariant(true);
// write the new settings to the json file
persistToFile();
} }
} }
@ -168,9 +184,6 @@ void DomainServerSettingsManager::setupConfigMap(const QStringList& argumentList
*entityServerVariant = entityServerMap; *entityServerVariant = entityServerMap;
} }
// write the new settings to the json file
persistToFile();
} }
} }
@ -188,9 +201,6 @@ void DomainServerSettingsManager::setupConfigMap(const QStringList& argumentList
qDebug() << "Migrating plaintext password to SHA256 hash in domain-server settings."; qDebug() << "Migrating plaintext password to SHA256 hash in domain-server settings.";
*passwordVariant = QCryptographicHash::hash(plaintextPassword.toUtf8(), QCryptographicHash::Sha256).toHex(); *passwordVariant = QCryptographicHash::hash(plaintextPassword.toUtf8(), QCryptographicHash::Sha256).toHex();
// write the new settings to file
persistToFile();
} }
} }
@ -293,16 +303,16 @@ void DomainServerSettingsManager::setupConfigMap(const QStringList& argumentList
QVariant* wizardCompletedOnce = _configMap.valueForKeyPath(WIZARD_COMPLETED_ONCE, true); QVariant* wizardCompletedOnce = _configMap.valueForKeyPath(WIZARD_COMPLETED_ONCE, true);
*wizardCompletedOnce = QVariant(true); *wizardCompletedOnce = QVariant(true);
// write the new settings to the json file
persistToFile();
} }
// write the current description version to our settings
*versionVariant = _descriptionVersion;
// write the new settings to the json file
persistToFile();
} }
unpackPermissions(); unpackPermissions();
// write the current description version to our settings
JSON_SETTING_VERSION.set(_descriptionVersion);
} }
QVariantMap& DomainServerSettingsManager::getDescriptorsMap() { QVariantMap& DomainServerSettingsManager::getDescriptorsMap() {

View file

@ -91,12 +91,6 @@ QVariantMap HifiConfigVariantMap::mergeCLParametersWithJSONConfig(const QStringL
return mergedMap; return mergedMap;
} }
HifiConfigVariantMap::HifiConfigVariantMap() :
_userConfigFilename()
{
}
void HifiConfigVariantMap::loadConfig(const QStringList& argumentList) { void HifiConfigVariantMap::loadConfig(const QStringList& argumentList) {
// load the user config // load the user config
const QString USER_CONFIG_FILE_OPTION = "--user-config"; const QString USER_CONFIG_FILE_OPTION = "--user-config";

View file

@ -21,7 +21,6 @@ class HifiConfigVariantMap {
public: public:
static QVariantMap mergeCLParametersWithJSONConfig(const QStringList& argumentList); static QVariantMap mergeCLParametersWithJSONConfig(const QStringList& argumentList);
HifiConfigVariantMap();
void loadConfig(const QStringList& argumentList); void loadConfig(const QStringList& argumentList);
const QVariant value(const QString& key) const { return _userConfig.value(key); } const QVariant value(const QString& key) const { return _userConfig.value(key); }

View file

@ -23,9 +23,15 @@
#include "SharedLogging.h" #include "SharedLogging.h"
const QSettings::Format JSON_FORMAT = QSettings::registerFormat("json", readJSONFile, writeJSONFile);
QSettings::SettingsMap jsonDocumentToVariantMap(const QJsonDocument& document); QSettings::SettingsMap jsonDocumentToVariantMap(const QJsonDocument& document);
QJsonDocument variantMapToJsonDocument(const QSettings::SettingsMap& map); QJsonDocument variantMapToJsonDocument(const QSettings::SettingsMap& map);
QString settingsFilename() {
return QSettings().fileName();
}
bool readJSONFile(QIODevice& device, QSettings::SettingsMap& map) { bool readJSONFile(QIODevice& device, QSettings::SettingsMap& map) {
QJsonParseError jsonParseError; QJsonParseError jsonParseError;

View file

@ -14,12 +14,13 @@
#include <QSettings> #include <QSettings>
extern const QSettings::Format JSON_FORMAT;
QString settingsFilename();
bool readJSONFile(QIODevice& device, QSettings::SettingsMap& map); bool readJSONFile(QIODevice& device, QSettings::SettingsMap& map);
bool writeJSONFile(QIODevice& device, const QSettings::SettingsMap& map); bool writeJSONFile(QIODevice& device, const QSettings::SettingsMap& map);
static const auto JSON_FORMAT = QSettings::registerFormat("json", readJSONFile, writeJSONFile);
void loadOldINIFile(QSettings& settings); void loadOldINIFile(QSettings& settings);
#endif // hifi_SettingHelpers_h #endif // hifi_SettingHelpers_h