2012-07-22 18:02:13 +03:00
|
|
|
/*
|
|
|
|
* ISimpleResourceLoader.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
|
2012-07-22 18:02:13 +03:00
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
2013-07-28 17:49:50 +03:00
|
|
|
class CInputStream;
|
2023-08-23 14:07:50 +02:00
|
|
|
class ResourcePath;
|
2012-07-22 18:02:13 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A class which knows the files containing in the archive or system and how to load them.
|
|
|
|
*/
|
|
|
|
class DLL_LINKAGE ISimpleResourceLoader
|
|
|
|
{
|
2012-08-01 15:02:54 +03:00
|
|
|
public:
|
2012-07-22 18:02:13 +03:00
|
|
|
virtual ~ISimpleResourceLoader() { };
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads a resource with the given resource name.
|
|
|
|
*
|
|
|
|
* @param resourceName The unqiue resource name in space of the archive.
|
|
|
|
* @return a input stream object
|
|
|
|
*/
|
2023-08-23 14:07:50 +02:00
|
|
|
virtual std::unique_ptr<CInputStream> load(const ResourcePath & resourceName) const = 0;
|
2012-07-22 18:02:13 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the entry exists.
|
|
|
|
*
|
|
|
|
* @return Returns true if the entry exists, false if not.
|
|
|
|
*/
|
2023-08-23 14:07:50 +02:00
|
|
|
virtual bool existsResource(const ResourcePath & resourceName) const = 0;
|
2012-07-22 18:02:13 +03:00
|
|
|
|
|
|
|
/**
|
2013-07-28 17:49:50 +03:00
|
|
|
* Gets mount point to which this loader was attached
|
2012-07-22 18:02:13 +03:00
|
|
|
*
|
2013-07-28 17:49:50 +03:00
|
|
|
* @return mount point URI
|
2012-07-22 18:02:13 +03:00
|
|
|
*/
|
2013-07-28 17:49:50 +03:00
|
|
|
virtual std::string getMountPoint() const = 0;
|
2012-08-01 15:02:54 +03:00
|
|
|
|
|
|
|
/**
|
2013-07-28 17:49:50 +03:00
|
|
|
* Gets full name of resource, e.g. name of file in filesystem.
|
2012-08-01 15:02:54 +03:00
|
|
|
*
|
2013-07-28 17:49:50 +03:00
|
|
|
* @return path or empty optional if file can't be accessed independently (e.g. file in archive)
|
2012-08-01 15:02:54 +03:00
|
|
|
*/
|
2023-08-23 14:07:50 +02:00
|
|
|
virtual std::optional<boost::filesystem::path> getResourceName(const ResourcePath & resourceName) const
|
2013-07-28 17:49:50 +03:00
|
|
|
{
|
2023-04-16 19:42:56 +02:00
|
|
|
return std::optional<boost::filesystem::path>();
|
2013-07-28 17:49:50 +03:00
|
|
|
}
|
2012-08-07 14:28:52 +03:00
|
|
|
|
2016-01-27 10:38:35 +02:00
|
|
|
/**
|
|
|
|
* Gets all full names of matching resources, e.g. names of files in filesystem.
|
|
|
|
*
|
|
|
|
* @return std::set with names.
|
|
|
|
*/
|
2023-08-23 14:07:50 +02:00
|
|
|
virtual std::set<boost::filesystem::path> getResourceNames(const ResourcePath & resourceName) const
|
2016-01-27 10:38:35 +02:00
|
|
|
{
|
2016-01-27 18:32:59 +02:00
|
|
|
std::set<boost::filesystem::path> result;
|
2016-01-27 10:38:35 +02:00
|
|
|
auto rn = getResourceName(resourceName);
|
|
|
|
if(rn)
|
|
|
|
{
|
2016-01-27 22:08:08 +02:00
|
|
|
result.insert(rn->string());
|
2016-01-27 10:38:35 +02:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-05-04 16:14:23 +03:00
|
|
|
/**
|
2016-10-16 22:09:57 +02:00
|
|
|
* Update lists of files that match filter function
|
|
|
|
*
|
|
|
|
* @param filter Filter that returns true if specified mount point matches filter
|
|
|
|
*/
|
|
|
|
virtual void updateFilteredFiles(std::function<bool(const std::string &)> filter) const = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get list of files that match filter function
|
2013-07-28 17:49:50 +03:00
|
|
|
*
|
|
|
|
* @param filter Filter that returns true if specified ID matches filter
|
|
|
|
* @return Returns list of flies
|
2013-05-04 16:14:23 +03:00
|
|
|
*/
|
2023-08-23 14:07:50 +02:00
|
|
|
virtual std::unordered_set<ResourcePath> getFilteredFiles(std::function<bool(const ResourcePath &)> filter) const = 0;
|
2013-05-04 16:14:23 +03:00
|
|
|
|
2012-08-07 14:28:52 +03:00
|
|
|
/**
|
|
|
|
* Creates new resource with specified filename.
|
|
|
|
*
|
2013-07-28 17:49:50 +03:00
|
|
|
* @return true if new file was created, false on error or if file already exists
|
2012-08-07 14:28:52 +03:00
|
|
|
*/
|
2023-09-04 15:16:00 +02:00
|
|
|
virtual bool createResource(const std::string & filename, bool update = false)
|
2012-08-07 14:28:52 +03:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2013-07-28 17:49:50 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Returns all loaders that have resource with such name
|
|
|
|
*
|
|
|
|
* @return vector with all loaders
|
|
|
|
*/
|
2023-08-23 14:07:50 +02:00
|
|
|
virtual std::vector<const ISimpleResourceLoader *> getResourcesWithName(const ResourcePath & resourceName) const
|
2013-07-28 17:49:50 +03:00
|
|
|
{
|
|
|
|
if (existsResource(resourceName))
|
|
|
|
return std::vector<const ISimpleResourceLoader *>(1, this);
|
|
|
|
return std::vector<const ISimpleResourceLoader *>();
|
|
|
|
}
|
2012-07-22 18:02:13 +03:00
|
|
|
};
|
2022-07-26 15:07:42 +02:00
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|