The Code Project View our sponsorsClick here for Whole Tomato Software - Home of Visual AssistAdvertise on the CodeProject
Home >> ATL >> Controls

SAWZip - zip file manipulation control
By Franky Braem

An ATL based control for reading and writing zip files. 
 VC 4-6, Win95-98, NT4, W2K, ATL
 Posted 3 Jan 2001
 Updated 23 May 2001
Articles by this author
Send to a friend
Printer friendly version
Lounge New Articles Sign in Forums Contribute
Broken links? Email us!
15 users have rated this article. result:
4.67 out of 5.

Introduction

While I was developing my Java Class Browser (JCB) I needed a control or sourcecode (C++) to read jar-files. I searched the web and I didn't find any good freeware to resolve this problem. What I found was the zlib-compression library of Jean-loup Gailly and Mark Adler. It was not easy to figure it out how it worked. After a while I found the library written by Tadeusz Dracz. He uses the zlib-compression in a MFC library. It gave me a good idea on how to use the zlib-compression library. The problem with his library was that it was written with MFC, and I want to avoid using MFC because I JCB is a WTL-program. That's why I started to develop an ATL-control based on the code I found in the sourcecode of Tadeusz Dracz.

You can use this control with Visual C++ and Visual Basic 6.0. The control has been tested on Windows 98 and Windows NT. The UNICODE version of the application is not yet tested on a Windows NT Platform.

Archive Object

Properties

Property Type R/W Description
Name String R The name of the zipfile.
Files Files Object R A collection of file-objects.
Comment String R/W The comment for the zipfile.
ReadOnly Boolean R True when the zip you opened is read-only. Test on this flag before you want to compress some files.

Methods

Name Returns Parameters Description
Close / / Closes the zipfile.
Create / ByVal aName as String The name of the zipfile to create
Open / ByVal aName as String The name of the zipfile to open

Files Object

Properties

Property Type R/W Description
Count long R Number of files in the archive.

Methods

Name Returns Parameters Description
Add / ByVal newVal as File Adds a file to the archive. When there's already a file compressed with the same name it will be override this file.
AddFileByName / ByVal aName as String,
ByVal level as Integer,
ByVal fullPath as Boolean,
ByVal refresh as Boolean
This method can add files with wildcards. For level and fullPath see File Object for more information. When refresh is set to true, the file with the same name in the archive is overwritten. When it is set to false, the file will be skipped.

The following example does the following: Adding all C++ sources in the current-directory to the archive. Overwrite the current files in the archive.
zip.Files.AddFileByName "*.cpp", 1, true, true
Item File ByVal index as Long Returns the file on position index.
Remove / ByVal index as Long Removes the file with position index from the archive.

File Object

Properties

Property Type R/W Description
Name String R/W The name of the file. When added with fullPath set to false, the path will not be stored in the archive.
Directory Boolean R Returns true when the file is a directory.
CompressedSize Long R The size of the file when compressed.
UncompressedSize Long R The size of the file when not compressed.
Level Integer R/W The level used to perform compression. A value in the range of 0 - 9. 0 is no compression at all. 1 gives best speed, 9 gives best compression. This can only be set when the file is not yet stored in the archive.
Crc32 Long R Returns the crc checkum value.
Comment String R/W Returns or sets the comment. The comment can only be set when the file is not yet in stored in the archive.
FullPath Boolean R/W When stored to the archive and FullPath is false the path-information will be discarded. When the file is extracted and the FullPath is false the file will be extracted without the path-information.
Index Long R The index of this file object in the Files collection. This will be -1 when the file is not yet stored in the archive.

Methods

Name Returns Parameters Description
Extract / ByVal aPath as String Extract the file into the specified path. When FullPath is set to false, the file will be stored without the path-information.

Remarks

This control uses the dll-version of the zlib-compression library. When you install this control the zlib.dll must be reachable. This control makes heavy use of private interfaces to communicate between the different objects. You can read more about this on my page of SAWEditListCtrl on how to accomplish this.

Resources

Here is a list of resources I used to develop this control:

The MFC Library of Tadeusz Dracz.
The zlib-compression home page.

Updates

27-Dec-2000    Version 1.0 Released.

8-Mar-2001    Version 1.1

  1. Add properties to the fileobject to retrieve the dates of the files
  2. Extracting to a stringbuffer

18-Apr-2001    Version 1.2

  1. Solved a bug in AddFileByName.

23-May-2001    Version 1.4

About Franky Braem

Currently working at KBC Insurance in Belgium.
Programmer since 1991 using C/C++/Visual Basic and Java. Playing with ATL/WTL at home.

Click here to visit Franky Braem's homepage.

[Top] Sign in to vote for this article:     PoorExcellent  
Hint: For improved responsiveness, use Internet Explorer 4 (or above) with Javascript enabled, choose 'Use DHTML' from the View dropdown and hit 'Set Options'.
 Keyword Filter
 View   Per page   Messages since
New threadMessages 1 to 22 of 22 (Total: 22)First Prev Next Last
Subject 
Author 
Date 
  zlib.h missing
Moin Anjum 7:05 28 May 01 
  Re: zlib.h missing
F Braem 8:55 28 May 01 
  Re: zlib.h missing
Moin Anjum 9:22 28 May 01 
  Compile error
Anonymous 6:07 26 May 01 
  Re: Compile error
F Braem 8:49 28 May 01 
  Register Failed
Anonymous 22:57 28 May 01 
  Re: Register Failed
Franky Braem 3:16 7 Jun 01 
  Memory Leak
Anonymous 20:24 9 May 01 
  File name inside de zip archive
Antxon Alonso 5:19 25 Apr 01 
  Re: File name inside de zip archive
Franky Braem 7:39 25 Apr 01 
  Error in VB Demo
Anonymous 15:27 21 Mar 01 
  Re: Error in VB Demo
Franky Braem 8:31 23 Mar 01 
  Where are the Files ???
Goran Lastro 5:10 9 Mar 01 
  Re: Where are the Files ???
Anonymous 14:23 10 Mar 01 
  zlib.dll ??
cheefarr 2:39 2 Feb 01 
  Re: zlib.dll ??
Franky Braem 5:34 2 Feb 01 
  Broken DL Links
Anonymous 20:28 24 Jan 01 
  Re: Broken DL Links
Anonymous 20:57 24 Jan 01 
  Nice Job
Anatoly Ivasyuk 15:44 4 Jan 01 
  oki
Anonymous 10:52 3 Jan 01 
  Re: oki
Anonymous 10:59 3 Jan 01 
  Re: oki
Anonymous 11:55 3 Jan 01 
Last Visit: 12:00 Friday 1st January, 1999First Prev Next Last

Home >> ATL >> Controls
last updated 23 May 2001
Article content copyright Franky Braem, 2001
everything else © CodeProject, 1999-2001.
The Code Project View our sponsorsClick here for Dundas Consulting - experts in MFC, C++, TCP/IP and ASPAdvertise on the CodeProject