diff --git a/config/schemas/settings.json b/config/schemas/settings.json index fce13a61b..9764bef9f 100644 --- a/config/schemas/settings.json +++ b/config/schemas/settings.json @@ -8,6 +8,7 @@ { "general" : { "type" : "object", + "default": {}, "required" : [ "classicCreatureWindow", "playerName", "showfps", "music", "sound" ], "properties" : { "classicCreatureWindow" : { @@ -34,6 +35,7 @@ }, "video" : { "type" : "object", + "default": {}, "required" : [ "screenRes", "bitsPerPixel", "fullscreen" ], "properties" : { "screenRes" : { @@ -57,6 +59,7 @@ }, "adventure" : { "type" : "object", + "default": {}, "required" : [ "heroSpeed", "enemySpeed", "scrollSpeed", "heroReminder" ], "properties" : { "heroSpeed" : { @@ -79,6 +82,7 @@ }, "battle" : { "type" : "object", + "default": {}, "required" : [ "animationSpeed", "mouseShadow", "cellBorders", "stackRange", "showQueue" ], "properties" : { "animationSpeed" : { @@ -105,6 +109,7 @@ }, "server" : { "type" : "object", + "default": {}, "required" : [ "server", "port", "localInformation", "playerAI", "neutralAI" ], "properties" : { "server" : { diff --git a/lib/CConfigHandler.cpp b/lib/CConfigHandler.cpp index 04586ac4f..02936f044 100644 --- a/lib/CConfigHandler.cpp +++ b/lib/CConfigHandler.cpp @@ -57,8 +57,13 @@ SettingsStorage::SettingsStorage(): void SettingsStorage::init() { - CResourceHandler::get()->createResource("config/settings.json"); - JsonNode(ResourceID("config/settings.json")).swap(config); + std::string confName = "config/settings.json"; + + // Porbably new install. Create initial configuration + if (!CResourceHandler::get()->existsResource(ResourceID(confName))) + CResourceHandler::get()->createResource(confName); + else + JsonNode(ResourceID("config/settings.json")).swap(config); JsonUtils::maximize(config, "vcmi:settings"); JsonUtils::validate(config, "vcmi:settings", "settings"); diff --git a/lib/CModHandler.cpp b/lib/CModHandler.cpp index 998cf0a42..874126f3c 100644 --- a/lib/CModHandler.cpp +++ b/lib/CModHandler.cpp @@ -229,7 +229,17 @@ std::vector CModHandler::resolveDependencies(std::vector input void CModHandler::initialize(std::vector availableMods) { - JsonNode modConfig(ResourceID("config/modSettings.json")); + std::string confName = "config/modSettings.json"; + JsonNode modConfig; + + // Porbably new install. Create initial configuration + if (!CResourceHandler::get()->existsResource(ResourceID(confName))) + CResourceHandler::get()->createResource(confName); + else + modConfig = JsonNode(ResourceID(confName)); + + CResourceHandler::get()->createResource("config/modSettings.json"); + const JsonNode & modList = modConfig["activeMods"]; JsonNode resultingList; diff --git a/lib/JsonNode.cpp b/lib/JsonNode.cpp index 9940f3835..26cf48c70 100644 --- a/lib/JsonNode.cpp +++ b/lib/JsonNode.cpp @@ -1080,14 +1080,19 @@ std::string JsonValidator::fail(const std::string &message) { std::string errors; errors += "At "; - BOOST_FOREACH(const JsonNode &path, currentPath) + if (!currentPath.empty()) { - errors += "/"; - if (path.getType() == JsonNode::DATA_STRING) - errors += path.String(); - else - errors += boost::lexical_cast(static_cast(path.Float())); + BOOST_FOREACH(const JsonNode &path, currentPath) + { + errors += "/"; + if (path.getType() == JsonNode::DATA_STRING) + errors += path.String(); + else + errors += boost::lexical_cast(static_cast(path.Float())); + } } + else + errors += ""; errors += "\n\t Error: " + message + "\n"; return errors; }