| ActivePatch Developer's Guide - Listing Package Files | ||
|
Once a package has been created, an application may need to obtain information about each of the files in that package. To do this, the functions GetFirstPackageFile and GetNextPackageFile may be used. Here is an example that lists each of the files in a package and writes their names to the console: // Write each of the files in the package to standard output
HPACKAGE hPackage;
PACKAGE_FILE_INFORMATION fileInfo;
LPCTSTR lpszPackageFile = _T("update.pkg"); // package file
LPCTSTR lpszPassword = _T("secret"); // package password
BOOL bResult;
// Open the package for read-only access
hPackage = OpenPackage(lpszPackageFile, // package file
lpszPassword, // package password
PACKAGE_OPEN_READONLY, // read-only access
NULL, 0); // callback function
if (hPackage == INVALID_PACKAGE_HANDLE)
{
// The package could not be opened; use the GetLastError
// function to determine the reason
return;
}
// Initialize the fileInfo structure with the size of the
// structure, and call the GetFirstPackageFile function
fileInfo.cbStructure = sizeof(PACKAGE_FILE_INFORMATION);
bResult = GetFirstPackageFile(hPackage, &fileInfo);
while (bResult)
{
// Write the file name to standard output
printf("%s\n", fileInfo.szFileName);
bResult = GetNextPackageFile(hPackage, &fileInfo);
}
ClosePackage(hPackage);
The first step in this example is to open the package, since we need a valid package handle in order to list the files. The package is opened in read-only mode using the OpenPackage function, and the return value is checked to make sure that it was successful. The next step is to initialize the Next, the GetFirstPackageFile function is called. The first parameter is the handle to the package that was opened and the second parameter is a pointer to the structure that will contain information about the file. If the function is successful, it returns a non-zero value, which results in the file name being written to standard output, and then the GetNextPackageFile function is called repeatedly, until the last file in the package is reached. At this point, the function will return a value of zero, and the loop exits. The package is then closed, releasing the handle. |
||