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

# XGameSaveEnumerateBlobInfo

> XGameSaveEnumerateBlobInfo

# XGameSaveEnumerateBlobInfo

擷取 XGameSaveContainer 內容的 Blob 資訊。

## 語法

```cpp theme={null}
HRESULT XGameSaveEnumerateBlobInfo(  
         XGameSaveContainerHandle container,  
         void* context,  
         XGameSaveBlobInfoCallback* callback  
)  
```

### 參數

*container*   \_In\_\
類型：XGameSaveContainerHandle

包含要列舉之 Blob 的 **XGameSaveContainer** 控制代碼。

*context*   \_In\_opt\_\
類型：void\*

將傳遞至回呼函式的指標。

*callback*   \_In\_\
類型：XGameSaveBlobInfoCallback\*

針對容器中每個 Blob 呼叫的函式，傳回 false 可停止列舉。

### 傳回值

類型：HRESULT

函式結果。

## 備註

<Note>雖然在時間敏感執行緒上呼叫此函式是安全的，但 XGameSaveBlobInfoCallback 可能會造成延遲，視遊戲在回呼內執行的動作而定。例如，從回呼複製資料沒有問題；但是，執行任何非時間敏感的呼叫都可能延遲回呼的傳回。如需詳細資訊，請參閱[時間敏感執行緒](https://learn.microsoft.com/gaming/gdk/docs/gdk-dev/console-dev/overviews/threads/time-sensitive-threads)。</Note>

Blob 包含構成容器的實際可擷取資料。列舉 Blob 可讓您查看容器內所有可用的資料。您可以使用 [XGameSaveEnumerateBlobInfoByName](/zh-TW/reference/system/xgamesave/functions/xgamesaveenumerateblobinfobyname) 來列舉符合特定前置詞的 Blob。

```cpp theme={null}
// wrapper for calling a method on each item in the XGameSaveContainerInfo 
HRESULT Sample::_ForEachBlob(_In_ const XGameSaveContainerInfo* container, _In_ void* context, _In_ XGameSaveBlobInfoCallback* callback) 
{ 
    // create the container handle so we can inspect the contents 
    XGameSaveContainerHandle containerContext = nullptr; 
    HRESULT hr = XGameSaveCreateContainer(_provider, container->name, &containerContext); 
    if (SUCCEEDED(hr)) 
    { 
        // for each item in the container invoke the callback 
        hr = XGameSaveEnumerateBlobInfo(containerContext, context, callback); 
    } 
  
    if (containerContext != nullptr) 
    { 
        // make sure we close the context handle or we will leak memory 
        XGameSaveCloseContainer(containerContext); 
    } 
    return hr; 
} 
  
// check to see if the container has the minimum blobs we need to load a save 
HRESULT Sample::_CheckForRequiredBlobs(_In_ XGameSaveContainerInfo* container) 
{ 
    const char* blobNames[] = { 
        "WorldState", 
        "PlayerState", 
        "PlayerInventory" 
    }; 
    return _CheckContainerForRequiredBlobs(container, blobNames, _countof(blobNames)); 
} 
  
//confirm this container has the blobs the caller is looking for 
HRESULT Sample::_CheckContainerForRequiredBlobs( 
    _In_ XGameSaveContainerInfo* container, 
    _In_z_count_(countOfBlobs) const char** expectedBlobNames, 
    _In_ uint32_t countOfBlobs) 
{ 
    HRESULT hr; 
    struct QueryContext 
    { 
        QueryContext(const char** blobNames, uint32_t countOfBlobs) : 
            expectedCount(countOfBlobs), expectedBlobNames(blobNames), hitCount(0) 
        {} 
  
        uint32_t expectedCount; 
        const char** expectedBlobNames; 
        uint32_t hitCount; 
    }; 
  
    QueryContext qc{ expectedBlobNames, countOfBlobs }; 
  
    // simple check to see if we just see each of the blob names in the container 
    // a more robust check would identify which blob was missing to inform the caller 
    auto callback = [](_In_ const XGameSaveBlobInfo* info, _In_ void* context) 
    { 
        QueryContext* qc = reinterpret_cast<QueryContext*>(context); 
        for (uint32_t i = 0; i < qc->expectedCount; i++) 
        { 
            if (strcmp(qc->expectedBlobNames[i], info->name) == 0) 
            { 
                if (++qc->hitCount == qc->expectedCount) 
                { 
                    // all the expected names are here, can stop enum 
                    return false; 
                } 
            } 
        } 
        // keep enumerating 
        return true; 
    }; 
  
    hr = _ForEachBlob(container, &qc, callback); 
    if (SUCCEEDED(hr)) 
    { 
        if (qc.hitCount != qc.expectedCount) 
        { 
            printf("missing blobs from container!"); 
            hr = E_UNEXPECTED; 
        } 
    } 
  
    return hr; 
} 
  
// find the size of a set of blobs in a container 
HRESULT Sample::_GetContainerBlobsDataSize( 
    _In_ const XGameSaveContainerInfo* container, 
    _In_z_count_(countOfBlobs) const char** blobNames, 
    _In_ uint32_t countOfBlobs, 
    _Out_ size_t* containerSize) 
{ 
  
    *containerSize = 0; 
  
    struct BlobSize { 
        size_t size; 
        const char** blobNames; 
        uint32_t countOfBlobs; 
    }; 
  
    BlobSize blobSize = { 0, blobNames, countOfBlobs }; 
  
    HRESULT hr = _ForEachBlob(container, &blobSize, 
        [](const XGameSaveBlobInfo* info, void* ctx) 
    { 
        BlobSize* size = reinterpret_cast<BlobSize*>(ctx); 
        for (uint32_t i = 0; i < size->countOfBlobs; i++) 
        { 
            if (strcmp(info->name, size->blobNames[i]) == 0) 
            { 
                size->size += strlen(info->name) + 1; // length + null 
                size->size += info->size + sizeof(XGameSaveBlob); 
                break; 
            } 
        } 
        return true; 
    }); 
  
    if (SUCCEEDED(hr)) 
    { 
        *containerSize = blobSize.size; 
    } 
  
    return hr; 
} 
```

## 需求

**標頭：** XGameSave.h

**程式庫：** xgameruntime.lib

**支援的平台：** Windows、XBOX One 系列主機和 XBOX Series 主機

## 概念文件

* [時間敏感執行緒](https://learn.microsoft.com/gaming/gdk/docs/gdk-dev/console-dev/overviews/threads/time-sensitive-threads)

## 另請參閱

[XGameSave](/zh-TW/reference/system/xgamesave/xgamesave_members)\
[XGameSaveBlobInfo](/zh-TW/reference/system/xgamesave/structs/xgamesaveblobinfo)\
[XGameSaveEnumerateBlobInfoByName](/zh-TW/reference/system/xgamesave/functions/xgamesaveenumerateblobinfobyname)\
[偵錯遊戲存檔](/zh-TW/build/core-features/common/game-save/game-saves-debugging)


## Related topics

- [XGameSaveEnumerateBlobInfo](/reference/system/xgamesave/functions/xgamesaveenumerateblobinfo.md)
- [XGameSaveEnumerateBlobInfoByName](/reference/system/xgamesave/functions/xgamesaveenumerateblobinfobyname.md)
