Introduction
Apologies in advance about my English and the brief descriptions, as my native language is German.
Two classes to wrap compression / extraction with cabinet.dll
. It will not allow add files to, remove files from or modify Cabinets.
Using the code
Class TCompress
The main Functions :
tCreateError Create (PCHAR CabFile,PCHAR Path,ULONG Size = CAB_MAXDISK)
Initialize a TCompressObject.CabFile
is the name for the (first) Cabinet. If the file(s) exists it will be overwritten Path
is the directory to store the Cabinet. Size
is the maximum size for a single Cabinet file.
BOOL Add (const PCHAR File,BOOL bExec = false)
Add File
to the Cabinet. Set bExec
true when the file should be executed after the extraction. A application must detect this flag and execute the file.
BOOL Store (void);
Store the Cabinet to disk.
void Destroy (void);
Free resources allocated by Create()
.
The simplest way to use :
#include "TCompress.hpp"
class cMyCompress : TCompress {
friend void main (void);
};
void main (void) {
cMyCompress *cmp = new cMyCompress();
if (cmp->Create("cabinet.cab","c:\\compressed") == errSuccess) {
cmp->Add ("AnyFileThatShouldExists.001");
cmp->Add ("AnyFileThatShouldExists.002");
cmp->Add ("AnyFileThatShouldExists.003");
cmp->Store ();
cmp->Destroy ();
}
delete cmp;
}
Control TCompress :
void SetCompression (bool b)
Turn compression on/off.
void SetStoredPath (tStoredPath sp)
Set how the path for files should be stored in Cabinet.
Control TCompress more :
virtual void CBOpenInfo (const PCHAR File,FILETIME *Time,USHORT &Attrib)
Called to allow set Time and Attributes stored in cabinet for File.
virtual void CBTempName (PCHAR szTemp,int nTemp)
Called when the path for temporary files is needed.
virtual void CBCabName (tCabName NextCabName,INT Count)
Called when the name for the next Cabinetfile in a set is needed.
virtual void CBDiskName (tCabDisk NextDiskName,INT Count)
Called when the name for the next disk (stored in Cabinet to prompt the user) is needed.
Feedback on various points at work :
virtual void CBReplaced (const PCHAR File,BOOL IsContinued)
virtual void CBFile (const tcFileStatus &Status)
virtual void CBFolder (tcFolderStatus s,USELESS ul1,USELESS ul2)
virtual void CBCabinet (ULONG CabinetSizeWritten)
Class TExpand
The main functions :
tCreateError Create (PCHAR CabFile,PCHAR BasePath = NULL)
Initialize a TExpandObject. CabFile
is the name of the Cabinet. BasePath
is the directory to store the extracted files. Default is the SystemTempDirectory
.
BOOL Copy (void)
Start extraction.
void Destroy (void)
Free resources allocated by Create()
.
The simplest way to use :
#include "TExpand.hpp"
class cMyExpand : TExpand {
friend void main (void);
};
void main (void) {
cMyExpand *exp = new cMyExpand();
if (exp->Create ("c:\\compressed\\cabinet.cab") == errSuccess) {
exp->Copy ();
exp->Destroy ();
}
delete exp;
}
Control TExpand :
void SetExpandStoredPath(tStoredPath s)
Set how the path stored in Cabinet should be restored.
void SetSubsequent (bool e)
Set / unset Continuation on subsequent Cabinets in a set.
bool GetCurrentFile (PCHAR File,UINT nFile)
Copy the name from the current extracted File to File.
bool HasIncomplete (PCHAR File,UINT nFile)
When Copy()
fails check for incomplete files continued in a not available Cabinet
bool GetFirstCab (PCHAR AnyCabinet,tPath FirstCabinet)
Get the first Cabinet from a set of Cabinet files beginning from any Cabinet in this set.
bool CreatePath (tConstPath Path)
Create the full path pointed by Path
.
bool FileAvaliable (tConstPath Path)
Try to open the file pointed by Path
for reading.
bool DirectoryExists (tConstPath Path)
Look for the directory pointed by Path
.
Control TExpand more :
virtual void CBCloseInfo (const PCHAR FileName_OnDisk,
USHORT FileTime_ToSet,
USHORT FileDate_ToSet,
USHORT FileAttribute_ToSet)
Called to set date, time and attributes for the file extracted to disk.
virtual bool CBCopyFile ( tPath FileName,
LONG UncompressedSize,
SYSTEMTIME SysTime_InCab,
USHORT Attribs_InCab,
bool &Error)
Called to ask for extract the File named FileName
. You should look for available space on disk and you can modify the FileName
here. Return false to skip the File. If Error not eeNone
a previous extraction has failed. In this case set Error to eeNone
and return false to continue extraction with the next file, otherwise Copy()
terminates immediately.
virtual void CBNextCabinet(const PCHAR CabFile_Needed,
const PCHAR Disk_Needed,
tCabPath CabinetPath,
teError &Error)
A continued file should be extracted and the Cabinet is not available. Prompt user for the disk named Disk_Needed
or set CabinetPath
to point on CabFile_Needed
. If it called with Error not eeNone
a previous call has failed. Set Error to eeNone
and try again or leave Error in this case Copy()
terminates immediately.
Feedback on various points at work :
virtual void CBProgress (void)
Points of Interest
Additional information about the FDI/FCI interface :
Download cabsdk.exe for documents that describe the internal structures of CabinetFiles, samples to use from C and a description of cabinet.dll
.
History
- June 1st, 2003: Initial release.