1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-03-19 21:10:12 +02:00

remove resource

This commit is contained in:
Laserlicht 2024-08-20 22:45:11 +02:00
parent c56d667981
commit d8869a33da
5 changed files with 16 additions and 9 deletions

View File

@ -31,10 +31,6 @@ void AssetGenerator::createAdventureOptionsCleanBackground()
if(!CResourceHandler::get("local")->createResource(filename))
return;
ResourcePath savePath(filename, EResType::IMAGE);
if(boost::filesystem::exists(*CResourceHandler::get("local")->getResourceName(savePath)) &&
boost::filesystem::file_size(*CResourceHandler::get("local")->getResourceName(savePath)))
return;
auto res = ImagePath::builtin("ADVOPTBK");
res.setOriginalResource(true);
@ -53,6 +49,8 @@ void AssetGenerator::createAdventureOptionsCleanBackground()
std::shared_ptr<IImage> image = GH.renderHandler().createImage(canvas.getInternalSurface());
image->exportBitmap(*CResourceHandler::get("local")->getResourceName(savePath));
CResourceHandler::get("local")->removeResource(savePath); // remove resource -> may overridden by mod later
}
void AssetGenerator::createBigSpellBook()
@ -62,10 +60,6 @@ void AssetGenerator::createBigSpellBook()
if(!CResourceHandler::get("local")->createResource(filename))
return;
ResourcePath savePath(filename, EResType::IMAGE);
if(boost::filesystem::exists(*CResourceHandler::get("local")->getResourceName(savePath)) &&
boost::filesystem::file_size(*CResourceHandler::get("local")->getResourceName(savePath)))
return;
auto res = ImagePath::builtin("SpelBack");
res.setOriginalResource(true);
@ -117,4 +111,6 @@ void AssetGenerator::createBigSpellBook()
std::shared_ptr<IImage> image = GH.renderHandler().createImage(canvas.getInternalSurface());
image->exportBitmap(*CResourceHandler::get("local")->getResourceName(savePath));
CResourceHandler::get("local")->removeResource(savePath); // remove resource -> may overridden by mod later
}

View File

@ -16,4 +16,4 @@ class AssetGenerator
public:
static void generate();
};
};

View File

@ -108,6 +108,11 @@ bool CFilesystemLoader::createResource(const std::string & requestedFilename, bo
return true;
}
void CFilesystemLoader::removeResource(const ResourcePath & resourceName)
{
fileList.erase(resourceName);
}
std::unordered_map<ResourcePath, boost::filesystem::path> CFilesystemLoader::listFiles(const std::string &mountPoint, size_t depth, bool initial) const
{
static const EResType initArray[] = {

View File

@ -38,6 +38,7 @@ public:
bool existsResource(const ResourcePath & resourceName) const override;
std::string getMountPoint() const override;
bool createResource(const std::string & filename, bool update = false) override;
void removeResource(const ResourcePath & resourceName) 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;

View File

@ -95,6 +95,11 @@ public:
return false;
}
/**
* Remove resources from cached list.
*/
virtual void removeResource(const ResourcePath & resourceName) { };
/**
* @brief Returns all loaders that have resource with such name
*