114 lines
		
	
	
		
			3.2 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			114 lines
		
	
	
		
			3.2 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
//
 | 
						|
// EX05CON.CPP
 | 
						|
//
 | 
						|
//  C++/DOS Example program for ArchiveLib 2.0
 | 
						|
//
 | 
						|
//  Copyright (c) Greenleaf Software, Inc. 1994 - 1996
 | 
						|
//  All Rights Reserved
 | 
						|
//
 | 
						|
// MEMBERS/FUNCTIONS DEMONSTRATED
 | 
						|
//
 | 
						|
//  ALStorage::GetSize()
 | 
						|
//  ALArchiveBase::GetComment()
 | 
						|
//  ALEntry::GetComment()
 | 
						|
//  ALEntry::GetCompressedSize()
 | 
						|
//  ALEntry::GetMark()
 | 
						|
//
 | 
						|
// DESCRIPTION
 | 
						|
//
 | 
						|
//  This example program gives a brief listing of an archive's contents.
 | 
						|
//  If you don't specify an archive name on the command line, by
 | 
						|
//  default it will display the contents of DOS00.GAL.  If you don't have a
 | 
						|
//  copy of DOS00.GAL already, you can create one using EX00CON.
 | 
						|
//
 | 
						|
// REVISION HISTORY
 | 
						|
//
 | 
						|
//  February 1, 1996  2.0A  : Second release
 | 
						|
//
 | 
						|
 | 
						|
#include <iostream.h>
 | 
						|
#include <iomanip.h>
 | 
						|
#include <string.h>
 | 
						|
#include <conio.h>
 | 
						|
 | 
						|
#include "arclib.h"
 | 
						|
#include "pkarc.h"
 | 
						|
#include "glarc.h"
 | 
						|
 | 
						|
ostream &operator << ( ostream &ostr, ALEntryList &list );
 | 
						|
 | 
						|
main( int argc, char *argv[] )
 | 
						|
{
 | 
						|
 char arcname[ 80 ] = "dos00.gal";
 | 
						|
 | 
						|
 cout << "Archive Library 2.0\nEX05CON.CPP\n\n";
 | 
						|
 cout << "This example program gives a brief listing of an archive's contents.\n";
 | 
						|
 cout << "If you don't specify an archive name on the command line, by\n";
 | 
						|
 cout << "default it will display the contents of DOS00.GAL.  If you don't have a\n";
 | 
						|
 cout << "copy of DOS00.GAL already, you can create one using EX00CON.\n\n";
 | 
						|
 getch();
 | 
						|
 | 
						|
 if ( argc == 2 )
 | 
						|
    strcpy( arcname, argv[ 1 ] );
 | 
						|
 else
 | 
						|
#if defined( ZIP )
 | 
						|
    strcpy( arcname, "dos00.zip" );
 | 
						|
 ALPkArchive archive( arcname );
 | 
						|
#else
 | 
						|
    strcpy( arcname, "dos00.gal" );
 | 
						|
 ALGlArchive archive( arcname );
 | 
						|
#endif
 | 
						|
 | 
						|
    ALEntryList list;
 | 
						|
 | 
						|
    archive.ReadDirectory( list );
 | 
						|
    if ( archive.GetComment() ) {
 | 
						|
        cout << "Archive comment: "
 | 
						|
             << archive.GetComment()
 | 
						|
             << endl;
 | 
						|
    }
 | 
						|
    cout << list; //This uses the overloaded stream operator, shown below
 | 
						|
    return 1;
 | 
						|
}
 | 
						|
 | 
						|
ostream &operator << ( ostream &ostr, ALEntryList &list )
 | 
						|
{
 | 
						|
    long total = 0;
 | 
						|
    long tsize = 0;
 | 
						|
    long tcomp = 0;
 | 
						|
 | 
						|
    ALEntry *entry = list.GetFirstEntry();
 | 
						|
 | 
						|
    if ( entry == 0 )
 | 
						|
        return ostr << "No entries in list";
 | 
						|
 | 
						|
    ostr << "============================================================================"
 | 
						|
         << endl;
 | 
						|
    ostr << "M            Name                Size        Comp   Comment" << endl;
 | 
						|
    ostr << "----------------------------------------------------------------------------"
 | 
						|
         << endl;
 | 
						|
 | 
						|
    while ( entry ) {
 | 
						|
        total++;
 | 
						|
        tsize += entry->mpStorageObject->GetSize();
 | 
						|
        tcomp += entry->GetCompressedSize();
 | 
						|
        ostr << ( entry->GetMark() ? "*" : " " );
 | 
						|
        ostr << setw( 24 ) << entry->mpStorageObject->mName;
 | 
						|
        ostr << setw( 12 ) << entry->mpStorageObject->GetSize();
 | 
						|
        ostr << setw( 12 ) << entry->GetCompressedSize();
 | 
						|
        if ( entry->GetComment() )
 | 
						|
            ostr << "  " << entry->GetComment();
 | 
						|
        ostr << endl;
 | 
						|
        entry = entry->GetNextEntry();
 | 
						|
    }
 | 
						|
    ostr << "----------------------------------------------------------------------------"
 | 
						|
         << endl;
 | 
						|
    ostr << " Total";
 | 
						|
    ostr << setw( 9 ) << total;
 | 
						|
    ostr << setw( 22 ) << tsize;
 | 
						|
    ostr << setw( 12 ) << tcomp << endl;
 | 
						|
 | 
						|
    return ostr;
 | 
						|
}
 | 
						|
 |