Click here to Skip to main content
15,891,033 members
Articles / Desktop Programming / MFC
Article

MS-Cabinet File WrapperClasses

Rate me:
Please Sign up or sign in to vote.
3.69/5 (7 votes)
31 May 20033 min read 99.9K   2.3K   23   20
Two classes using cabinet.dll to create or extract from MS-Cabinet Files

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 :

C++
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.

C++
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.

C++
BOOL         Store     (void);

Store the Cabinet to disk.

C++
void         Destroy   (void);

Free resources allocated by Create().

The simplest way to use :

C++
#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 :

C++
void SetCompression     (bool b)

Turn compression on/off.

C++
void SetStoredPath      (tStoredPath sp)

Set how the path for files should be stored in Cabinet.

Control TCompress more :

C++
virtual void CBOpenInfo (const PCHAR File,FILETIME *Time,USHORT &Attrib)

Called to allow set Time and Attributes stored in cabinet for File.

C++
virtual void CBTempName (PCHAR szTemp,int nTemp)

Called when the path for temporary files is needed.

C++
virtual void CBCabName  (tCabName NextCabName,INT Count)

Called when the name for the next Cabinetfile in a set is needed.

C++
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 :

C++
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 :

C++
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.

C++
BOOL         Copy       (void)

Start extraction.

C++
void         Destroy    (void)

Free resources allocated by Create().

The simplest way to use :

C++
#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 :

C++
void  SetExpandStoredPath(tStoredPath s)

Set how the path stored in Cabinet should be restored.

C++
void  SetSubsequent      (bool e)

Set / unset Continuation on subsequent Cabinets in a set.

C++
bool  GetCurrentFile     (PCHAR File,UINT nFile)

Copy the name from the current extracted File to File.

C++
bool  HasIncomplete      (PCHAR File,UINT nFile)

When Copy() fails check for incomplete files continued in a not available Cabinet

C++
bool  GetFirstCab        (PCHAR AnyCabinet,tPath FirstCabinet)

Get the first Cabinet from a set of Cabinet files beginning from any Cabinet in this set.

C++
bool  CreatePath         (tConstPath Path)

Create the full path pointed by Path.

C++
bool  FileAvaliable      (tConstPath Path)

Try to open the file pointed by Path for reading.

C++
bool  DirectoryExists    (tConstPath Path)

Look for the directory pointed by Path.

Control TExpand more :

C++
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.

C++
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.

C++
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 :

C++
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.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Germany Germany
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralA better solution Pin
Elmue26-Jul-06 3:47
Elmue26-Jul-06 3:47 
GeneralRe: A better solution Pin
.dan.g.25-Jun-08 14:10
professional.dan.g.25-Jun-08 14:10 
GeneralRe: A better solution Pin
Elmue30-Jun-08 6:55
Elmue30-Jun-08 6:55 
GeneralRe: A better solution Pin
mirik12320-Nov-11 5:28
mirik12320-Nov-11 5:28 
GeneralRe: A better solution Pin
Elmue22-Nov-11 3:38
Elmue22-Nov-11 3:38 
Question.net(c# or vb.net) version? Pin
Huisheng Chen23-Mar-04 20:26
Huisheng Chen23-Mar-04 20:26 
Is there any .net(c# or vb.net) version of this wrapper???

Please let me know, thanks a lot: unruledboy@hotmail.com
AnswerRe: .net(c# or vb.net) version? Pin
Stefan Voitel24-Mar-04 0:54
Stefan Voitel24-Mar-04 0:54 
GeneralRe: .net(c# or vb.net) version? Pin
J.B16-Aug-04 14:12
J.B16-Aug-04 14:12 
GeneralRe: .net(c# or vb.net) version? Pin
steven Deng19-Jan-05 9:55
susssteven Deng19-Jan-05 9:55 
GeneralRe: .net(c# or vb.net) version? Pin
sd_alberta20-Jan-05 8:03
sd_alberta20-Jan-05 8:03 
GeneralRe: .net(c# or vb.net) version? Pin
Elmue31-Aug-06 0:41
Elmue31-Aug-06 0:41 
AnswerRe: .net(c# or vb.net) version? Pin
Elmue31-Aug-06 0:41
Elmue31-Aug-06 0:41 
GeneralAccessing Folders in MFC Pin
vgandhi13-Jun-03 8:33
vgandhi13-Jun-03 8:33 
QuestionHow to digitally sign cab from code ??? Pin
AntonS1-Jun-03 21:41
AntonS1-Jun-03 21:41 
AnswerRe: How to digitally sign cab from code ??? Pin
Stefan Voitel3-Jun-03 8:32
Stefan Voitel3-Jun-03 8:32 
QuestionHow to extract from .MSI? Pin
harinath1-Jun-03 18:48
professionalharinath1-Jun-03 18:48 
AnswerRe: How to extract from .MSI? Pin
Stefan Voitel3-Jun-03 8:39
Stefan Voitel3-Jun-03 8:39 
GeneralRe: How to extract from .MSI? Pin
Anonymous8-Feb-04 6:50
Anonymous8-Feb-04 6:50 
AnswerRe: How to extract from .MSI? Pin
Matteo Mike Peluso27-Sep-05 8:34
Matteo Mike Peluso27-Sep-05 8:34 
AnswerRe: How to extract from .MSI? Pin
Ellery Pierce7-Aug-06 22:43
professionalEllery Pierce7-Aug-06 22:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.