From 6a260a60cfde0aaedd8a7b027a27644740e11ebe Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Mon, 4 Sep 2023 16:16:00 +0300 Subject: [PATCH] Fix resource creation --- lib/CConfigHandler.cpp | 2 +- lib/filesystem/AdapterLoaders.cpp | 4 ++-- lib/filesystem/AdapterLoaders.h | 2 +- lib/filesystem/CFilesystemLoader.cpp | 5 +++-- lib/filesystem/CFilesystemLoader.h | 2 +- lib/filesystem/ISimpleResourceLoader.h | 2 +- lib/mapping/MapFormatH3M.cpp | 2 +- lib/mapping/MapIdentifiersH3M.cpp | 2 +- lib/modding/CModHandler.cpp | 2 +- server/CGameHandler.cpp | 2 +- 10 files changed, 13 insertions(+), 12 deletions(-) diff --git a/lib/CConfigHandler.cpp b/lib/CConfigHandler.cpp index 471a71205..6e507dbe7 100644 --- a/lib/CConfigHandler.cpp +++ b/lib/CConfigHandler.cpp @@ -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"); diff --git a/lib/filesystem/AdapterLoaders.cpp b/lib/filesystem/AdapterLoaders.cpp index c95ac4c77..8bdf8abab 100644 --- a/lib/filesystem/AdapterLoaders.cpp +++ b/lib/filesystem/AdapterLoaders.cpp @@ -128,9 +128,9 @@ std::unordered_set 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, diff --git a/lib/filesystem/AdapterLoaders.h b/lib/filesystem/AdapterLoaders.h index 23bf6d6a6..6fea768d7 100644 --- a/lib/filesystem/AdapterLoaders.h +++ b/lib/filesystem/AdapterLoaders.h @@ -75,7 +75,7 @@ public: std::set getResourceNames(const ResourcePath & resourceName) const override; void updateFilteredFiles(std::function filter) const override; std::unordered_set getFilteredFiles(std::function filter) const override; - bool createResource(const ResourcePath & filename, bool update = false) override; + bool createResource(const std::string & filename, bool update = false) override; std::vector getResourcesWithName(const ResourcePath & resourceName) const override; /** diff --git a/lib/filesystem/CFilesystemLoader.cpp b/lib/filesystem/CFilesystemLoader.cpp index 0a59a7279..09073660c 100644 --- a/lib/filesystem/CFilesystemLoader.cpp +++ b/lib/filesystem/CFilesystemLoader.cpp @@ -68,9 +68,10 @@ std::unordered_set 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; diff --git a/lib/filesystem/CFilesystemLoader.h b/lib/filesystem/CFilesystemLoader.h index 301adc361..ec75c62a0 100644 --- a/lib/filesystem/CFilesystemLoader.h +++ b/lib/filesystem/CFilesystemLoader.h @@ -37,7 +37,7 @@ public: std::unique_ptr 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 getResourceName(const ResourcePath & resourceName) const override; void updateFilteredFiles(std::function filter) const override; std::unordered_set getFilteredFiles(std::function filter) const override; diff --git a/lib/filesystem/ISimpleResourceLoader.h b/lib/filesystem/ISimpleResourceLoader.h index b9b9c3f94..836a3a505 100644 --- a/lib/filesystem/ISimpleResourceLoader.h +++ b/lib/filesystem/ISimpleResourceLoader.h @@ -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; } diff --git a/lib/mapping/MapFormatH3M.cpp b/lib/mapping/MapFormatH3M.cpp index e7040ce5d..0b156c422 100644 --- a/lib/mapping/MapFormatH3M.cpp +++ b/lib/mapping/MapFormatH3M.cpp @@ -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 ); } } diff --git a/lib/mapping/MapIdentifiersH3M.cpp b/lib/mapping/MapIdentifiersH3M.cpp index 70789a001..05c35020c 100644 --- a/lib/mapping/MapIdentifiersH3M.cpp +++ b/lib/mapping/MapIdentifiersH3M.cpp @@ -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; diff --git a/lib/modding/CModHandler.cpp b/lib/modding/CModHandler.cpp index 78fa70a5c..6fb6f0ac5 100644 --- a/lib/modding/CModHandler.cpp +++ b/lib/modding/CModHandler.cpp @@ -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(); } diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index 701c27ab7..6525c1b00 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -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 {