home *** CD-ROM | disk | FTP | other *** search
- //
- // EX28CON.CPP
- //
- // C++/DOS Example program for ArchiveLib 2.0
- //
- // Copyright (c) Greenleaf Software, Inc. 1996
- // All Rights Reserved
- //
- // MEMBERS/FUNCTIONS DEMONSTRATED
- //
- // ALReadDir()
- // ALFreeDir()
- // ALSetName()
- // ALSetComment()
- //
- // DESCRIPTION
- //
- // This example program demonstrates ALSetName() and
- // ALSetComment(), two of the ZIP file manipulation functions in the
- // ArchiveLib simplified interface. It walks through the directory
- // of CON00.ZIP, and prepends a "temp/" string to each of the
- // objects in the directory. A subsequent call to ALExtract()
- // would then extract the files to a temp directory, instead of
- // the current directory.
- //
- // REVISION HISTORY
- //
- // February 1, 1996 2.0A : Second release
- //
- // 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 <string.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include "alsimple.h"
-
- //
- // A simple function that is used when I want to display a ratio
- //
- inline int ratio( struct ALZipDir *z )
- {
- return int( 100L - ( ( 100L * z->compressed_size ) / (long) z->size ) );
- }
-
- main()
- {
- cout << "Archive Library 2.0\nEX28CON.CPP\n\n";
- cout << "This example program prepends a temp/ string to \n";
- cout << "the start of every file name in CON00.ZIP ALSetName()\n";
- cout << "function in the simplified interface. It also modifies\n";
- cout << "the comment field for each file. You can create CON00.ZIP\n";
- cout << "by running EX25CON.\n";
- cout << "\nHit ESCAPE to abort, any other key to proceed..." << flush;
- int c = getch();
- cout << endl;
- if ( c == 0 || c == 0x1b || c == 3 )
- exit( 1 );
- cout << endl;
-
- cout << "\nModifying names and comments in con00.zip\n";
- ALZipDir *z = ALReadDir( "con00.zip", 0, 0 );
- int i;
- if ( z != 0 ) {
- for ( i = 0 ; z[ i ].size != -1 ; i++ ) {
- char *p = new char[ ( strlen( z[ i ].name ) + 10 ) ];
- strcpy( p, "temp/" );
- strcat( p, z[ i ].name );
- ALSetName( z + i, p );
- delete[] p;
- char buf[ 81 ];
- sprintf( buf, "Modified path for entry %d", i );
- ALSetComment( z + i, buf );
- }
- ALWriteDir( z );
- ALFreeDir( z );
- } else
- cout << "Error reading zip file directory\n";
- int count;
- int error;
- z = ALReadDir( "con00.zip", &count, &error );
- if ( z != 0 && error == AL_SUCCESS ) {
- cout << "Contents of CON00.ZIP:\n\n" << flush;
- for ( i = 0 ; i < count ; i++ )
- printf( "%7ld %7ld %3d%% %-20s %s\n",
- z[ i ].size,
- z[ i ].compressed_size,
- ratio( z + i ),
- z[ i ].name,
- z[ i ].comment );
- ALFreeDir( z );
- } else
- cout << "Error reading zip file directory\n";
- cout << "\nHit any key to exit..." << flush;
- getch();
- return 0;
- }
-
-