Cabinet.cpp in MakeCab.rar
Sponsored links
// Cabinet.cpp: implementation of the CCabinet class.
//
//////////////////////////////////////////////////////////////////////
#include "Cabinet.h"
//下面是压缩时用到的回调函数。
/*
* 分配内存
*/
FNFCIALLOC(mem_alloc)
{
return malloc(cb);
}
/*
* 释放内存
*/
FNFCIFREE(mem_free)
{
free(memory);
}
/*
* 打开文件
*/
FNFCIOPEN(fci_open)
{
return _open(pszFile, oflag, pmode);
}
/*
* 读取文件
*/
FNFCIREAD(fci_read)
{
return (unsigned int) _read(hf, memory, cb);
}
/*
* 写文件
*/
FNFCIWRITE(fci_write)
{
return (unsigned int) _write(hf, memory, cb);
}
/*
* 关闭文件
*/
FNFCICLOSE(fci_close)
{
return _close(hf);
}
FNFCISEEK(fci_seek)
{
return _lseek(hf, dist, seektype);
}
FNFCIDELETE(fci_delete)
{
return remove(pszFile);
}
FNFCIFILEPLACED(file_placed)
{
return 0;
}
FNFCIGETTEMPFILE(get_temp_file)
{
char *psz;
psz = _tempnam("","xx"); // Get a name
if ((psz != NULL) && (strlen(psz) < (unsigned)cbTempName)) {
strcpy(pszTempName,psz); // Copy to caller's buffer
free(psz); // Free temporary name buffer
return TRUE; // Success
}
//** Failed
if (psz) {
free(psz);
}
return FALSE;
}
/*
* 用于压缩过程中的提示信息显示,这里忽略。
*/
FNFCISTATUS(progress)
{
return 0;
}
/*
* 这里忽略。
*/
FNFCIGETNEXTCABINET(get_next_cabinet)
{
return TRUE;
}
FNFCIGETOPENINFO(get_open_info)
{
BY_HANDLE_FILE_INFORMATION finfo;
FILETIME filetime;
HANDLE handle;
DWORD attrs;
int hf;
/*
* Need a Win32 type handle to get file date/time
* using the Win32 APIs, even though the handle we
* will be returning is of the type compatible with
* _open
*/
handle = CreateFile(
pszName,
GENERIC_READ
...
...
... to be continued.
This is a preview. To get the complete source file,
please click here to download the whole source code package.