docs: update resources API docs
This commit is contained in:
@@ -2,19 +2,17 @@
|
||||
|
||||
**命名空间**: `XCEngine::Resources`
|
||||
|
||||
**类型**: `class` (extends IArchive)
|
||||
**类型**: `class`
|
||||
|
||||
**描述**: 文件归档封装类,用于读取归档包(如 .pak、.zip)中的资源文件。
|
||||
**头文件**: `XCEngine/Resources/FileArchive.h`
|
||||
|
||||
**继承自**: `IArchive`
|
||||
|
||||
**描述**: 文件归档读取器,将文件系统目录作为虚拟归档进行访问。
|
||||
|
||||
## 概述
|
||||
|
||||
`FileArchive` 实现了 `IArchive` 接口,提供从单个归档包文件中读取资源的功能。它维护已打开归档的路径和有效性状态。
|
||||
|
||||
## 头文件
|
||||
|
||||
```cpp
|
||||
#include <XCEngine/Resources/FileArchive.h>
|
||||
```
|
||||
`FileArchive` 实现了 `IArchive` 接口,用于将文件系统目录作为虚拟归档进行访问。它维护已打开目录的路径和有效性状态,支持读取文件、检查存在性、获取文件大小等操作。
|
||||
|
||||
## 继承关系
|
||||
|
||||
@@ -25,60 +23,53 @@ IArchive
|
||||
|
||||
## 公共方法
|
||||
|
||||
### 构造与析构
|
||||
|
||||
| 方法 | 描述 |
|
||||
|------|------|
|
||||
| `FileArchive()` | 默认构造 |
|
||||
| `~FileArchive()` | 析构函数,关闭归档 |
|
||||
|
||||
### IArchive 接口实现
|
||||
|
||||
| 方法 | 描述 |
|
||||
|------|------|
|
||||
| `bool Open(const Containers::String& path) override` | 打开归档文件 |
|
||||
| `void Close() override` | 关闭归档文件 |
|
||||
| `bool Read(const Containers::String& fileName, void* buffer, size_t size, size_t offset) const override` | 从归档中读取文件数据 |
|
||||
| `size_t GetSize(const Containers::String& fileName) const override` | 获取归档内文件大小 |
|
||||
| `bool Exists(const Containers::String& fileName) const override` | 检查文件是否存在于归档中 |
|
||||
| `void Enumerate(const Containers::String& pattern, Containers::Array<Containers::String>& outFiles) const override` | 枚举归档内匹配的文件(当前为 stub) |
|
||||
| `bool IsValid() const override` | 检查归档是否有效 |
|
||||
|
||||
## 实现说明
|
||||
|
||||
**注意**: `Enumerate()` 当前为 stub,仅清空输出数组。
|
||||
|
||||
### 访问器
|
||||
|
||||
| 方法 | 描述 |
|
||||
|------|------|
|
||||
| `const Containers::String& GetPath() const` | 获取归档文件路径 |
|
||||
| [`FileArchive()`](filearchive.md) | 默认构造 |
|
||||
| [`~FileArchive()`](filearchive.md) | 析构函数,自动关闭归档 |
|
||||
| [`Open(...)`](open.md) | 打开归档目录 |
|
||||
| [`Close()`](close.md) | 关闭归档 |
|
||||
| [`Read(...)`](read.md) | 读取文件数据 |
|
||||
| [`GetSize(...)`](getsize.md) | 获取文件大小 |
|
||||
| [`Exists(...)`](exists.md) | 检查文件是否存在 |
|
||||
| [`Enumerate(...)`](enumerate.md) | 枚举匹配的文件(暂未实现) |
|
||||
| [`IsValid()`](filearchive.md) | 检查归档是否有效 |
|
||||
| [`GetPath()`](filearchive.md) | 获取归档路径 |
|
||||
|
||||
## 使用示例
|
||||
|
||||
```cpp
|
||||
#include <XCEngine/Resources/FileArchive.h>
|
||||
|
||||
// 创建并打开归档
|
||||
FileArchive archive;
|
||||
if (archive.Open("data/resources.pak")) {
|
||||
if (archive.Open("resources/textures/")) {
|
||||
// 检查文件是否存在
|
||||
if (archive.Exists("textures/player.png")) {
|
||||
if (archive.Exists("player.png")) {
|
||||
// 获取文件大小
|
||||
size_t size = archive.GetSize("textures/player.png");
|
||||
size_t size = archive.GetSize("player.png");
|
||||
|
||||
// 读取文件内容
|
||||
Containers::Array<Core::uint8> buffer(size);
|
||||
archive.Read("textures/player.png", buffer.Data(), size, 0);
|
||||
if (archive.Read("player.png", buffer.Data(), size, 0)) {
|
||||
// 处理文件数据
|
||||
}
|
||||
}
|
||||
|
||||
// 枚举文件
|
||||
// 枚举匹配的文件
|
||||
Containers::Array<Containers::String> files;
|
||||
archive.Enumerate("textures/*.png", files);
|
||||
archive.Enumerate("*.png", files);
|
||||
|
||||
archive.Close();
|
||||
}
|
||||
```
|
||||
|
||||
## 实现说明
|
||||
|
||||
- `Enumerate()` 当前为 stub,仅清空输出数组,未实现模式匹配功能。
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [IArchive](../filesystem/filesystem.md) - 归档接口
|
||||
- [ResourceFileSystem](../filesystem/filesystem.md) - 资源文件系统
|
||||
- [Resources 总览](../resources.md) - 返回模块总览
|
||||
- [Resources 模块总览](../resources.md) - 返回模块总览
|
||||
- [IArchive](../resourcefilesystem/resourcefilesystem.md) - 归档接口定义
|
||||
- [ResourceFileSystem](../resourcefilesystem/resourcefilesystem.md) - 资源文件系统
|
||||
|
||||
Reference in New Issue
Block a user