mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	Fix resource creation
This commit is contained in:
		| @@ -61,7 +61,7 @@ void SettingsStorage::init() | ||||
|  | ||||
| 	// Probably new install. Create config file to save settings to | ||||
| 	if (!CResourceHandler::get("local")->existsResource(confName)) | ||||
| 		CResourceHandler::get("local")->createResource(confName); | ||||
| 		CResourceHandler::get("local")->createResource("config/settings.json"); | ||||
|  | ||||
| 	JsonUtils::maximize(config, "vcmi:settings"); | ||||
| 	JsonUtils::validate(config, "vcmi:settings", "settings"); | ||||
|   | ||||
| @@ -128,9 +128,9 @@ std::unordered_set<ResourcePath> CFilesystemList::getFilteredFiles(std::function | ||||
| 	return ret; | ||||
| } | ||||
|  | ||||
| bool CFilesystemList::createResource(const ResourcePath & filename, bool update) | ||||
| bool CFilesystemList::createResource(const std::string & filename, bool update) | ||||
| { | ||||
| 	logGlobal->trace("Creating %s", filename.getOriginalName()); | ||||
| 	logGlobal->trace("Creating %s", filename); | ||||
| 	for (auto & loader : boost::adaptors::reverse(loaders)) | ||||
| 	{ | ||||
| 		if (writeableLoaders.count(loader.get()) != 0                       // writeable, | ||||
|   | ||||
| @@ -75,7 +75,7 @@ public: | ||||
| 	std::set<boost::filesystem::path> getResourceNames(const ResourcePath & resourceName) const override; | ||||
| 	void updateFilteredFiles(std::function<bool(const std::string &)> filter) const override; | ||||
| 	std::unordered_set<ResourcePath> getFilteredFiles(std::function<bool(const ResourcePath &)> filter) const override; | ||||
| 	bool createResource(const ResourcePath & filename, bool update = false) override; | ||||
| 	bool createResource(const std::string & filename, bool update = false) override; | ||||
| 	std::vector<const ISimpleResourceLoader *> getResourcesWithName(const ResourcePath & resourceName) const override; | ||||
|  | ||||
| 	/** | ||||
|   | ||||
| @@ -68,9 +68,10 @@ std::unordered_set<ResourcePath> CFilesystemLoader::getFilteredFiles(std::functi | ||||
| 	return foundID; | ||||
| } | ||||
|  | ||||
| bool CFilesystemLoader::createResource(const ResourcePath & resID, bool update) | ||||
| bool CFilesystemLoader::createResource(const std::string & requestedFilename, bool update) | ||||
| { | ||||
| 	std::string filename = resID.getOriginalName() + '.' + boost::to_lower_copy(EResTypeHelper::getEResTypeAsString(resID.getType())); | ||||
| 	std::string filename = requestedFilename; | ||||
| 	ResourcePath resID(filename); | ||||
|  | ||||
| 	if (fileList.find(resID) != fileList.end()) | ||||
| 		return true; | ||||
|   | ||||
| @@ -37,7 +37,7 @@ public: | ||||
| 	std::unique_ptr<CInputStream> load(const ResourcePath & resourceName) const override; | ||||
| 	bool existsResource(const ResourcePath & resourceName) const override; | ||||
| 	std::string getMountPoint() const override; | ||||
| 	bool createResource(const ResourcePath & filename, bool update = false) override; | ||||
| 	bool createResource(const std::string & filename, bool update = false) override; | ||||
| 	std::optional<boost::filesystem::path> getResourceName(const ResourcePath & resourceName) const override; | ||||
| 	void updateFilteredFiles(std::function<bool(const std::string &)> filter) const override; | ||||
| 	std::unordered_set<ResourcePath> getFilteredFiles(std::function<bool(const ResourcePath &)> filter) const override; | ||||
|   | ||||
| @@ -90,7 +90,7 @@ public: | ||||
| 	 * | ||||
| 	 * @return true if new file was created, false on error or if file already exists | ||||
| 	 */ | ||||
| 	virtual bool createResource(const ResourcePath & filename, bool update = false) | ||||
| 	virtual bool createResource(const std::string & filename, bool update = false) | ||||
| 	{ | ||||
| 		return false; | ||||
| 	} | ||||
|   | ||||
| @@ -984,7 +984,7 @@ void CMapLoaderH3M::readObjectTemplates() | ||||
| 		auto tmpl = reader->readObjectTemplate(); | ||||
| 		templates.push_back(tmpl); | ||||
|  | ||||
| 		if (!CResourceHandler::get()->existsResource(tmpl->animationFile)) | ||||
| 		if (!CResourceHandler::get()->existsResource(tmpl->animationFile.addPrefix("SPRITES/"))) | ||||
| 			logMod->warn("Template animation %s of type (%d %d) is missing!", tmpl->animationFile.getOriginalName(), tmpl->id, tmpl->subid ); | ||||
| 	} | ||||
| } | ||||
|   | ||||
| @@ -56,7 +56,7 @@ void MapIdentifiersH3M::loadMapping(const JsonNode & mapping) | ||||
| 		std::string h3mName = boost::to_lower_copy(entryTemplate.second.String()); | ||||
| 		std::string vcmiName = boost::to_lower_copy(entryTemplate.first); | ||||
|  | ||||
| 		if (!CResourceHandler::get()->existsResource(AnimationPath::builtin("SPRITES/" + vcmiName))) | ||||
| 		if (!CResourceHandler::get()->existsResource(AnimationPath::builtinTODO("SPRITES/" + vcmiName))) | ||||
| 			logMod->warn("Template animation file %s was not found!", vcmiName); | ||||
|  | ||||
| 		mappingObjectTemplate[h3mName] = vcmiName; | ||||
|   | ||||
| @@ -35,7 +35,7 @@ static JsonNode loadModSettings(const JsonPath & path) | ||||
| 		return JsonNode(path); | ||||
| 	} | ||||
| 	// Probably new install. Create initial configuration | ||||
| 	CResourceHandler::get("local")->createResource(path); | ||||
| 	CResourceHandler::get("local")->createResource(path.getOriginalName() + ".json"); | ||||
| 	return JsonNode(); | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -1718,7 +1718,7 @@ void CGameHandler::save(const std::string & filename) | ||||
| 	const auto stem	= FileInfo::GetPathStem(filename); | ||||
| 	const auto savefname = stem.to_string() + ".vsgm1"; | ||||
| 	ResourcePath savePath(stem.to_string(), EResType::SAVEGAME); | ||||
| 	CResourceHandler::get("local")->createResource(savePath); | ||||
| 	CResourceHandler::get("local")->createResource(savefname); | ||||
|  | ||||
| 	try | ||||
| 	{ | ||||
|   | ||||
		Reference in New Issue
	
	Block a user