2015-03-17 20:59:39 +00:00
|
|
|
#ifndef OPENMW_COMPONENTS_RESOURCEMANAGER_H
|
|
|
|
#define OPENMW_COMPONENTS_RESOURCEMANAGER_H
|
|
|
|
|
2022-07-16 16:19:56 +00:00
|
|
|
#include <components/files/istreamptr.hpp>
|
2015-03-17 20:59:39 +00:00
|
|
|
|
|
|
|
#include <filesystem>
|
2022-07-16 10:14:20 +00:00
|
|
|
#include <memory>
|
2022-07-16 16:19:56 +00:00
|
|
|
#include <string>
|
2024-01-15 23:30:41 +00:00
|
|
|
#include <string_view>
|
2022-07-28 20:20:44 +00:00
|
|
|
#include <vector>
|
2015-03-17 20:59:39 +00:00
|
|
|
|
2024-01-15 23:30:41 +00:00
|
|
|
#include "filemap.hpp"
|
2024-01-16 22:55:42 +00:00
|
|
|
#include "pathutil.hpp"
|
2023-05-31 21:11:03 +00:00
|
|
|
|
2015-03-17 20:59:39 +00:00
|
|
|
namespace VFS
|
|
|
|
{
|
2024-01-15 23:30:41 +00:00
|
|
|
class Archive;
|
|
|
|
class RecursiveDirectoryRange;
|
2021-09-06 19:56:32 +00:00
|
|
|
|
2015-03-17 20:59:39 +00:00
|
|
|
/// @brief The main class responsible for loading files from a virtual file system.
|
|
|
|
/// @par Various archive types (e.g. directories on the filesystem, or compressed archives)
|
|
|
|
/// can be registered, and will be merged into a single file tree. If the same filename is
|
|
|
|
/// contained in multiple archives, the last added archive will have priority.
|
2016-02-06 15:57:54 +00:00
|
|
|
/// @par Most of the methods in this class are considered thread-safe, see each method documentation for details.
|
2015-03-17 20:59:39 +00:00
|
|
|
class Manager
|
|
|
|
{
|
2024-01-15 23:30:41 +00:00
|
|
|
public:
|
|
|
|
Manager();
|
2021-09-23 16:47:59 +00:00
|
|
|
|
2024-01-15 23:30:41 +00:00
|
|
|
~Manager();
|
2021-09-23 16:47:59 +00:00
|
|
|
|
2017-08-22 02:31:19 +00:00
|
|
|
// Empty the file index and unregister archives.
|
|
|
|
void reset();
|
|
|
|
|
2015-03-17 20:59:39 +00:00
|
|
|
/// Register the given archive. All files contained in it will be added to the index on the next buildIndex()
|
|
|
|
/// call.
|
2022-07-16 10:14:20 +00:00
|
|
|
void addArchive(std::unique_ptr<Archive>&& archive);
|
2015-03-17 20:59:39 +00:00
|
|
|
|
|
|
|
/// Build the file index. Should be called when all archives have been registered.
|
|
|
|
void buildIndex();
|
|
|
|
|
|
|
|
/// Does a file with this name exist?
|
2016-02-06 15:57:54 +00:00
|
|
|
/// @note May be called from any thread once the index has been built.
|
2024-01-16 22:55:42 +00:00
|
|
|
bool exists(const Path::Normalized& name) const;
|
2015-03-17 20:59:39 +00:00
|
|
|
|
2024-02-22 22:59:23 +00:00
|
|
|
bool exists(Path::NormalizedView name) const;
|
|
|
|
|
2024-05-02 23:07:47 +00:00
|
|
|
// Returns open file if exists or nullptr.
|
|
|
|
Files::IStreamPtr find(Path::NormalizedView name) const;
|
|
|
|
|
2015-03-17 20:59:39 +00:00
|
|
|
/// Retrieve a file by name.
|
|
|
|
/// @note Throws an exception if the file can not be found.
|
2016-02-06 15:57:54 +00:00
|
|
|
/// @note May be called from any thread once the index has been built.
|
2024-01-16 22:55:42 +00:00
|
|
|
Files::IStreamPtr get(const Path::Normalized& name) const;
|
2015-03-17 20:59:39 +00:00
|
|
|
|
2024-03-09 00:45:21 +00:00
|
|
|
Files::IStreamPtr get(Path::NormalizedView name) const;
|
|
|
|
|
2015-03-26 17:02:51 +00:00
|
|
|
/// Retrieve a file by name (name is already normalized).
|
|
|
|
/// @note Throws an exception if the file can not be found.
|
2016-02-06 15:57:54 +00:00
|
|
|
/// @note May be called from any thread once the index has been built.
|
2023-12-17 14:20:48 +00:00
|
|
|
Files::IStreamPtr getNormalized(std::string_view normalizedName) const;
|
2015-03-26 17:02:51 +00:00
|
|
|
|
2024-01-16 22:55:42 +00:00
|
|
|
std::string getArchive(const Path::Normalized& name) const;
|
2021-09-06 19:56:32 +00:00
|
|
|
|
2023-05-10 00:07:08 +00:00
|
|
|
/// Recursively iterate over the elements of the given path
|
2021-09-06 19:56:32 +00:00
|
|
|
/// In practice it return all files of the VFS starting with the given path
|
|
|
|
/// @note the path is normalized
|
|
|
|
/// @note May be called from any thread once the index has been built.
|
2022-07-17 10:19:19 +00:00
|
|
|
RecursiveDirectoryRange getRecursiveDirectoryIterator(std::string_view path) const;
|
2021-09-06 19:56:32 +00:00
|
|
|
|
2024-03-11 23:40:03 +00:00
|
|
|
RecursiveDirectoryRange getRecursiveDirectoryIterator(VFS::Path::NormalizedView path) const;
|
|
|
|
|
|
|
|
RecursiveDirectoryRange getRecursiveDirectoryIterator() const;
|
|
|
|
|
2022-05-14 01:58:00 +00:00
|
|
|
/// Retrieve the absolute path to the file
|
|
|
|
/// @note Throws an exception if the file can not be found.
|
|
|
|
/// @note May be called from any thread once the index has been built.
|
2022-06-19 11:28:33 +00:00
|
|
|
std::filesystem::path getAbsoluteFileName(const std::filesystem::path& name) const;
|
2022-05-14 01:58:00 +00:00
|
|
|
|
2015-03-17 20:59:39 +00:00
|
|
|
private:
|
2022-07-16 10:14:20 +00:00
|
|
|
std::vector<std::unique_ptr<Archive>> mArchives;
|
2015-03-17 20:59:39 +00:00
|
|
|
|
2023-12-17 14:20:48 +00:00
|
|
|
FileMap mIndex;
|
2024-05-02 23:07:47 +00:00
|
|
|
|
|
|
|
inline Files::IStreamPtr findNormalized(std::string_view normalizedPath) const;
|
2015-03-17 20:59:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|