2013-07-28 17:49:50 +03:00
|
|
|
/*
|
|
|
|
* AdapterLoaders.h, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
2017-07-13 10:26:03 +02:00
|
|
|
#pragma once
|
2013-07-28 17:49:50 +03:00
|
|
|
|
|
|
|
#include "ISimpleResourceLoader.h"
|
2013-11-08 23:36:26 +03:00
|
|
|
#include "ResourceID.h"
|
2013-07-28 17:49:50 +03:00
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
2013-07-28 17:49:50 +03:00
|
|
|
class CInputStream;
|
2013-11-08 23:36:26 +03:00
|
|
|
class JsonNode;
|
2013-07-28 17:49:50 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class that implements file mapping (aka *nix symbolic links)
|
|
|
|
* Uses json file as input, content is map:
|
|
|
|
* "fileA.txt" : "fileB.txt"
|
|
|
|
* Note that extension is necessary, but used only to determine type
|
|
|
|
*
|
|
|
|
* fileA - file which will be replaced
|
|
|
|
* fileB - file which will be used as replacement
|
|
|
|
*/
|
|
|
|
class DLL_LINKAGE CMappedFileLoader : public ISimpleResourceLoader
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Ctor.
|
|
|
|
*
|
|
|
|
* @param config Specifies filesystem configuration
|
|
|
|
*/
|
|
|
|
explicit CMappedFileLoader(const std::string &mountPoint, const JsonNode & config);
|
|
|
|
|
|
|
|
/// Interface implementation
|
|
|
|
/// @see ISimpleResourceLoader
|
|
|
|
std::unique_ptr<CInputStream> load(const ResourceID & resourceName) const override;
|
|
|
|
bool existsResource(const ResourceID & resourceName) const override;
|
|
|
|
std::string getMountPoint() const override;
|
2016-01-16 17:36:16 +02:00
|
|
|
boost::optional<boost::filesystem::path> getResourceName(const ResourceID & resourceName) const override;
|
2016-10-16 22:09:57 +02:00
|
|
|
void updateFilteredFiles(std::function<bool(const std::string &)> filter) const override {}
|
2015-10-12 15:47:10 +02:00
|
|
|
std::unordered_set<ResourceID> getFilteredFiles(std::function<bool(const ResourceID &)> filter) const override;
|
2013-07-28 17:49:50 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
/** A list of files in this map
|
|
|
|
* key = ResourceID for resource loader
|
|
|
|
* value = ResourceID to which file this request will be redirected
|
|
|
|
*/
|
|
|
|
std::unordered_map<ResourceID, ResourceID> fileList;
|
|
|
|
};
|
|
|
|
|
|
|
|
class DLL_LINKAGE CFilesystemList : public ISimpleResourceLoader
|
|
|
|
{
|
2013-12-29 14:27:38 +03:00
|
|
|
std::vector<std::unique_ptr<ISimpleResourceLoader> > loaders;
|
2013-07-28 17:49:50 +03:00
|
|
|
|
|
|
|
std::set<ISimpleResourceLoader *> writeableLoaders;
|
|
|
|
|
2013-12-29 18:48:56 +03:00
|
|
|
//FIXME: this is only compile fix, should be removed in the end
|
2016-10-16 22:09:57 +02:00
|
|
|
CFilesystemList(CFilesystemList &) = delete;
|
|
|
|
CFilesystemList &operator=(CFilesystemList &) = delete;
|
2013-12-29 18:48:56 +03:00
|
|
|
|
2013-07-28 17:49:50 +03:00
|
|
|
public:
|
2013-07-28 21:57:07 +03:00
|
|
|
CFilesystemList();
|
2013-07-29 13:08:02 +03:00
|
|
|
~CFilesystemList();
|
2013-07-28 17:49:50 +03:00
|
|
|
/// Interface implementation
|
|
|
|
/// @see ISimpleResourceLoader
|
|
|
|
std::unique_ptr<CInputStream> load(const ResourceID & resourceName) const override;
|
|
|
|
bool existsResource(const ResourceID & resourceName) const override;
|
|
|
|
std::string getMountPoint() const override;
|
2016-01-16 17:36:16 +02:00
|
|
|
boost::optional<boost::filesystem::path> getResourceName(const ResourceID & resourceName) const override;
|
2016-10-16 22:09:57 +02:00
|
|
|
std::set<boost::filesystem::path> getResourceNames(const ResourceID & resourceName) const override;
|
|
|
|
void updateFilteredFiles(std::function<bool(const std::string &)> filter) const override;
|
2013-07-28 17:49:50 +03:00
|
|
|
std::unordered_set<ResourceID> getFilteredFiles(std::function<bool(const ResourceID &)> filter) const override;
|
|
|
|
bool createResource(std::string filename, bool update = false) override;
|
|
|
|
std::vector<const ISimpleResourceLoader *> getResourcesWithName(const ResourceID & resourceName) const override;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a resource loader to the loaders list
|
|
|
|
* Passes loader ownership to this object
|
|
|
|
*
|
|
|
|
* @param loader The simple resource loader object to add
|
|
|
|
* @param writeable - resource shall be treated as writeable
|
|
|
|
*/
|
|
|
|
void addLoader(ISimpleResourceLoader * loader, bool writeable);
|
2022-09-17 13:04:01 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes loader from the loader list
|
|
|
|
* Take care about memory deallocation
|
|
|
|
*
|
|
|
|
* @param loader The simple resource loader object to remove
|
|
|
|
*
|
|
|
|
* @return if loader was successfully removed
|
|
|
|
*/
|
|
|
|
bool removeLoader(ISimpleResourceLoader * loader);
|
2013-11-08 23:36:26 +03:00
|
|
|
};
|
2022-07-26 15:07:42 +02:00
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|