mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	properly initialize settings when configuration was not found
This commit is contained in:
		| @@ -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" : { | ||||
|   | ||||
| @@ -57,7 +57,12 @@ SettingsStorage::SettingsStorage(): | ||||
|  | ||||
| void SettingsStorage::init() | ||||
| { | ||||
| 	CResourceHandler::get()->createResource("config/settings.json"); | ||||
| 	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"); | ||||
|   | ||||
| @@ -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; | ||||
|  | ||||
|   | ||||
| @@ -1080,6 +1080,8 @@ std::string JsonValidator::fail(const std::string &message) | ||||
| { | ||||
| 	std::string errors; | ||||
| 	errors += "At "; | ||||
| 	if (!currentPath.empty()) | ||||
| 	{ | ||||
| 		BOOST_FOREACH(const JsonNode &path, currentPath) | ||||
| 		{ | ||||
| 			errors += "/"; | ||||
| @@ -1088,6 +1090,9 @@ std::string JsonValidator::fail(const std::string &message) | ||||
| 			else | ||||
| 				errors += boost::lexical_cast<std::string>(static_cast<unsigned>(path.Float())); | ||||
| 		} | ||||
| 	} | ||||
| 	else | ||||
| 		errors += "<root>"; | ||||
| 	errors += "\n\t Error: " + message + "\n"; | ||||
| 	return errors; | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user