将数据保存到指定容器内的指定 blob(文件)中。
语法
HRESULT Save(const std::string& containerName,
const std::string& blobName,
size_t dataSize,
const uint8_t* blobData);
参数
containerName _In_
类型:std::string
容器的名称。
blobName _In_
类型:std::string
blob 的名称。
dataSize _In_
类型:size_t
要写入 blob 的数据量。 此大小的最大限制为 16 MB (GS_MAX_BLOB_SIZE)。
blobData _In_
类型:uint8_t*
指向要写入到 blob 的字节的指针。
返回值
类型:HRESULT
成功时,此方法返回 S_OK,失败时则返回以下 HRESULT 代码:
- GS_INVALID_CONTAINER_NAME
- GS_OUT_OF_LOCAL_STORAGE
- GS_UPDATE_TOO_BIG
- GS_QUOTA_EXCEEDED
- GS_HANDLE_EXPIRED
示例
以下代码示例演示如何使用 保存 函数。
using Microsoft::Xbox::Wrappers::GameSave;
std::vector<uint8_t> saveData; // Contains the player's data.
Provider provider = new Provider();
if(SUCCEEDED(provider->Initialize(userHandle, mySCID))
{
HRESULT hr = provider->Save("Save_slot_1", "progress", saveData.size(), saveData.data());
if(FAILED(hr))
{
if(hr == E_GS_QUOTA_EXCEEDED)
{
// Message that the user must delete saves for this game.
}
else if(hr == E_GS_OUT_OF_LOCAL_STORAGE)
{
// Message to the user that they have run out of save
// space on the local device.
}
else if(hr == E_GS_UPDATE_TOO_BIG)
{
// This is really a development time thing to catch.
// Your save size was too large for this Save call. Save
// calls are limited to a maximum size of
// 16 MB (GS_MAX_BLOB_SIZE).
}
else if(hr == E_GS_HANDLE_EXPIRED)
{
// You must recreate the provider, and then try again.
}
else
{
// Log error.
}
}
}
备注
必须调用 初始化 方法,才可以从 Provider 类中调用任何其他方法。
要初始化存档游戏包装器,并同步指定用户的所有容器,请调用 初始化。
要从指定容器内给定的 blob 中加载数据,请调用 加载。
要求
头文件:xgamesavewrappers.hpp
支持平台:Windows、Xbox One 系列主机和 Xbox Series 主机
另请参阅
Microsoft.Xbox.Wrappers.XGameSave.Provider
XGameSave 包装器成员
游戏存档简化包装器
负载