Click here to Skip to main content
Click here to Skip to main content

MS-Cabinet File WrapperClasses

, 31 May 2003
Rate this:
Please Sign up or sign in to vote.
Two classes using cabinet.dll to create or extract from MS-Cabinet Files
<!-- Add the rest of your HTML here -->

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.

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

About the Author

Stefan Voitel

Germany Germany
No Biography provided

Comments and Discussions

 
Question2Tb Virtual Disk Pinmembernhchmg27-Jun-11 20:26 
GeneralA better solution PinmemberElmue26-Jul-06 3:47 
GeneralRe: A better solution Pinmember.dan.g.25-Jun-08 14:10 
GeneralRe: A better solution PinmemberElmue30-Jun-08 6:55 
GeneralRe: A better solution Pinmembermirik12320-Nov-11 5:28 
GeneralRe: A better solution PinmemberElmue22-Nov-11 3:38 
Question.net(c# or vb.net) version? Pinmemberchenhuisheng23-Mar-04 20:26 
AnswerRe: .net(c# or vb.net) version? PinmemberStefan Voitel24-Mar-04 0:54 
GeneralRe: .net(c# or vb.net) version? PinmemberJ.B16-Aug-04 14:12 
GeneralRe: .net(c# or vb.net) version? Pinsusssteven Deng19-Jan-05 9:55 
GeneralRe: .net(c# or vb.net) version? Pinmembersd_alberta20-Jan-05 8:03 
GeneralRe: .net(c# or vb.net) version? PinmemberElmue31-Aug-06 0:41 
AnswerRe: .net(c# or vb.net) version? PinmemberElmue31-Aug-06 0:41 
GeneralAccessing Folders in MFC Pinmembervgandhi13-Jun-03 8:33 
QuestionHow to digitally sign cab from code ??? PinmemberAntonS1-Jun-03 21:41 
AnswerRe: How to digitally sign cab from code ??? PinsussStefan Voitel3-Jun-03 8:32 
QuestionHow to extract from .MSI? Pinmemberharinath1-Jun-03 18:48 
AnswerRe: How to extract from .MSI? PinsussStefan Voitel3-Jun-03 8:39 
GeneralRe: How to extract from .MSI? PinsussAnonymous8-Feb-04 6:50 
AnswerRe: How to extract from .MSI? PinmemberMatteo Mike Peluso27-Sep-05 8:34 
AnswerRe: How to extract from .MSI? PinmemberEllery Pierce7-Aug-06 22:43 

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

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

| Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 1 Jun 2003
Article Copyright 2003 by Stefan Voitel
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid