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

# XPackageGetInstallationProgress

> XPackageGetInstallationProgress

# XPackageGetInstallationProgress

インストールの現在の進行状況を返します。

## Syntax

```cpp theme={null}
void XPackageGetInstallationProgress(  
         XPackageInstallationMonitorHandle installationMonitor,  
         XPackageInstallationProgress* progress  
)  
```

### Parameters

*installationMonitor*   \_In\_\
型: XPackageInstallationMonitorHandle

インストール モニターへのハンドル。

*progress*   \_Out\_\
型: [XPackageInstallationProgress\*](/reference/system/xpackage/structs/xpackageinstallationprogress)

戻り時、インストールの現在の進行状況を含みます。

### Return value

型: void

## Remarks

インストールの現在の進行状況を取得するには、[XPackageGetInstallationProgress](/reference/system/xpackage/functions/xpackagegetinstallationprogress) を呼び出します。インストール中の変更の通知を受けるには、コールバックを登録します。パッケージ全体または特定のサブセットに対してインストール モニターを作成できます。

新しいコンテンツの新規インストール中の一瞬、インストールがまだ完全に開始されていないため、ランタイムはパッケージの合計サイズを計算できません。この場合、ランタイムは totalBytes の値として UINT64\_MAX を返し、その他のすべてのフィールドについてはゼロまたは false を返します。

例:

```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}
hr = XPackageRegisterInstallationProgressChanged(
    monitor,
    nullptr,
    ProgressChangedCallback,
    &token);
```

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

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

## Requirements

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

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

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

## Conceptual documentation

* [インテリジェント デリバリー: 言語指定子](/build/core-features/common/packaging/intelligentdelivery-language)

## See also

[XPackage](/reference/system/xpackage/xpackage_members)


## Related topics

- [XPackageInstallationProgressCallback](/ja-jp/reference/system/xpackage/functions/xpackageinstallationprogresscallback.md)
- [XPackageRegisterInstallationProgressChanged](/ja-jp/reference/system/xpackage/functions/xpackageregisterinstallationprogresschanged.md)
- [XPackageUpdateInstallationMonitor](/ja-jp/reference/system/xpackage/functions/xpackageupdateinstallationmonitor.md)
- [XPackage](/ja-jp/reference/system/xpackage/xpackage_members.md)
- [XPackageCreateInstallationMonitor](/ja-jp/reference/system/xpackage/functions/xpackagecreateinstallationmonitor.md)
