mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	Rebase on develop
This commit is contained in:
		| @@ -532,6 +532,51 @@ JsonNode addMeta(JsonNode config, std::string meta) | ||||
| 	return config; | ||||
| } | ||||
|  | ||||
| CModInfo::Version CModInfo::Version::GameVersion() | ||||
| { | ||||
| 	return Version(GameConstants::VCMI_VERSION_MAJOR, GameConstants::VCMI_VERSION_MINOR, GameConstants::VCMI_VERSION_PATCH); | ||||
| } | ||||
|  | ||||
| CModInfo::Version CModInfo::Version::fromString(std::string from) | ||||
| { | ||||
| 	int major = 0, minor = 0, patch = 0; | ||||
| 	try | ||||
| 	{ | ||||
| 		auto pointPos = from.find('.'); | ||||
| 		major = std::stoi(from.substr(0, pointPos)); | ||||
| 		if(pointPos != std::string::npos) | ||||
| 		{ | ||||
| 			from = from.substr(pointPos + 1); | ||||
| 			pointPos = from.find('.'); | ||||
| 			minor = std::stoi(from.substr(0, pointPos)); | ||||
| 			if(pointPos != std::string::npos) | ||||
| 				patch = std::stoi(from.substr(pointPos + 1)); | ||||
| 		} | ||||
| 	} | ||||
| 	catch(const std::invalid_argument & e) | ||||
| 	{ | ||||
| 		return Version(); | ||||
| 	} | ||||
| 	return Version(major, minor, patch); | ||||
| } | ||||
|  | ||||
| std::string CModInfo::Version::toString() const | ||||
| { | ||||
| 	return std::to_string(major) + '.' + std::to_string(minor) + '.' + std::to_string(patch); | ||||
| } | ||||
|  | ||||
| bool CModInfo::Version::compatible(const Version & other, bool checkMinor, bool checkPatch) const | ||||
| { | ||||
| 	return  (major == other.major && | ||||
| 			(!checkMinor || minor >= other.minor) && | ||||
| 			(!checkPatch || minor > other.minor || (minor == other.minor && patch >= other.patch))); | ||||
| } | ||||
|  | ||||
| bool CModInfo::Version::isNull() const | ||||
| { | ||||
| 	return major == 0 && minor == 0 && patch == 0; | ||||
| } | ||||
|  | ||||
| CModInfo::CModInfo(): | ||||
| 	checksum(0), | ||||
| 	enabled(false), | ||||
| @@ -551,6 +596,12 @@ CModInfo::CModInfo(std::string identifier,const JsonNode & local, const JsonNode | ||||
| 	validation(PENDING), | ||||
| 	config(addMeta(config, identifier)) | ||||
| { | ||||
| 	version = Version::fromString(config["version"].String()); | ||||
| 	if(!config["compatibility"].isNull()) | ||||
| 	{ | ||||
| 		vcmiCompatibleMin = Version::fromString(config["compatibility"]["min"].String()); | ||||
| 		vcmiCompatibleMax = Version::fromString(config["compatibility"]["max"].String()); | ||||
| 	} | ||||
| 	loadLocalData(local); | ||||
| } | ||||
|  | ||||
| @@ -601,6 +652,13 @@ void CModInfo::loadLocalData(const JsonNode & data) | ||||
| 		validated = data["validated"].Bool(); | ||||
| 		checksum  = strtol(data["checksum"].String().c_str(), nullptr, 16); | ||||
| 	} | ||||
| 	 | ||||
| 	//check compatibility | ||||
| 	bool wasEnabled = enabled; | ||||
| 	enabled &= vcmiCompatibleMin.isNull() || Version::GameVersion().compatible(vcmiCompatibleMin); | ||||
| 	enabled &= vcmiCompatibleMax.isNull() || vcmiCompatibleMax.compatible(Version::GameVersion()); | ||||
| 	if(wasEnabled && !enabled) | ||||
| 		logGlobal->warn("Mod %s is incompatible with current version of VCMI and cannot be enabled", name); | ||||
|  | ||||
| 	if (enabled) | ||||
| 		validation = validated ? PASSED : PENDING; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user