home *** CD-ROM | disk | FTP | other *** search
- //
- // EX26CON.CPP
- //
- // C++/DOS Example program for ArchiveLib 2.0
- //
- // Copyright (c) Greenleaf Software, Inc. 1996
- // All Rights Reserved
- //
- // MEMBERS/FUNCTIONS DEMONSTRATED
- //
- // ALExtract()
- // ALReadDir()
- // ALFreeDir()
- //
- // DESCRIPTION
- //
- // This example program demonstrates ALExtract(), one of the
- // ZIP file manipulation functions in the simplified interface.
- // It creates a directory named "temp", then extracts the
- // contents of CON00.ZIP into that directory. Note that EX25CON.CPP
- // can be used to create CON00.ZIP.
- //
- // This program also demonstrates the use of the callback function
- // in the simplified interface.
- //
- // REVISION HISTORY
- //
- // February 1, 1996 2.0A : Second release
- //
- // March 18, 1996 2.01A : Added documentation and cleaned up the UI
- //
- // April 5, 1996 2.01A : Added a little bit of info to the UI. Note
- // that I have to flush the output stream before
- // doing getch(), since IBM Visual Age doesn't
- // do it for me at an end of line.
-
- #include <iostream.h>
- #include <iomanip.h>
- #include <conio.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
-
- #if defined( AL_BORLAND )
- #include <dir.h>
- #else
- #include <direct.h>
- #endif
-
- #include "alsimple.h"
-
- //
- // The callback function for the simplified interface gets
- // called at at two different times. First, when an object
- // is being added to the archive, the callback function
- // is called with a valid filename in parameter name,
- // and -1 in the two numeric paramters. Second, at various
- // times during the compression cycle, it is called with
- // a 0 (null pointer) for the parameter name, and valid ratios
- // in the two numeric parameters.
- //
- // This simple callback function prints file names, and prints
- // both ratios during progress.
- //
-
- void my_callback( const char AL_DLL_FAR *name,
- int object_ratio,
- int job_ratio )
- {
- if ( name )
- cout << "\n" << name << " ";
- if ( object_ratio >= 0 ) {
- char buf[ 24 ];
- sprintf( buf, "%d%% %d%%", object_ratio, job_ratio );
- cout << " \b\b\b\b\b\b\b\b\b\b" << buf;
- for ( int i = 0 ; i < (int) strlen( buf ) ; i++ )
- cout << '\b';
- }
- cout.flush();
- }
-
- main()
- {
- cout << "Archive Library 2.0\nEX26CON.CPP\n\n";
- cout << "This example program creates a temp directory, then\n";
- cout << "extracts the contents of CON00.ZIP into that directory.\n";
- cout << "You can create CON00.ZIP by running EX25CON.\n";
- cout << "\nHit ESCAPE to abort, any other key to proceed..." << flush;
- int c = getch();
- cout << "\n" << flush;
- if ( c == 0 || c == 0x1b || c == 3 )
- exit( 1 );
- mkdir( "temp" );
- if ( chdir( "temp" ) == 0 ) {
- struct ALZipDir *z = ALReadDir( "..\\con00.zip", 0, 0 );
- if ( z != 0 ) {
- int i = ALExtract( z, 0, my_callback );
- cout << "\n\nALExtract returned " << i << "\n";
- ALFreeDir( z );
- } else
- cout << "\n\nError reading zip file directory\n";
- chdir( ".." );
- }
- cout << "\nHit any key to exit..." << flush;
- getch();
- return 0;
- }
-
-