// // EX22CON.CPP // // C++/DOS Example program for ArchiveLib 2.0 // // Copyright (c) Greenleaf Software, Inc. 1994 - 1996 // All Rights Reserved // // MEMBERS/FUNCTIONS DEMONSTRATED // // // DESCRIPTION // // This example program shows how you can set up a monitor and use // it to allow for an abort path during archiving. We derive a new // monitor class from ALBargraph. We are going to use ALBargraph's // existing functions, and just add a keyboard check. So to the end // user it will look exactly like the existing bargraph. // // REVISION HISTORY // // February 1, 1996 2.0A : Second release // #include #include "arclib.h" #include "bargraph.h" #include "pkarc.h" #include "glarc.h" #include // // Our new class has to have a ctor, plus we add a Progress() function. // The Progress() function gets called a lot, so that is where we get // to check the keyboard for a keypress. // class MyMonitor : public ALBarGraph { public : MyMonitor() : ALBarGraph( AL_MONITOR_OBJECTS ){ ; } void AL_PROTO Progress( long object_so_far, ALStorage AL_DLL_FAR &object ); virtual AL_INLINE_PROTO ~MyMonitor(){;} // // I don't really need these functions, but if I don't declare them here, // gcc goes looking for them, even though it doesn't need them. // protected : AL_PROTO MyMonitor( MyMonitor AL_DLL_FAR & ); MyMonitor AL_DLL_FAR & AL_PROTO operator=( const MyMonitor AL_DLL_FAR & ); }; // // The Progress() function is clearly pretty lazy. The first thing // it does is call ALBarGraph::Progress(), so we don't have to do any // U/I stuff. All we do then is check to see if the user hit a keystroke. // If the did, we set the error flag on the object, which should lead // to an abort of the archiving function. // void MyMonitor::Progress( long object_tell, ALStorage& object ) { ALBarGraph::Progress( object_tell, object ); if ( kbhit() ) { getch(); object.mStatus.SetError( AL_USER_ABORT, "User hit abort key..." ); } } // // This should look just like EX00CON.CPP. It is nearly identical, with // the only important difference being the fact that it creates monitor // from my derived class. // int main() { MyMonitor monitor; cout << "Archive Library 2.0\nEX22CON.CPP\n\n"; cout << "Our new class has to have a ctor, plus we add a Progress() function.\n"; cout << "The Progress() function gets called a lot, so that is where we get\n"; cout << "to check the keyboard for a keypress.\n\n"; getch(); #if defined( ZIP ) ALPkArchive archive( "dos00.zip" ); ALEntryList list( &monitor, PkCompressTools() ); #else ALGlArchive archive( "dos00.gal" ); ALEntryList list( &monitor, GlCompressTools() ); #endif cout << "\nAdding input*.dat and *.bak to " << archive.GetStorageObject()->mName << " using an ALBarGraph\n\n"; list.AddWildCardFiles( "input*.dat, *.bak" ); archive.Create( list ); cout << "\n" << archive.mStatus << "\n"; return archive.mStatus; }