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

# XPackageCreateInstallationMonitor

> XPackageCreateInstallationMonitor

# XPackageCreateInstallationMonitor

インストール状態のモニターを作成します。

## Syntax

```cpp theme={null}
HRESULT XPackageCreateInstallationMonitor(  
         const char* packageIdentifier,  
         uint32_t selectorCount,  
         XPackageChunkSelector* selectors,  
         uint32_t minimumUpdateIntervalMs,  
         XTaskQueueHandle queue,  
         XPackageInstallationMonitorHandle* installationMonitor  
)  
```

### Parameters

*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\_opt\_(selectorCount)\
型: [XPackageChunkSelector\*](/reference/system/xpackage/structs/xpackagechunkselector)

監視するチャンクを指定するセレクターの配列。

*minimumUpdateIntervalMs*   \_In\_\
型: uint32\_t

モニターの解像度 (ミリ秒単位)。

*queue*   \_In\_opt\_\
型: XTaskQueueHandle

更新が実行されるキュー。

*installationMonitor*   \_Out\_\
型: XPackageInstallationMonitorHandle\*

戻り時、作成されたインストール モニターを指します。

### Return value

型: HRESULT

HRESULT の成功またはエラー コード。

## Remarks

<Note>この関数はタイム センシティブ スレッドで呼び出すのは安全ではありません。詳細については、[タイム センシティブ スレッド](https://learn.microsoft.com/gaming/gdk/docs/gdk-dev/console-dev/overviews/threads/time-sensitive-threads) を参照してください。</Note>

**XPackageCreateInstallationMonitor** は、インストールの状態を追跡するモニターを作成します。モニターは、指定された更新間隔によって管理される定期的なペースで自身を更新およびリフレッシュします。更新は指定されたタスク キュー上でスケジュールされます。間隔がゼロの場合、更新は決して実行されず、インストールの一度限りのスナップショットとなるインストール モニターが作成されます。間隔がゼロで渡された場合、queue パラメーターは null にできます。

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

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

```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); 
```

インストールされたすべてのコンテンツには一意の識別子があります。パッケージの識別子を知っており、そのコンテンツにアクセス権があれば、任意のパッケージのインストールを監視できます。実行中のプロセスは自身のパッケージ識別子を取得できます。

```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/packaging-installstatus)
* [タイム センシティブ スレッド](https://learn.microsoft.com/gaming/gdk/docs/gdk-dev/console-dev/overviews/threads/time-sensitive-threads)
* [更新の確認](https://learn.microsoft.com/gaming/gdk/docs/store/commerce/fundamentals/xstore-checking-for-updates)

## 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)
- [ストリーミング インストール: ステータス](/ja-jp/build/core-features/common/packaging/packaging-installstatus.md)
- [更新プログラムの確認](/ja-jp/publishing/xstore-commerce/xstore-checking-updates.md)
- [XPackageCloseInstallationMonitorHandle](/ja-jp/reference/system/xpackage/functions/xpackagecloseinstallationmonitorhandle.md)
