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