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

# XPackageInstallationProgressCallback

> XPackageInstallationProgressCallback

# XPackageInstallationProgressCallback

[XPackageRegisterInstallationProgressChanged](/reference/system/xpackage/functions/xpackageregisterinstallationprogresschanged) が使用するコールバック。

## Syntax

```cpp theme={null}
void XPackageInstallationProgressCallback(  
         void* context,  
         XPackageInstallationMonitorHandle monitor  
)  
```

### Parameters

*context*   \_In\_\
型: void\*

[XPackageRegisterInstallationProgressChanged](/reference/system/xpackage/functions/xpackageregisterinstallationprogresschanged) に渡されたコンテキスト。

*monitor*   \_In\_\
型: XPackageInstallationMonitorHandle

インストールに対するインストール モニター。

### Return value

型: void

## Remarks

**PackageInstallationProgressCallback** は、ProgressChanged 通知の登録時に指定されたペースで呼び出されます。

ゲームは起動マーカーを実装できるため、完全にインストールされる前に実行できます。ゲームは、どの部分がインストールされていて、どの部分がインストールされていないかを知る必要があります。次の例では、ゲームは指定されたトラック名を持つレーストラックに関連付けられたチャンクがいつインストールされるかを知る必要があります:

```cpp theme={null}
void CALLBACK ProgressChangedCallback(
    void* /* context*/,
    XPackageInstallationMonitorHandle monitor)
{
    XPackageInstallationProgress progress;
    XPackageGetInstallationProgress(monitor, &progress);

    if (progress.completed)
    {
        printf("Track ready\n");
        XPackageCloseInstallationMonitorHandle(monitor);
    }
}

HRESULT StartMonitoring(XTaskQueueHandle queue, char* trackName)
{
    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 = trackName;

    XPackageInstallationMonitorHandle monitor;
    hr = XPackageCreateInstallationMonitor(
        id,         // Identity to be monitored
        1,          // Number of selectors
        &selector,  // Selectors
        1000,       // Resolution of the monitor, in milliseconds
        queue,      // Queue where updates are performed
        &monitor);
    if (FAILED(hr)) return hr;

    XTaskQueueRegistrationToken token;
    hr = XPackageRegisterInstallationProgressChanged(
        monitor,
        nullptr,
        ProgressChangedCallback,
        &token);

    if (FAILED(hr))
    {
        XPackageCloseInstallationMonitorHandle(monitor);
    }

    return hr;
}
```

上記のコードの各 API 呼び出しを順に見ていきましょう:

```cpp theme={null}
XPackageGetCurrentProcessPackageIdentifier(_countof(id), id); 
```

インストールされたすべてのコンテンツには一意の識別子があります。パッケージの識別子を知っており、そのコンテンツにアクセス権があれば、任意のパッケージのインストールを監視できます。実行中のプロセスは自身のパッケージ識別子を取得できます。パッケージ識別子の詳細については、[ダウンロード可能なコンテンツ (DLC) の管理およびライセンス](https://learn.microsoft.com/gaming/gdk/docs/store/commerce/fundamentals/xstore-manage-and-license-optional-packages) を参照してください。

```cpp theme={null}
XPackageCreateInstallationMonitor(
    id,         // Identity to be monitored
    1,          // Number of selectors
    &selector,  // Selectors
    1000,       // Resolution of the monitor, in milliseconds
    queue,      // Queue where updates are performed
    &monitor);
```

これにより、インストールの状態を追跡するモニターが作成されます。このインストール モニターは、定期的なペースで自身を更新します。インストールの現在の進行状況を取得するには、[XPackageGetInstallationProgress](/reference/system/xpackage/functions/xpackagegetinstallationprogress) を呼び出します。インストール中の変更の通知を受けるには、コールバックを登録します。

パッケージ全体または特定のサブセットに対してインストール モニターを作成できます。ここでは、トラック名のインストール進行状況を知りたいと指定する「セレクター」を定義しています。インストール モニターが進捗状況のスナップショットを更新する頻度を指定できます (この場合は 1000 ms)。この速度が上限です。時間内に進行がなかった場合は、より遅くなる可能性があります。

```cpp theme={null}
XPackageRegisterInstallationProgressChanged(
    monitor,
    nullptr,
    ProgressChangedCallback,
    &token);
```

トラックがいつロードを完了したかを知りたいので、モニターに進捗変更イベントを登録します。このコールバックは、モニターが作成されたときに提供されたタスク キューを通じて、[XPackageCreateInstallationMonitor](/reference/system/xpackage/functions/xpackagecreateinstallationmonitor) で指定されたおおよそのペースで呼び出されます。コールバック内で、ゲーム内の進捗を描画したり、トラックの準備が整ったことをゲームに通知したりできます。

この例では、インストール モニターを閉じますが、通知の登録は解除しません。インストール モニター通知のライフタイムはインストール モニターに結び付けられているため、モニターを閉じることで、それに関連するすべての通知が登録解除されます。

## Requirements

**ヘッダー:** XPackage.h

**ライブラリ:** xgameruntime.lib

**サポートされているプラットフォーム:** Windows、XBOX One ファミリー本体および XBOX Series 本体

## See also

[XPackage](/reference/system/xpackage/xpackage_members)\
[ストリーミング インストールとインテリジェント デリバリー](/build/core-features/common/packaging/overviews/streaming_install-intelligent_delivery)\
[XPackageGetInstallationProgress](/reference/system/xpackage/functions/xpackagegetinstallationprogress)\
[XPackageCreateInstallationMonitor](/reference/system/xpackage/functions/xpackagecreateinstallationmonitor)


## Related topics

- [XPackageRegisterInstallationProgressChanged](/ja-jp/reference/system/xpackage/functions/xpackageregisterinstallationprogresschanged.md)
- [XPackage](/ja-jp/reference/system/xpackage/xpackage_members.md)
- [XPackageInstallationProgress](/ja-jp/reference/system/xpackage/structs/xpackageinstallationprogress.md)
- [XPackageGetInstallationProgress](/ja-jp/reference/system/xpackage/functions/xpackagegetinstallationprogress.md)
- [XPackageUnregisterInstallationProgressChanged](/ja-jp/reference/system/xpackage/functions/xpackageunregisterinstallationprogresschanged.md)
