1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-03 17:37:18 +00:00
OpenMW/components/vfs/manager.hpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

91 lines
3.3 KiB
C++
Raw Normal View History

#ifndef OPENMW_COMPONENTS_RESOURCEMANAGER_H
#define OPENMW_COMPONENTS_RESOURCEMANAGER_H
#include <components/files/istreamptr.hpp>
#include <filesystem>
#include <memory>
#include <string>
#include <string_view>
#include <vector>
#include "filemap.hpp"
#include "pathutil.hpp"
2023-05-31 21:11:03 +00:00
namespace VFS
{
class Archive;
class RecursiveDirectoryRange;
/// @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.
/// @par Most of the methods in this class are considered thread-safe, see each method documentation for details.
class Manager
{
public:
Manager();
~Manager();
// Empty the file index and unregister archives.
void reset();
/// Register the given archive. All files contained in it will be added to the index on the next buildIndex()
/// call.
void addArchive(std::unique_ptr<Archive>&& archive);
/// Build the file index. Should be called when all archives have been registered.
void buildIndex();
/// Does a file with this name exist?
/// @note May be called from any thread once the index has been built.
bool exists(const Path::Normalized& name) const;
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;
/// Retrieve a file by name.
/// @note Throws an exception if the file can not be found.
/// @note May be called from any thread once the index has been built.
Files::IStreamPtr get(const Path::Normalized& name) const;
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.
/// @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
std::string getArchive(const Path::Normalized& name) const;
2023-05-10 00:07:08 +00:00
/// Recursively iterate over the elements of the given path
/// 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;
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.
std::filesystem::path getAbsoluteFileName(const std::filesystem::path& name) const;
2022-05-14 01:58:00 +00:00
private:
std::vector<std::unique_ptr<Archive>> mArchives;
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;
};
}
#endif