#include <lzexpand.h> |
int GetExpandedName(lpszSource, lpszBuffer) | |||||
LPCSTR lpszSource; | /* specifies name of compressed file | */ | |||
LPSTR lpszBuffer; | /* points to buffer receiving original filename | */ |
The GetExpandedName function retrieves the original name of a compressed file if the file was compressed with the COMPRESS.EXE utility and the /r option was specified.
lpszSource
Points to a string that specifies the name of a compressed file.
lpszBuffer
Points to a buffer that receives the name of the compressed file.
The return value is TRUE if the function is successful. Otherwise, it is an error value that is less than zero, and it may be LZERROR_BADINHANDLE, which means that the handle identifying the source file was not valid.
The following example uses the GetExpandedName function to retrieve the original filename of a compressed file:
char szSrc[] = {"readme.cmp"};
char szFileName[128];
OFSTRUCT ofStrSrc;
OFSTRUCT ofStrDest;
HFILE hfSrcFile, hfDstFile, hfCompFile;
int cbRead;
BYTE abBuf[512];
/* Open the compressed source file. */
hfSrcFile = OpenFile(szSrc, &ofStrSrc, OF_READ);
/*
* Initialize internal data structures for the decompression
* operation.
*/
hfCompFile = LZInit(hfSrcFile);
/* Retrieve the original name for the compressed file. */
GetExpandedName(szSrc, szFileName);
/* Create the destination file using the original name. */
hfDstFile = LZOpenFile(szFileName, &ofStrDest, OF_CREATE);
/* Copy the compressed source file to the destination file. */
do {
if ((cbRead = LZRead(hfCompFile, abBuf, sizeof(abBuf))) > 0)
_lwrite(hfDstFile, abBuf, cbRead);
else {
.
. /* handle error condition */
.
}
} while (cbRead == sizeof(abBuf));
/* Close the files. */
LZClose(hfSrcFile);
LZClose(hfDstFile);
This function retrieves the original filename from the header of the compressed file. If the source file is not compressed, the filename to which lpszSource points is copied to the buffer to which lpszBuffer points.
If the /r option was not set when the file was compressed, the string in the buffer to which lpszBuffer points is invalid.