Files
XCEngine/docs/api/resources/resource-file-system/get-resource-info.md

1.7 KiB

ResourceFileSystem::GetResourceInfo

方法签名

bool GetResourceInfo(const Containers::String& relativePath, ResourceInfo& outInfo) const;

所属类

XCEngine::Resources::ResourceFileSystem

描述

获取指定资源的详细信息,包括路径、大小、修改时间和所属档案等。查询结果会被缓存以提高后续查询性能。

此方法线程安全。

参数

参数名 类型 描述
relativePath const Containers::String& 资源的相对路径
outInfo ResourceInfo& 输出参数,接收资源信息

返回值

  • bool - 成功获取返回 true,资源不存在返回 false

示例

#include "Resources/ResourceFileSystem.h"

using namespace XCEngine::Resources;

ResourceFileSystem& fs = ResourceFileSystem::Get();
fs.Initialize("C:/Game/Resources");
fs.AddDirectory("C:/Game/Assets");
fs.AddArchive("C:/Game/Paks/Textures.pak");

ResourceInfo info;

// 获取目录中的资源信息
if (fs.GetResourceInfo("shaders/forward.glsl", info)) {
    printf("Path: %s\n", info.path.CStr());
    printf("Size: %zu bytes\n", info.size);
    printf("In Archive: %s\n", info.inArchive ? "Yes" : "No");
}

// 获取档案中的资源信息
if (fs.GetResourceInfo("textures/player/diffuse.png", info)) {
    printf("Path: %s\n", info.path.CStr());
    printf("Archive: %s\n", info.archivePath.CStr());
    printf("In Archive: %s\n", info.inArchive ? "Yes" : "No");
}

注意事项

  • 首次查询后信息会被缓存
  • 当前实现的大小和修改时间为占位值,待完整实现
  • ResourceInfo::sizeResourceInfo::modifiedTime 的获取需要操作系统 API 支持