ResourceFileSystem
命名空间: XCEngine::Resources
类型: class
描述: 资源文件系统,负责资源文件的查找、读取和虚拟文件系统(支持目录和归档包)管理。
概述
ResourceFileSystem 实现了虚拟资源文件系统,支持从多个目录和归档包(如 .zip、.pak)中查找和读取资源。它通过 IArchive 接口支持不同的归档格式,并提供资源信息缓存。
IArchive 接口
抽象归档接口,用于封装单个归档包或目录的读取操作。
公共方法
| 方法 |
描述 |
virtual bool Open(const Containers::String& path) |
打开归档 |
virtual void Close() |
关闭归档 |
virtual bool Read(fileName, buffer, size, offset) |
从归档中读取文件 |
virtual size_t GetSize(fileName) |
获取文件大小 |
virtual bool Exists(fileName) |
检查文件是否存在 |
virtual void Enumerate(pattern, outFiles) |
枚举匹配的文件 |
virtual bool IsValid() const |
是否有效 |
ResourceInfo 结构体
| 成员 |
类型 |
描述 |
path |
Containers::String |
资源相对路径 |
size |
size_t |
文件大小(字节) |
modifiedTime |
Core::uint64 |
修改时间戳 |
inArchive |
bool |
是否在归档包中 |
archivePath |
Containers::String |
所属归档路径 |
单例访问
| 方法 |
描述 |
static ResourceFileSystem& Get() |
获取单例实例 |
公共方法
生命周期
| 方法 |
描述 |
void Initialize(const Containers::String& rootPath) |
初始化,设置资源根目录 |
void Shutdown() |
关闭,释放所有归档 |
归档和目录管理
| 方法 |
描述 |
bool AddArchive(const Containers::String& archivePath) |
添加归档包(优先查找) |
bool AddDirectory(const Containers::String& directoryPath) |
添加资源目录 |
void RemoveArchive(const Containers::String& archivePath) |
移除归档包 |
资源查找
| 方法 |
描述 |
bool FindResource(const Containers::String& relativePath, Containers::String& outAbsolutePath) |
查找资源的绝对路径 |
bool Exists(const Containers::String& relativePath) |
检查资源是否存在 |
Containers::Array<Core::uint8> ReadResource(const Containers::String& relativePath) |
读取资源文件内容(字节数组) |
资源信息
| 方法 |
描述 |
bool GetResourceInfo(const Containers::String& relativePath, ResourceInfo& outInfo) |
获取资源信息 |
void EnumerateResources(const Containers::String& pattern, Containers::Array<ResourceInfo>& outResources) |
枚举匹配的资源 |
使用示例
相关文档