2012-07-22 18:02:13 +03:00
|
|
|
/*
|
|
|
|
* CFilesystemLoader.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
|
|
|
|
|
|
|
#include "ISimpleResourceLoader.h"
|
2023-08-23 14:07:50 +02:00
|
|
|
#include "ResourcePath.h"
|
2012-07-22 18:02:13 +03:00
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
2012-07-22 18:02:13 +03:00
|
|
|
class CInputStream;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A class which can scan and load files of directories.
|
|
|
|
*/
|
|
|
|
class DLL_LINKAGE CFilesystemLoader : public ISimpleResourceLoader
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Ctor.
|
|
|
|
*
|
|
|
|
* @param baseDirectory Specifies the base directory and their sub-directories which should be indexed.
|
2012-07-23 13:23:43 +03:00
|
|
|
* @param depth - recursion depth of subdirectories search. 0 = no recursion
|
2012-07-22 18:02:13 +03:00
|
|
|
*
|
|
|
|
* @throws std::runtime_error if the base directory is not a directory or if it is not available
|
|
|
|
*/
|
2014-08-21 23:26:28 +03:00
|
|
|
explicit CFilesystemLoader(std::string mountPoint, boost::filesystem::path baseDirectory, size_t depth = 16, bool initial = false);
|
2012-07-22 18:02:13 +03:00
|
|
|
|
2013-05-04 16:14:23 +03:00
|
|
|
/// Interface implementation
|
|
|
|
/// @see ISimpleResourceLoader
|
2023-08-23 14:07:50 +02:00
|
|
|
std::unique_ptr<CInputStream> load(const ResourcePath & resourceName) const override;
|
|
|
|
bool existsResource(const ResourcePath & resourceName) const override;
|
2013-07-28 17:49:50 +03:00
|
|
|
std::string getMountPoint() const override;
|
2023-09-04 15:16:00 +02:00
|
|
|
bool createResource(const std::string & filename, bool update = false) override;
|
2023-08-23 14:07:50 +02:00
|
|
|
std::optional<boost::filesystem::path> getResourceName(const ResourcePath & resourceName) const override;
|
2016-10-16 22:09:57 +02:00
|
|
|
void updateFilteredFiles(std::function<bool(const std::string &)> filter) const override;
|
2023-08-23 14:07:50 +02:00
|
|
|
std::unordered_set<ResourcePath> getFilteredFiles(std::function<bool(const ResourcePath &)> filter) const override;
|
2012-08-07 14:28:52 +03:00
|
|
|
|
2012-07-22 18:02:13 +03:00
|
|
|
private:
|
|
|
|
/** The base directory which is scanned and indexed. */
|
2014-08-21 23:26:28 +03:00
|
|
|
boost::filesystem::path baseDirectory;
|
2012-07-22 18:02:13 +03:00
|
|
|
|
2013-07-28 17:49:50 +03:00
|
|
|
std::string mountPoint;
|
2022-09-10 18:30:41 +02:00
|
|
|
|
|
|
|
size_t recursiveDepth;
|
2013-07-28 17:49:50 +03:00
|
|
|
|
2012-08-07 14:28:52 +03:00
|
|
|
/** A list of files in the directory
|
2023-08-23 14:07:50 +02:00
|
|
|
* key = ResourcePath for resource loader
|
2012-08-07 14:28:52 +03:00
|
|
|
* value = name that can be used to access file
|
|
|
|
*/
|
2023-08-23 14:07:50 +02:00
|
|
|
mutable std::unordered_map<ResourcePath, boost::filesystem::path> fileList;
|
2012-08-07 14:28:52 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a list of pathnames denoting the files in the directory denoted by this pathname.
|
|
|
|
*
|
|
|
|
* If the pathname of this directory is absolute, then the file info pathnames are absolute as well. If the pathname of this directory is relative
|
|
|
|
* then the file info pathnames are relative to the basedir as well.
|
|
|
|
*
|
|
|
|
* @return a list of pathnames denoting the files and directories in the directory denoted by this pathname
|
|
|
|
* The array will be empty if the directory is empty. Ptr is null if the directory doesn't exist or if it isn't a directory.
|
|
|
|
*/
|
2023-08-23 14:07:50 +02:00
|
|
|
std::unordered_map<ResourcePath, boost::filesystem::path> listFiles(const std::string &mountPoint, size_t depth, bool initial) const;
|
2012-07-22 18:02:13 +03:00
|
|
|
};
|
2022-07-26 15:07:42 +02:00
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|