home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DP Tool Club 31
/
CDASC_31_1996_juillet_aout.iso
/
vrac
/
altd201a.zip
/
EXAMPLES.ARJ
/
EXAMPLES
/
EX25CON.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1996-04-19
|
4KB
|
133 lines
//
// EX25CON.CPP
//
// C++/DOS Example program for ArchiveLib 2.0
//
// Copyright (c) Greenleaf Software, Inc. 1996
// All Rights Reserved
//
// MEMBERS/FUNCTIONS DEMONSTRATED
//
// ALCreate()
// ALReadDir()
// ALFreeDir()
// ALAppend()
//
// DESCRIPTION
//
// This example program demonstrates several functions in the
// ArchiveLib simplified interface. It first adds a set of files
// to an archive using ALCreate(). It then reads the directory
// for the archive and prints its contents. It then appends
// additional files to the archive.
//
// This program also demonstrates the use of the callback function
// in the simplified interface.
//
// 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 <conio.h>
#include <iostream.h>
#include <iomanip.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#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();
}
//
// A simple function that is used when I want to display a ratio
//
int ratio( struct ALZipDir *z )
{
return int( 100L - ( ( 100L * z->compressed_size ) / (long) z->size ) );
}
main()
{
cout << "Archive Library 2.0\nEX25CON.CPP\n\n";
cout << "This example program creates CON00.ZIP, initializing it\n";
cout << "with compressed copies of BUILD*.* and *.BAK. After doing\n";
cout << "this it reads the directory and prints the results. Finally\n";
cout << "it performs an append, adding C:\\COMMAND.* to the archive.\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 );
int i;
int count;
int error;
struct ALZipDir *z;
char *levels[] = { "Stored ",
"DeflatN",
"DeflatX",
"DeflatF",
"DeflatS" };
printf( "\nCreating CON00.ZIP with *.BAK and BUILD*.*\n\n" );
i = ALCreate( "con00.zip", "*.bak, build*.*", 0, my_callback );
printf( "\nALCreate() returned %d\n\n", i );
z = ALReadDir( "con00.zip", &count, &error );
if ( z != 0 && error == AL_SUCCESS )
printf( "Contents of CON00.ZIP:\n\n" );
for ( i = 0 ; i < count ; i++ )
printf( "%7ld %s %7ld %3d%% %02d-%02d-%04d %02d:%02d %s %s\n",
z[ i ].size,
levels[ z[ i ].level ],
z[ i ].compressed_size,
ratio( z + i ),
z[ i ].month,
z[ i ].date,
z[ i ].year,
z[ i ].hour,
z[ i ].minute,
z[ i ].name,
z[ i ].comment );
ALFreeDir( z );
printf( "\nAppending c:\\command.* to CON00.ZIP\n" );
i = ALAppend( "con00.zip", "*.tr? c:\\command.*", 1, my_callback );
printf( "\n\n" );
printf( "ALAppend() returned %d\n\n", i );
cout << "\nHit any key to exit..." << flush;
getch();
return i;
}