> ## Documentation Index
> Fetch the complete documentation index at: https://docs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Save

> 将数据保存到指定容器中的指定 Blob（文件）。

# Microsoft.Xbox.Wrappers.XGameSave.Provider.Save

将数据保存到指定容器中的指定 Blob（文件）。

## 语法

```cpp theme={null}
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**

## 示例

以下代码示例演示了如何使用 **Save** 函数。

```cpp theme={null}
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.
      }
   }
}
```

## 备注

必须先调用 [Initialize](https://docs.xbox.com/zh-CN/reference/system/Wrappers/classes/provider/methods/xgamesave_wrapper_provider_initialize.md) 方法，然后才能调用 `Provider` 类中的任何其他方法。

若要初始化保存游戏包装器并同步指定用户的所有容器，请调用 [Initialize](https://docs.xbox.com/zh-CN/reference/system/Wrappers/classes/provider/methods/xgamesave_wrapper_provider_initialize.md)。

若要从指定容器中的给定 Blob 加载数据，请调用 [Load](https://docs.xbox.com/zh-CN/reference/system/Wrappers/classes/provider/methods/xgamesave_wrapper_provider_load.md)。

## 要求

**标头：** xgamesavewrappers.hpp

**支持的平台：** Windows、XBOX One 系列主机和 XBOX Series 主机

## 另请参阅

[Microsoft.Xbox.Wrappers.XGameSave.Provider](https://docs.xbox.com/zh-CN/reference/system/Wrappers/classes/provider/xgamesave_wrapper_provider.md)\
[XGameSave 包装器成员](https://docs.xbox.com/zh-CN/reference/system/Wrappers/xgamesave_wrapper_members.md)\
[Load](https://docs.xbox.com/zh-CN/reference/system/Wrappers/classes/provider/methods/xgamesave_wrapper_provider_load.md)


## Related topics

- [Game Saves 冲突](https://docs.xbox.com/zh-CN/services/playfab/player-progression/game-saves/conflicts.md)
- [Game Saves 限制](https://docs.xbox.com/zh-CN/services/playfab/player-progression/game-saves/limits.md)
- [XGameSaveBlob](https://docs.xbox.com/zh-CN/reference/system/xgamesave/structs/xgamesaveblob.md)
- [PFGameSaveFilesSetSaveDescriptionResult](https://docs.xbox.com/zh-CN/services/playfab/api-references/c/pfgamesavefiles/functions/pfgamesavefilessetsavedescriptionresult.md)
- [Game Saves UI 回调](https://docs.xbox.com/zh-CN/services/playfab/player-progression/game-saves/ui-callbacks.md)
