1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

properly initialize settings when configuration was not found

This commit is contained in:
Ivan Savenko 2013-04-02 21:39:32 +00:00
parent c927913f5f
commit 0307639c32
4 changed files with 34 additions and 9 deletions

View File

@ -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" : {

View File

@ -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");

View File

@ -229,7 +229,17 @@ std::vector <TModID> CModHandler::resolveDependencies(std::vector <TModID> input
void CModHandler::initialize(std::vector<std::string> 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;

View File

@ -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<std::string>(static_cast<unsigned>(path.Float()));
BOOST_FOREACH(const JsonNode &path, currentPath)
{
errors += "/";
if (path.getType() == JsonNode::DATA_STRING)
errors += path.String();
else
errors += boost::lexical_cast<std::string>(static_cast<unsigned>(path.Float()));
}
}
else
errors += "<root>";
errors += "\n\t Error: " + message + "\n";
return errors;
}