Contents - Index


Creating a Self Extracting Zip File 

If you create a Self Extracting Executable (SFX), The resulting zip file will have the same name as the original zip archive except that it will have an extention of .EXE. This will allow people to unzip files in your zip file without needing to have any kind of unzip utility themselves.  You can do this in two ways, with VCLZip  

Use the MakeSFX Method to create a SFX if you have an already existing zip file that you wish to turn into an SFX. 

 

Use the MakeNewSFX method to create a SFX  and zip the files that it will contain, all in one step.  With this method, you also have the capability to add configuration information to the zip file if your stub is capable of this.  VCLZip is distributed with a 32bit sfx stub that does have this capability by using the TSFXConfig Component to create the configuration block.

  

Here is an example of using the MakeSFX method:  

 

If you have a zip file called data.zip that you want to turn into a self extracting zip file and your SFX stub is called sfx32.exe.  You might use the following code:  

 

begin 

With VCLZip1 do 

begin 

ZipName := 'c:\myfiles\data.zip'      /* the zip archive you want to turn into an SFX */; 

MakeSFX( 'c:\sfxstuff\32bit\sfx32.exe', True );  /* note that the second argument is meaningless at this time */ 

end; 

end; 

  

This will result in a file named data.exe in the same directory as data.zip.  The local, central,and end of central headers in data.exe will be modified to reflect their new offsets.  

 

Here is an example of using the MakeNewSFX method using TSFXConfig (defined in the unit} along with the 32bit SFX stub that is included with VCLZip.  This example assumes that the stub is called ZipSFX32.bin and is located in the same directory as the running program.:

  

USES   kpSFXCfg;  

VCLZip1.RootDir := 'd:\test\somedir\';  { Start recursive search from here } 

VCLZip1.FilesList.Add('*.pas'); { Zip all of the .pas files in the dir structure } 

VCLZip1.Recurse := True;  { Recurse subdirectories } 

VCLZip1.StorePaths := True;  { Save path information } 

sfxcfg := TSFXConfig.Create(nil);  {Create the TSFXConfig object or drop the component on your form } 

with sfxcfg do 

begin             { Set the options } 

UserCanDisableCmdLine := chkUserDisableCmd.Checked; 

UserCanChooseFiles := chkUserChooseFiles.Checked; 

UserCanChangeOverwrite := chkUserChangeMode.Checked; 

OverwriteMode := TsfxOverwriteMode(OverwriteGrp.ItemIndex); 

AutoExtract := chkAutoExtract.Checked; 

Caption := txtCaption.Text; 

DefaultPath := txtDefDest.Text; 

CmdLine := txtCmdLine.Text; 

InfoText := InfoTextFrm.InfoText.Text; 

InfoTitle := InfoTextFrm.InfoTitle.Text; 

sfxcfg.CreateHeader; 

end; 

{ Get the stub } 

SFXStub := ExtractFilePath(Application.ExeName) + 'ZipSFX32.bin'; 

{ Make the SFX file } 

if FileExists(SFXFile) then 

SysUtils.DeleteFile(SFXFile); 

VCLZip1.MakeNewSFX(SFXStub, SFXFile, sfxcfg.theHeader, sfxcfg.HeaderLen); 

end;