> ## 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.

# XPackageInstallChunksAsync

> XPackageInstallChunksAsync

# XPackageInstallChunksAsync

启动区块的安装。

## 语法

```cpp theme={null}
HRESULT XPackageInstallChunksAsync(  
         const char* packageIdentifier,  
         uint32_t selectorCount,  
         XPackageChunkSelector* selectors,  
         uint32_t minimumUpdateIntervalMs,  
         bool suppressUserConfirmation,  
         XAsyncBlock* asyncBlock  
)  
```

### 参数

*packageIdentifier*   \_In\_z\_\
类型：char\*

用于在磁盘上唯一标识已安装包的字符串。有关包标识符的详细信息，请参阅[管理和授权可下载内容 (DLC)](https://learn.microsoft.com/gaming/gdk/docs/store/commerce/fundamentals/xstore-manage-and-license-optional-packages)。

*selectorCount*   \_In\_\
类型：uint32\_t

*selectors* 参数中的选择器数量。

*selectors*   \_In\_reads\_(selectorCount)\
类型：[XPackageChunkSelector\*](/reference/system/xpackage/structs/xpackagechunkselector)

一个选择器数组，用于指定要安装的区块。

*minimumUpdateIntervalMs*   \_In\_\
类型：uint32\_t

更新之间的间隔时间（以毫秒为单位）。

*suppressUserConfirmation*   \_In\_\
类型：bool

如果待安装的区块超过预设大小，则会显示确认提示。如果 *suppressUserConfirmation* 为 true，则不会显示提示，安装将像用户已接受一样继续进行。这样，游戏就可以呈现自己的 UI。如果游戏使用此参数，还应调用 [XPackageEstimateDownloadSize](/reference/system/xpackage/functions/xpackageestimatedownloadsize) 以获取将向用户显示的大小。[XPackageEstimateDownloadSize](/reference/system/xpackage/functions/xpackageestimatedownloadsize) 还会返回一个布尔值，用于指示大小是否已达到需要显示提示的程度。如果需要下载确认，则游戏必须使用自己的 UI 显示确认，或让 **XPackageInstallChunks** 显示确认。

*asyncBlock*   \_Inout\_\
类型：[XAsyncBlock\*](/reference/system/xasync/structs/xasyncblock)

用于监视异步调用状态的 **XAsyncBlock**。

### 返回值

类型：HRESULT

HRESULT 成功或错误代码。

## 备注

[XPackageInstallChunks](/reference/system/xpackage/functions/xpackageinstallchunks) 有一个异步变体。区块的安装可能需要提示用户接受下载大小。

此示例展示了如何使用异步 API 安装 BigMaps：

```cpp theme={null}
void CALLBACK BigMapsInstallProgress(
    void* /* context */,
    XPackageInstallationMonitorHandle monitor)
{
    XPackageInstallationProgress progress;
    XPackageGetInstallationProgress(monitor, &progress);
    if (progress.completed)
    {
        printf("BigMaps Installed\n");
        XPackageCloseInstallationMonitorHandle(monitor);
    }
}

void CALLBACK BigMapsAsyncInstallComplete(XAsyncBlock* asyncBlock)
{
    XPackageInstallationMonitorHandle monitor;
    HRESULT hr = XPackageInstallChunksResult(asyncBlock, &monitor);
    delete asyncBlock;

    if (SUCCEEDED(hr))
    {
        XTaskQueueRegistrationToken token;
        if (FAILED(XPackageRegisterInstallationProgressChanged(
            monitor,
            nullptr,
            BigMapsInstallProgress, &token)))
        {
            XPackageCloseInstallationMonitorHandle(monitor);
        }
    }
}

HRESULT InstallBigMapsAsync(XTaskQueueHandle queue)
{
    char id[XPACKAGE_IDENTIFIER_MAX_LENGTH];
    HRESULT hr = XPackageGetCurrentProcessPackageIdentifier(_countof(id), id);
    if (FAILED(hr)) return hr;

    XPackageChunkSelector selector;
    selector.type = XPackageChunkSelectorType::Tag;
    selector.tag = "BigMaps";

    XAsyncBlock* asyncBlock = new (std::nothrow) XAsyncBlock{};
    asyncBlock->callback = BigMapsAsyncInstallComplete;
    asyncBlock->queue = queue;

    hr = XPackageInstallChunksAsync(
        id, 1, &selector, 1000,
        false, asyncBlock);

    if (FAILED(hr))
    {
        delete asyncBlock;
    }

    return hr;
}
```

## 要求

**头文件：** XPackage.h

**库：** xgameruntime.lib

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

## 概念文档

* [异步编程设计目标与改进](/build/core-features/common/async/async-whitepaper)

## 另请参阅

[XPackage](/reference/system/xpackage/xpackage_members)\
[流式安装和智能交付](/build/core-features/common/packaging/overviews/streaming_install-intelligent_delivery)\
[XPackageInstallChunks](/reference/system/xpackage/functions/xpackageinstallchunks)


## Related topics

- [XPackageInstallChunksResult](/zh-CN/reference/system/xpackage/functions/xpackageinstallchunksresult.md)
- [XPackage](/zh-CN/reference/system/xpackage/xpackage_members.md)
- [面向 GDK 的 Unity C# API 包装器](/zh-CN/build/gdk-and-engines/unity/unity-api-wrappers.md)
- [XPackageInstallChunks](/zh-CN/reference/system/xpackage/functions/xpackageinstallchunks.md)
- [XPackageChangeChunkInstallOrder](/zh-CN/reference/system/xpackage/functions/xpackagechangechunkinstallorder.md)
