XStoreQueryGameAndDlcPackageUpdatesAsync
擷取遊戲套件及任何相關聯 DLC 或可感知中心之套件的可用更新清單,之後可用來下載並安裝這些更新。語法
HRESULT XStoreQueryGameAndDlcPackageUpdatesAsync(
const XStoreContextHandle storeContextHandle,
XAsyncBlock* async
)
參數
storeContextHandle _In_類型:XStoreContextHandle 由 XStoreCreateContext 傳回之使用者的商店內容控制代碼。 async _Inout_
類型:XAsyncBlock* 定義正在進行之非同步工作的 XAsyncBlock。XAsyncBlock 可用來輪詢呼叫的狀態並擷取呼叫結果。如需詳細資訊,請參閱 XAsyncBlock。
傳回值
類型:HRESULT HRESULT 成功或錯誤碼。備註
若要擷取可用更新清單以及此函式的執行結果,請在呼叫此函式之後呼叫 XStoreQueryGameAndDlcPackageUpdatesResult。若要取得要擷取的更新數目,請在呼叫此函式之後呼叫 XStoreQueryGameAndDlcPackageUpdatesResultCount。結果計數函式很重要,因為它可讓您判斷要傳遞給結果函式的陣列適當大小。| 呼叫內容 | 結果 |
|---|---|
| 系列遊戲中心 | 系列遊戲中心本身、任何相依於它的可感知中心遊戲,以及與任何可感知中心遊戲或系列遊戲中心本身相關聯的任何 DLC、附加元件。 |
| 其他遊戲 | 遊戲本身以及與其相關聯的 DLC、附加元件。 |
struct UpdateContext
{
XStoreContextHandle storeContextHandle;
XTaskQueueHandle taskQueueHandle;
bool downloadOnly;
};
void CALLBACK DownloadAndInstallPackageUpdatesCallback(XAsyncBlock* asyncBlock)
{
HRESULT hr = XStoreDownloadAndInstallPackageUpdatesResult(asyncBlock);
if (FAILED(hr))
{
printf("Failed download and install package updates: 0x%x\r\n", hr);
return;
}
}
void CALLBACK DownloadPackageUpdatesCallback(XAsyncBlock* asyncBlock)
{
HRESULT hr = XStoreDownloadPackageUpdatesResult(asyncBlock);
if (FAILED(hr))
{
printf("Failed download package updates: 0x%x\r\n", hr);
return;
}
}
void CALLBACK QueryGameAndDlcPackageUpdatesCallback(XAsyncBlock* asyncBlock)
{
UpdateContext* updateContext = reinterpret_cast<UpdateContext*>(asyncBlock->context);
uint32_t count;
HRESULT hr = XStoreQueryGameAndDlcPackageUpdatesResultCount(
asyncBlock,
&count);
if (FAILED(hr))
{
printf("Failed retrieve the game and dlc update count: 0x%x\r\n", hr);
delete updateContext;
return;
}
printf("Number of updates: %d", count);
if (count > 0)
{
XStorePackageUpdate* updates = new XStorePackageUpdate[count];
hr = XStoreQueryGameAndDlcPackageUpdatesResult(
asyncBlock,
count,
&updates);
if (FAILED(hr))
{
delete[] updates;
delete updateContext;
printf("Failed retrieve the game and dlc updates: 0x%x\r\n", hr);
return;
}
auto packageIdentifiers = new char[count][XPACKAGE_IDENTIFIER_MAX_LENGTH];
for (uint32_t index = 0; index < count; index++)
{
printf("packageIdentifier: %s\r\n", updates[index].packageIdentifier);
printf("isMandatory : %s\r\n", updates[index].isMandatory ? "true" : "false");
memcpy(&packageIdentifiers[index], updates[index].packageIdentifier, XPACKAGE_IDENTIFIER_MAX_LENGTH);
}
delete[] updates;
auto downloadAsyncBlock = std::make_unique<XAsyncBlock>();
ZeroMemory(downloadAsyncBlock.get(), sizeof(*downloadAsyncBlock));
downloadAsyncBlock->queue = updateContext->taskQueueHandle;
downloadAsyncBlock->context = updateContext;
if (updateContext->downloadOnly)
{
// NOTE: This can be used instead to only perform the download.
// This is helpful if you wish to download in the background
// while the player continues to play. Once the download is completed,
// you could then warn the user and call XStoreDownloadAndInstallPackageUpdatesAsync
// to trigger the game to update which may close the game.
downloadAsyncBlock->callback = DownloadPackageUpdatesCallback;
hr = XStoreDownloadPackageUpdatesAsync(
updateContext->storeContextHandle,
(const char**)(&packageIdentifiers[0]),
count,
downloadAsyncBlock.get());
if (FAILED(hr))
{
delete updateContext;
delete[] packageIdentifiers;
printf("Failed start download: 0x%x\r\n", hr);
return;
}
}
else
{
downloadAsyncBlock->callback = DownloadAndInstallPackageUpdatesCallback;
hr = XStoreDownloadAndInstallPackageUpdatesAsync(
updateContext->storeContextHandle,
(const char**)(&packageIdentifiers[0]),
count,
downloadAsyncBlock.get());
if (FAILED(hr))
{
delete updateContext;
delete[] packageIdentifiers;
printf("Failed start download and install: 0x%x\r\n", hr);
return;
}
}
delete[] packageIdentifiers;
}
else
{
delete updateContext;
}
}
void QueryGameAndDlcPackageUpdates(XStoreContextHandle storeContextHandle, XTaskQueueHandle taskQueueHandle, bool downloadOnly)
{
UpdateContext* updateContext = new UpdateContext;
updateContext->storeContextHandle = storeContextHandle;
updateContext->taskQueueHandle = taskQueueHandle;
updateContext->downloadOnly = downloadOnly;
auto asyncBlock = std::make_unique<XAsyncBlock>();
ZeroMemory(asyncBlock.get(), sizeof(*asyncBlock));
asyncBlock->queue = taskQueueHandle;
asyncBlock->context = updateContext;
asyncBlock->callback = QueryGameAndDlcPackageUpdatesCallback;
HRESULT hr = XStoreQueryGameAndDlcPackageUpdatesAsync(
storeContextHandle,
asyncBlock.get());
if (FAILED(hr))
{
printf("Failed to query game and DLC updates: 0x%x\r\n", hr);
delete updateContext;
return;
}
if(FAILED(XAsyncGetStatus(asyncBlock, true)))
{
printf("XStoreQueryGameAndDlcPackageUpdatesAsync failed\r\n");
return;
}
}
需求
標頭: XStore.h (包含在 XGameRuntime.h 中) 程式庫: xgameruntime.lib 支援的平台: Windows、XBOX One 系列主機和 XBOX Series 主機概念文件
另請參閱
XStoreXStoreQueryGameAndDlcPackageUpdatesResult
XStoreQueryGameAndDlcPackageUpdatesResultCount
系列遊戲中心
