|
Overview
|
This project started when I was trying to build up the indexes for the vbAccelerator site.
I had a program to search through all the HTML files which make up the site, and
this could pick out the ZIP files linked to by the pages. But how to determine which
projects these ZIP files contained? You need a way to read ZIP files. As usual with VB
there are no library routines or even controls available for ZIP files, so you need
another way.
Luckily there is one, and its free! If you have a look at the Acknowledgements in the
WinZip helpfile, you will find that the compression code for ZIP files is actually implemented
using free code from the Info-ZIP group:
|
"WinZip incorporates compression code by the Info-ZIP group, which is used with their permission. Special thanks to the entire Info-Zip group, in particular to Jean-loup Gailly, Greg Roelofs, and Mark Adler. The original Info-Zip sources are freely available from CompuServe in the pcprog forum and by anonymous ftp from the Internet site ftp.uu.net:/pub/archiving/zip. We will also, upon request, mail you the Info-Zip sources if you send a self-addressed stamped envelope to the address in the WinZip "About" dialog box."
|
|
Info-ZIP's purpose is to "provide free, portable, high-quality versions of the Zip and UnZip compressor-archiver utilities that are compatible with the DOS-based PKZIP by PKWARE, Inc." -
and they do an excellent job at it. Their code runs on almost every OS ever devised (Tandem NSK?) and is
also part of many products such as WinZip, PGP, the third party ActiveX control DynaZip and so on.
The licensing arrangment for this DLL is classic freeware too: you cannot sell the product,
but you are free to use it as you wish provided that (1) the customer does not believe Unzip is
being sold and (2) the customer receives all normal documentation.
|
Using the Info-ZIP Unzip DLL from VB
|
The task of using Info-ZIP in VB is greatly assisted by the work of VB coders
Raymond L. King, Christian Spieler, Mike Le Voi and Mike White who contributed
to the vbunzip.bas module in the download. Whilst this module demonstrates
the use of the functions and provides useful declares for using them, the
code is not at all easy to reuse because the unzipping is embedded within the
logic to present the information in the sample.
This sample fixes that problem by providing a class module, cUnzip.cls,
which exposes all of the options and parameters as named class members as well wrapping
up directory listing of zips with simple calls.
|
Make Sure You Keep Running
|
One problem with using the Info-ZIP compiled DLL as-is is that the precompiled binaries
supplied by the Info-ZIP group are for courtesy only, and the Win32 rules for DLL have
not been followed, i.e. if you create a DLL which is not
compatible with the previous version then you should change the name so you don't stop
existing applications from working.
For example, the function for unzipping files was actually
renamed from windll_unzip to
Wiz_SingleEntryUnzip between versions! No doubt Info-ZIP have their reasons for
this but if you had production code out there that used the older version then you would
be stuffed - there would be no choice but to ship an entirely new version of your code.
You can prevent this happening to you by simply renaming the DLLs downloaded from
the Info-Zip site. In this case, I've renamed unzip32.dll to vbuzip10.dll.
When/if another version appears and it requires code to be changed, I will call this
new version vbuzip11.dll, and so on.
|
Reusing the VB code
|
The demonstration application for download implements a fully featured unzip
application. However, this code is based around a reusable class and a supporting
module:
To use this in your application, declare a WithEvents instance of the cUnzip class:
Private WithEvents m_cUnzip As cUnzip
The simplest operation is to open and unzip a zip without password encryption.
This is all you need to do:
' Set the zip file:
m_cUnzip.ZipFile = sFIle
' Set the base folder to unzip to:
m_cUnzip.UnzipFolder = sFolder
' Unzip the file!
m_cUnzip.Unzip
If you want to get a directory listing of files within the zip, use the Directory
method. When this returns, you can use the FileCount property to get the number
of files in the zip, and the FileCompressionMethod, FileCompressionRatio,
FileCRC, FileDate, FileDirectory, FileEncrypted, FilePackedSize,
and FileSize methods to display information about the files.
To restrict which files are extracted, set the FileSelected property to False
for the files you don't want to extract.
As Directory listings and Unzip operations are performed, the DLL will raise the
Progress event, which you can use to display status messages about the
directory operation, and Cancel events, which allow you to stop the directory.
The PasswordRequest event is raised when you attempt to extract a file from an
encrypted ZIP. Here you can supply the password and optionally cancel the extract operation.
If you set the PromptToOverwrite option, you will also get OverwritePrompt
events to respond to.
The remainder of the properties of the class allow you to set unzipping options, such as
UseFolderNames.
|
Back to top
Back to Library Source Code
Back to Source Code
|
|
  |