The method for creating a self-extracting zip file is very similar to that of creating a regular zip file, except that you must specify the self-extractor binary to use. You'll also want to (although it is optional) give your zip file a ".exe" extension instead of the usual ".zip".
Here we'll follow the same steps as the zipping files topic, but modified for creating a self-extracting zip file. To create a new self-extracting zip file, perform the following 5 steps. Put the Xceed Zip control on a form, then:
Specify the zip file to create. Make it a ".EXE". To do this, set the ZipFilename property.
Specify the files you want to zip up. To do this, set the FilesToProcess property.
Specify the self-extractor binary to use. To do this, set the SfxBinaryModule property.
Tell Xceed Zip to start zipping. To do this, call the Zip method.
Make sure it worked successfully. To do this, check the Zip method's return value.
Here is sample VB code for these 5 steps:
Visual Basic | Copy Code |
---|---|
|
Here is sample Delphi code for these 5 steps:
Delphi | Copy Code |
---|---|
|
You will probably want to customize the self-extracting zip files you create. For example, you may want to change its title and introduction message, or have it suggest a default unzipping folder. There is a group of properties that start with "Sfx" designed to let you do just that. See the About the Self-Extractor Module properties topic to find out what you can customize.
Other than customizing the appearance and behavior of the self-extracting zip file, you should also ask yourself the following questions:
The self-extracting zip file always recreates files with their stored paths. Do you want to store paths in the zip file? See the controlling how paths are stored topic.
Do you want to password-protect the files in your self-extracting zip files? See the EncryptionPassword property. Self-extracting zip files that contain password protected files will display a dialog box asking the user to enter a decryption password, otherwise the encrypted files will be skipped. There's also the SfxDefaultPassword property that lets the self-extracting zip file decrypt some or all of its contents without asking the user for a password.
Do you want to zip up files in subfolders, too? See the ProcessSubfolders property.
Do you want to display the status of the zipping operation? See the GlobalStatus event.
Is there a chance the self-extracting zip file may span multiple disks? If so, write a handler for the InsertDisk event.
Other questions you may want to consider are:
Do you want to zip only certain types of files? See the filtering properties.
Do you want to edit a file's info before zipping? See the ZipPreprocessingFile event.
Is there a chance you're zipping files already open? See the ZipOpenedFiles property.
Are you looking for the best compression ratio? See the CompressionLevel property.
Do you want to store UNICODE filenames in the zip file? See the ExtraHeaders property.
If there's anything else you need to do that's not mentioned here, consult the Properties topic, or search the index – chances are, Xceed Zip does what you need. If not, ask Xceed Software whether it's possible or not.