개발 콘솔에서 지정된 저장소 장치에 사용할 수 있는 총 바이트 수를 가져옵니다.
구문
HRESULT XtfGetAvailableSpaceForAppInstallation(
LPCWSTR address,
LPCWSTR storageName,
UINT64 *bytes
)
매개 변수
address
형식: LPCWSTR
[in] 확인할 개발 콘솔의 주소입니다.
storageName
형식: LPCWSTR
[in] 검사할 저장소 장치의 이름입니다. 다음의 값이 허용됩니다.
| 값 | 설명 |
|---|---|
nullptr |
기본값 저장소 장치. |
| internal | 내부 저장소 장치. |
bytes
형식: UINT64*
[out] 주소에서 지정된 개발 콘솔을 위해 storageName에서 지정된 저장소 장치에서 사용 가능한 전체 바이트 수입니다.
반환 값
형식: HRESULT
성공한 경우 S_OK을(를) 반환하고, 그렇지 않으면 HRESULT 오류 코드를 반환합니다.
설명
이 함수는 개발 콘솔에 대해 지정된 저장소 장치에서 사용할 수 있는 총 바이트 수를 가져오며, 이를 사용하면 도구 개발자는 콘솔을 위한 사용자 지정 배포 도구를 작성하여 설치 프로세스를 시작하기 전에 앱 패키지를 설치하는데 필요한 충분한 공간이 있는지 확인할 수 있습니다. XTF(Xbox 도구 프레임워크) 도구에 대한 자세한 내용은 명령줄 도구(NDA 항목)권한 부여 필요를 참조하세요.
다음 코드 샘플은 앱 패키지에 필요한 공간을 계산하는 방법을 보여줍니다.
#include <stdio.h>
#include <conio.h>
#include <Windows.h>
#include <xtfapi.h>
//Round up file sizes to the nearest 4K boundary to get a better estimate of the actual size of disk
#define ESTIMATED_FILE_SIZE_ON_DISK(fileSize) ((fileSize + ((4UI64 * 1024UI64) - 1)) & ~((4UI64 * 1024UI64) - 1))
//Size of the buffer (string) that we use to contain file/directory names - MAX_PATH + 1 for the terminating null
#define DIR_BUFFER_LENGTH (MAX_PATH + 1)
//Forward declaration of the function that figures out the game size on disk
UINT64 EstimateRequiredSpace(LPWSTR targetDir) ;
//Calculates whether there is enough disk space to deploy the game
//Returns an ERRORLEVEL:
// 0 - OK - Enough space
// 1 - ERROR - Not enough space
// 2 - ERROR - Other error
int wmain(int argc, wchar_t **argv)
{
HRESULT hr = S_OK;
UINT64 availableBytes = 0;
UINT64 requiredBytes = 0;
LPWSTR consoleAddress = nullptr;
LPWSTR targetDir = nullptr;
if (argc != 3)
{
wprintf(L"\nUsage: %s <consoleAddress> <directory name>\n", argv[0]);
return 2;
}
consoleAddress = argv[1];
targetDir = argv[2];
wprintf(L"\nTarget console is %s\n", consoleAddress);
wprintf(L"\nTarget directory is %s\n\n",targetDir);
hr = XtfGetAvailableSpaceForAppInstallation(consoleAddress, L"Internal", &availableBytes);
if (hr != S_OK)
{
wprintf(L"\n\n*** Error %d", hr);
return 2;
}
requiredBytes = EstimateRequiredSpace(targetDir);
if (hr != S_OK)
{
wprintf(L"\n\n*** Error calculating size");
return 2;
}
wprintf(L"*** Space available on console is %I64u \n", availableBytes);
wprintf(L"*** Space required is %I64u \n", requiredBytes);
if (requiredBytes > availableBytes)
{
wprintf(L"*** DO NOT DEPLOY \n");
return 1;
}
wprintf(L"*** OK TO DEPLOY \n");
return 0;
}
//Function that figures out the game size on disk
UINT64 EstimateRequiredSpace(LPWSTR targetDir)
{
WIN32_FIND_DATA ffd;
LARGE_INTEGER filesize;
TCHAR szDir[DIR_BUFFER_LENGTH];
size_t targetDirLength = 0;
HANDLE hFind = INVALID_HANDLE_VALUE;
DWORD dwError = 0;
UINT64 requiredBytes = 0;
// Check that the input path plus 3 is not longer than the size of szDir.
// Three characters are for the "\*" plus NULL appended below.
targetDirLength = wcsnlen_s(targetDir, DIR_BUFFER_LENGTH);
if (targetDirLength + 3 > DIR_BUFFER_LENGTH)
{
wprintf(L"\nDirectory path is too long.\n");
return -1;
}
// Create the search string for FindFile functions.
wcscpy_s(szDir, DIR_BUFFER_LENGTH, targetDir);
wcscat_s(szDir, DIR_BUFFER_LENGTH, L"\\*");
// Find the first file in the directory.
hFind = FindFirstFile(szDir, &ffd);
if (INVALID_HANDLE_VALUE == hFind)
{
dwError = GetLastError();
wprintf(L"\nError: FindFirstFile failed %d.\n", dwError);
return -1;
}
// Iterate over all the files in the game collecting file size information
do
{
//If is a directory drill into it
if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
if (wcscmp(ffd.cFileName, L".") != 0 && wcscmp(ffd.cFileName, L"..") != 0) //There is probably a better way to do this...
{
size_t newDirLength = wcsnlen_s(ffd.cFileName, DIR_BUFFER_LENGTH);
if (targetDirLength + 1 + newDirLength + 1 > DIR_BUFFER_LENGTH)
{
wprintf(L"\nDirectory path is too long.\n");
return -1;
}
wcscpy_s(szDir, DIR_BUFFER_LENGTH, targetDir);
wcscat_s(szDir, DIR_BUFFER_LENGTH, L"\\");
wcscat_s(szDir, DIR_BUFFER_LENGTH, ffd.cFileName);
UINT64 result = EstimateRequiredSpace(szDir);
if (result == -1)
{
return -1;
}
requiredBytes += result;
}
}
else
{
filesize.LowPart = ffd.nFileSizeLow;
filesize.HighPart = ffd.nFileSizeHigh;
//Round up file sizes to the nearest 4K boundary to get a better estimate of the actual size of disk
requiredBytes += ESTIMATED_FILE_SIZE_ON_DISK(filesize.QuadPart);
}
}
while (FindNextFile(hFind, &ffd) != 0);
dwError = GetLastError();
if (dwError != ERROR_NO_MORE_FILES)
{
wprintf(L"\nError: FindNextFile failed %d.\n", dwError);
return -1;
}
FindClose(hFind);
return requiredBytes;
}
요구 사항
헤더: xtfapi.h
라이브러리: XtfApi.lib
지원되는 플랫폼: Windows(Xbox 콘솔 도구용)