diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index be842016d0..728d46d7ca 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -74,6 +74,8 @@ QString DomainServer::_iceServerAddr { ICE_SERVER_DEFAULT_HOSTNAME }; int DomainServer::_iceServerPort { ICE_SERVER_DEFAULT_PORT }; bool DomainServer::_overrideDomainID { false }; QUuid DomainServer::_overridingDomainID; +bool DomainServer::_getTempName { false }; +QString DomainServer::_userConfigFilename; int DomainServer::_parentPID { -1 }; bool DomainServer::forwardMetaverseAPIRequest(HTTPConnection* connection, @@ -181,9 +183,16 @@ DomainServer::DomainServer(int argc, char* argv[]) : // (need this since domain-server can restart itself and maintain static variables) DependencyManager::set(); - auto args = arguments(); - - _settingsManager.setupConfigMap(args); + // load the user config + QString userConfigFilename; + if (!_userConfigFilename.isEmpty()) { + userConfigFilename = _userConfigFilename; + } else { + // we weren't passed a user config path + static const QString USER_CONFIG_FILE_NAME = "config.json"; + userConfigFilename = PathUtils::getAppDataFilePath(USER_CONFIG_FILE_NAME); + } + _settingsManager.setupConfigMap(userConfigFilename); // setup a shutdown event listener to handle SIGTERM or WM_CLOSE for us #ifdef _WIN32 @@ -242,8 +251,7 @@ DomainServer::DomainServer(int argc, char* argv[]) : } // check for the temporary name parameter - const QString GET_TEMPORARY_NAME_SWITCH = "--get-temp-name"; - if (args.contains(GET_TEMPORARY_NAME_SWITCH)) { + if (_getTempName) { getTemporaryName(); } @@ -321,14 +329,14 @@ void DomainServer::parseCommandLine(int argc, char* argv[]) { const QCommandLineOption iceServerAddressOption("i", "ice-server address", "IP:PORT or HOSTNAME:PORT"); parser.addOption(iceServerAddressOption); - const QCommandLineOption domainIDOption("d", "domain-server uuid"); + const QCommandLineOption domainIDOption("d", "domain-server uuid", "uuid"); parser.addOption(domainIDOption); const QCommandLineOption getTempNameOption("get-temp-name", "Request a temporary domain-name"); parser.addOption(getTempNameOption); - const QCommandLineOption masterConfigOption("master-config", "Deprecated config-file option"); - parser.addOption(masterConfigOption); + const QCommandLineOption userConfigOption("user-config", "Pass user config file pass", "path"); + parser.addOption(userConfigOption); const QCommandLineOption parentPIDOption(PARENT_PID_OPTION, "PID of the parent process", "parent-pid"); parser.addOption(parentPIDOption); @@ -377,6 +385,13 @@ void DomainServer::parseCommandLine(int argc, char* argv[]) { qDebug() << "domain-server ID is" << _overridingDomainID; } + if (parser.isSet(getTempNameOption)) { + _getTempName = true; + } + + if (parser.isSet(userConfigOption)) { + _userConfigFilename = parser.value(userConfigOption); + } if (parser.isSet(parentPIDOption)) { bool ok = false; diff --git a/domain-server/src/DomainServer.h b/domain-server/src/DomainServer.h index 7e96787371..e2bddc1aa5 100644 --- a/domain-server/src/DomainServer.h +++ b/domain-server/src/DomainServer.h @@ -270,6 +270,8 @@ private: static int _iceServerPort; static bool _overrideDomainID; // should we override the domain-id from settings? static QUuid _overridingDomainID; // what should we override it with? + static bool _getTempName; + static QString _userConfigFilename; static int _parentPID; bool _sendICEServerAddressToMetaverseAPIInProgress { false }; diff --git a/domain-server/src/DomainServerSettingsManager.cpp b/domain-server/src/DomainServerSettingsManager.cpp index 2bcaa8899e..780fad15f2 100644 --- a/domain-server/src/DomainServerSettingsManager.cpp +++ b/domain-server/src/DomainServerSettingsManager.cpp @@ -191,13 +191,12 @@ void DomainServerSettingsManager::processSettingsRequestPacket(QSharedPointersendPacketList(std::move(packetList), message->getSenderSockAddr()); } -void DomainServerSettingsManager::setupConfigMap(const QStringList& argumentList) { +void DomainServerSettingsManager::setupConfigMap(const QString& userConfigFilename) { // since we're called from the DomainServerSettingsManager constructor, we don't take a write lock here // even though we change the underlying config map - _argumentList = argumentList; - - _configMap.loadConfig(_argumentList); + _configMap.setUserConfigFilename(userConfigFilename); + _configMap.loadConfig(); static const auto VERSION_SETTINGS_KEYPATH = "version"; QVariant* versionVariant = _configMap.valueForKeyPath(VERSION_SETTINGS_KEYPATH); @@ -1736,7 +1735,7 @@ void DomainServerSettingsManager::persistToFile() { // failed to write, reload whatever the current config state is // with a write lock since we're about to overwrite the config map QWriteLocker locker(&_settingsLock); - _configMap.loadConfig(_argumentList); + _configMap.loadConfig(); } } diff --git a/domain-server/src/DomainServerSettingsManager.h b/domain-server/src/DomainServerSettingsManager.h index bcd33c2bb0..2020561205 100644 --- a/domain-server/src/DomainServerSettingsManager.h +++ b/domain-server/src/DomainServerSettingsManager.h @@ -49,7 +49,7 @@ public: DomainServerSettingsManager(); bool handleAuthenticatedHTTPRequest(HTTPConnection* connection, const QUrl& url); - void setupConfigMap(const QStringList& argumentList); + void setupConfigMap(const QString& userConfigFilename); // each of the three methods in this group takes a read lock of _settingsLock // and cannot be called when the a write lock is held by the same thread @@ -144,8 +144,6 @@ private slots: void processUsernameFromIDRequestPacket(QSharedPointer message, SharedNodePointer sendingNode); private: - QStringList _argumentList; - QJsonArray filteredDescriptionArray(bool isContentSettings); void updateSetting(const QString& key, const QJsonValue& newValue, QVariantMap& settingMap, const QJsonObject& settingDescription); diff --git a/libraries/shared/src/HifiConfigVariantMap.cpp b/libraries/shared/src/HifiConfigVariantMap.cpp index 59f660feee..91ec056f1a 100644 --- a/libraries/shared/src/HifiConfigVariantMap.cpp +++ b/libraries/shared/src/HifiConfigVariantMap.cpp @@ -91,58 +91,7 @@ QVariantMap HifiConfigVariantMap::mergeCLParametersWithJSONConfig(const QStringL return mergedMap; } -void HifiConfigVariantMap::loadConfig(const QStringList& argumentList) { - // 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 { - // we weren't passed a user config path - _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 - - // figure out what the old path was - - // if our build version is "dev" we should migrate from a different organization folder - - auto oldConfigFilename = QString("%1/%2/%3/%4").arg(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation), - QCoreApplication::organizationName(), - QCoreApplication::applicationName(), - USER_CONFIG_FILE_NAME); - - oldConfigFilename = oldConfigFilename.replace("High Fidelity - dev", "High Fidelity"); - - - // 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 - auto dataDirectory = PathUtils::getAppDataPath(); - if (QDir().mkpath(dataDirectory)) { - if (oldConfigFile.copy(_userConfigFilename)) { - qCDebug(shared) << "Migrated config file from" << oldConfigFilename << "to" << _userConfigFilename; - } else { - qCWarning(shared) << "Could not copy previous config file from" << oldConfigFilename << "to" << _userConfigFilename - << "- please try to copy manually and restart."; - } - } else { - qCWarning(shared) << "Could not create application data directory" << dataDirectory << "- unable to migrate previous config file."; - } - } - } - - } - +void HifiConfigVariantMap::loadConfig() { loadMapFromJSONFile(_userConfig, _userConfigFilename); } diff --git a/libraries/shared/src/HifiConfigVariantMap.h b/libraries/shared/src/HifiConfigVariantMap.h index ee248ec3d2..5725ae8f34 100644 --- a/libraries/shared/src/HifiConfigVariantMap.h +++ b/libraries/shared/src/HifiConfigVariantMap.h @@ -21,7 +21,7 @@ class HifiConfigVariantMap { public: static QVariantMap mergeCLParametersWithJSONConfig(const QStringList& argumentList); - void loadConfig(const QStringList& argumentList); + void loadConfig(); const QVariant value(const QString& key) const { return _userConfig.value(key); } QVariant* valueForKeyPath(const QString& keyPath, bool shouldCreateIfMissing = false) @@ -30,6 +30,7 @@ public: QVariantMap& getConfig() { return _userConfig; } const QString& getUserConfigFilename() const { return _userConfigFilename; } + void setUserConfigFilename(const QString& filename) { _userConfigFilename = filename; } private: QString _userConfigFilename;