From b9ad2977de3e5f1c5bdfd6c6fe7835a7df19bec2 Mon Sep 17 00:00:00 2001 From: Paulchen-Panther Date: Thu, 18 Aug 2016 21:11:21 +0200 Subject: [PATCH] Update and fix JSON writer (#183) * Fixing the check of createKey in handleConfigSetCommand * Update schema-config.json * add overwrite option to configset command * add overwrite option to setConfig function * add overwrite option to setConfig function --- libsrc/jsonserver/JsonClientConnection.cpp | 5 +++-- libsrc/jsonserver/schema/schema-config.json | 3 +++ src/hyperion-remote/JsonConnection.cpp | 3 ++- src/hyperion-remote/JsonConnection.h | 2 +- src/hyperion-remote/hyperion-remote.cpp | 3 ++- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/libsrc/jsonserver/JsonClientConnection.cpp b/libsrc/jsonserver/JsonClientConnection.cpp index 568482f6..ab497bd4 100644 --- a/libsrc/jsonserver/JsonClientConnection.cpp +++ b/libsrc/jsonserver/JsonClientConnection.cpp @@ -931,8 +931,9 @@ void JsonClientConnection::handleConfigSetCommand(const Json::Value &message, co return; } - bool createKey = message.isMember("create"); - Json::Value hyperionConfig = _hyperion->getJsonConfig(); + bool createKey = message["create"].asBool(); + Json::Value hyperionConfig; + message["overwrite"].asBool() ? createKey = true : hyperionConfig = _hyperion->getJsonConfig(); nested::configSetCommand(message["config"], hyperionConfig, createKey); JsonFactory::writeJson(_hyperion->getConfigFileName(), hyperionConfig); diff --git a/libsrc/jsonserver/schema/schema-config.json b/libsrc/jsonserver/schema/schema-config.json index 6f6483b1..a1e28174 100644 --- a/libsrc/jsonserver/schema/schema-config.json +++ b/libsrc/jsonserver/schema/schema-config.json @@ -20,6 +20,9 @@ }, "create": { "type" : "boolean" + }, + "overwrite": { + "type" : "boolean" } }, "additionalProperties": false diff --git a/src/hyperion-remote/JsonConnection.cpp b/src/hyperion-remote/JsonConnection.cpp index c7dcf5f5..fb5446ba 100644 --- a/src/hyperion-remote/JsonConnection.cpp +++ b/src/hyperion-remote/JsonConnection.cpp @@ -268,7 +268,7 @@ QString JsonConnection::getConfig(std::string type) return QString(); } -void JsonConnection::setConfig(const std::string &jsonString, bool create) +void JsonConnection::setConfig(const std::string &jsonString, bool create, bool overwrite) { // create command Json::Value command; @@ -276,6 +276,7 @@ void JsonConnection::setConfig(const std::string &jsonString, bool create) command["subcommand"] = "setconfig"; command["create"] = create; + command["overwrite"] = overwrite; Json::Value & config = command["config"]; if (jsonString.size() > 0) { diff --git a/src/hyperion-remote/JsonConnection.h b/src/hyperion-remote/JsonConnection.h index b629a17b..71c16d20 100644 --- a/src/hyperion-remote/JsonConnection.h +++ b/src/hyperion-remote/JsonConnection.h @@ -114,7 +114,7 @@ public: /// @param jsonString The JSON String(s) to write /// @param create Specifies whether the nonexistent json string to be created /// - void setConfig(const std::string & jsonString, bool create); + void setConfig(const std::string & jsonString, bool create, bool overwrite); /// /// Set the color transform of the leds diff --git a/src/hyperion-remote/hyperion-remote.cpp b/src/hyperion-remote/hyperion-remote.cpp index 76742d05..c0af50e7 100644 --- a/src/hyperion-remote/hyperion-remote.cpp +++ b/src/hyperion-remote/hyperion-remote.cpp @@ -91,6 +91,7 @@ int main(int argc, char * argv[]) SwitchParameter<> & argSchemaGet = parameters.add >(0x0, "schemaGet" , "Print the json schema for Hyperion configuration"); StringParameter & argConfigSet = parameters.add('W', "configSet", "Write to the actual loaded configuration file. Should be a Json object string."); SwitchParameter<> & argCreate = parameters.add >(0x0, "createkeys", "Create non exist Json Entry(s) in the actual loaded configuration file. Argument to use in combination with configSet."); + SwitchParameter<> & argOverwriteConfig = parameters.add >(0x0, "overwrite", "Overwrite the actual loaded configuration file with the Json object string from configSet. Argument to use in combination with configSet."); // set the default values argAddress.setDefault(defaultServerAddress.toStdString()); @@ -219,7 +220,7 @@ int main(int argc, char * argv[]) } else if (argConfigSet.isSet()) { - connection.setConfig(argConfigSet.getValue(), argCreate.isSet()); + connection.setConfig(argConfigSet.getValue(), argCreate.isSet(), argOverwriteConfig.isSet()); } else if (colorModding) {