CascLib API Reference

CascGetFileInfo

Description


  bool WINAPI CascGetFileInfo(
      HANDLE hFile                    // Handle to an open file
      CASC_FILE_INFO_CLASS InfoClass  // Specifies which type of file info to get
      void * pvFileInfo,              // Pointer to buffer that receives the file info
      size_t cbFileInfo,              // Length of buffer pointed by pvFileInfo
      size_t * pcbLengthNeeded        // Pointer to a variable that receives the length of the file info
      );

Function CascGetFileInfo retrieves various information about an open file. The file must have been open open by a previous call to CascOpenFile.

Parameters

hFile [in]
Handle to an open CASC file.
InfoClass [in]
Specifies the type of information to be returned about the file, in the buffer that pvFileInfo points to.
CASC_FILE_INFO_CLASS value Type of information returned
CascFileContentKey 16-byte value of file content key. A content key is a MD5 hash of the plain (decoded) file data.
Note: Content key must not be present for all files in the storage. An example is Warcraft III storages, where most of the files are referenced by Encoded key.
CascFileEncodedKey 16-byte value of file encoded key. Am encoded key is MD5 hash of the encoded file headers.
Note: Encoded key must not have full 16 byte length. In such case, the data returned is padded by zeros.
CascFileFullInfo A CASC_FILE_FULL_INFO structure.
CascFileSpanInfo A CASC_FILE_SPAN_INFO structure.
pvFileInfo [out]
Pointer to a caller-allocated buffer into which the routine writes the requested information about the file object. The InfoClass parameter specifies the type of information that the caller requests.
cbFileInfo [in]
The size, in bytes, of the buffer pointed to by pvFileInfo.
pcbLengthNeeded [out, optional]
If non-NULL, this parameter points to a size_t variable that receives the number of bytes that is needed for storing the entire information. This information can be used to allocate buffer big enough to hold the given file information.

Return Value

On success, the function returns true.
On failure, the function returns false and GetLastError() returns the error code.

Example

This example demonstrates usage of GascGetFileInfo for retrieving a variable-sized information


PCASC_FILE_SPAN_INFO GetFileSpanInfo(HANDLE hFile)
{
    PCASC_FILE_SPAN_INFO pSpans = NULL;
    size_t cbLength = 0;

    // Retrieve the full file info
    CascGetFileInfo(hFile, CascFileSpanInfo, pSpans, cbLength, &cbLength);
    if(cbLength != 0)
    {
        if((pSpans = (PCASC_FILE_SPAN_INFO)(new BYTE[cbLength])) != NULL)
        {
            if(CascGetFileInfo(hFile, CascFileSpanInfo, pSpans, cbLength, NULL))
                return pSpans;
            
            CASC_FREE(pSpans);
            pSpans = NULL;
        }
    }

    return pSpans;
}