Makecab.exe

MakeCAB is a Lossless Data Compression tool that can be used for a wide variety of purposes. Although it was originally designed for use by setup programs, it can also be used in almost any situation where lossless data compression is required.MAKECAB.EXE is designed to produce the final distribution files and cabinets for an entire product in a single run. The most common way to use MAKECAB.EXE is to supply adirectives file that controls how files are compressed and stored into one or more cabinets.

You can run this command from the Visual Studio Command Prompt.

MAKECAB.EXE Syntax

There two primary forms of MAKECAB.EXE usage. The first is used for compressing a single file, while the second is used for compressing multiple files.
MAKECAB  [/Vn] [/D variable=value ...] [/L directory] source [destination]
MAKECAB  [/Vn] [/D variable=value ] /F directives_file [...]
The parameters are described below.
Parameter Description
source A file to be compressed.
destination The name of the file to receive the compressed version of the source file. If not supplied, a default destination name is constructed from the source file name according to the rules defined by the CompressedFileExtensionChar variable. You can use /D CompressedFileExtensionChar=c on the command line to change the appended character.
/Dvariable=value Set variable to be equal to value. Equivalent to using the .Set command in the directives file. For example, a single directive file could be used to produce layouts for different disk sizes by running MakeCAB once with different values of MaxDiskSize defined: /D MaxDiskSize=1.44M. Both standard MakeCAB variables and custom variables may be defined in this way. If .Option Explicit is specified in a directive file, then variable must be defined with a .Definecommand in a directive file.
/L directory Specifies an output directory where the compressed file will be placed (most useful when destination is not supplied).
/Fdirectives_file A file containing commands for MAKECAB.EXE to execute. If more than one directive file is specified (/F file1 /F file2 …), they are processed in the order (left to right) specified on the command line. Variable settings, open cabinets, open disks, etc. are all carried forward from one directive file to the next (just as if all of the files had been concatenated together and presented as a single file to MakeCAB). For example, this is intended to simplify the work for a product shipped in multiple languages. There would be a short, language-specific directives file, and then a single, large master directives file that covers the bulk of the product.
/Vn Set debugging verbosity level (0=none,…,3=full)

If there are more than file that one file that you’ll have to package them all together in a single .cab file, then you have to prepare a .ddf file (Diamond Directive File). This file will store a list of all the files to be included in a single package. 

MAKECAB.EXE Directive File Syntax

Following is a sample of a .ddf file format.

OPTION EXPLICIT ; Generate errors on variable typos

.Set CabinetNameTemplate=fileexport.cab ; The name of the file
.set DiskDirectoryTemplate=CDROM ; All cabinets go in a single directory
.Set CompressionType=MSZIP ;
.Set Cabinet=on ;
.Set Compress=on ;
.Set DiskDirectory1=directorypath\Directory.CAB 
.Set MaxDiskSize=51200               ; multiple of 512

;*** Files to zip ;
;
directorypath\manifest.xml
directorypath\ExportSettings.xml
directorypath\Requirements.xml
directorypath\RootObjectMap.xml
directorypath\SystemData.xml
directorypath\UserGroup.xml
directorypath\ViewFormsList.xml
directorypath\00000000.dat
directorypath\00000001.dat
directorypath\00000002.dat
directorypath\00000003.dat
;***

A special mention has to be made about the MaxDiskSize property. For some very strange reason you’ld not find this property in most of the online samples. The importance of this property is that it will include only those files in your .cab whose size is less than that specified here. For example, I had some 17 files where most of the files were larger than 25MB. When I executed the Makecab.exe command, I found that only smaller files were included in the .cab files. Larger files were silently ignored with no error message! This was very bad. Anyways, after doing some google, I came across the following post,

http://www.pseale.com/blog/strongopinionsaynotomakecabexe.aspx

which stressed on the importance of this property. Once included in my .ddf file with a value of about 5120000, I can see all my files in the resultant .cab file.

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s