home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 31 / CDASC_31_1996_juillet_aout.iso / vrac / altd201a.zip / EXAMPLES.ARJ / EXAMPLES / EX26CON.CPP < prev    next >
C/C++ Source or Header  |  1996-04-19  |  3KB  |  109 lines

  1. //
  2. // EX26CON.CPP
  3. //
  4. //  C++/DOS Example program for ArchiveLib 2.0
  5. //
  6. //  Copyright (c) Greenleaf Software, Inc. 1996
  7. //  All Rights Reserved
  8. //
  9. // MEMBERS/FUNCTIONS DEMONSTRATED
  10. //
  11. //   ALExtract()
  12. //   ALReadDir()
  13. //   ALFreeDir()
  14. //
  15. // DESCRIPTION
  16. //
  17. //  This example program demonstrates ALExtract(), one of the
  18. //  ZIP file manipulation functions in the simplified interface.
  19. //  It creates a directory named "temp", then extracts the
  20. //  contents of CON00.ZIP into that directory.  Note that EX25CON.CPP
  21. //  can be used to create CON00.ZIP.
  22. //
  23. //  This program also demonstrates the use of the callback function
  24. //  in the simplified interface.
  25. //
  26. // REVISION HISTORY
  27. //
  28. //  February 1, 1996  2.0A  : Second release
  29. //
  30. //  March 18, 1996    2.01A : Added documentation and cleaned up the UI
  31. //
  32. //  April 5, 1996     2.01A : Added a little bit of info to the UI.  Note
  33. //                            that I have to flush the output stream before
  34. //                            doing getch(), since IBM Visual Age doesn't
  35. //                            do it for me at an end of line.
  36.  
  37. #include <iostream.h>
  38. #include <iomanip.h>
  39. #include <conio.h>
  40. #include <stdlib.h>
  41. #include <stdio.h>
  42. #include <string.h>
  43.  
  44. #if defined( AL_BORLAND )
  45. #include <dir.h>
  46. #else
  47. #include <direct.h>
  48. #endif
  49.  
  50. #include "alsimple.h"
  51.  
  52. //
  53. // The callback function for the simplified interface gets
  54. // called at at two different times.  First, when an object
  55. // is being added to the archive, the callback function
  56. // is called with a valid filename in parameter name,
  57. // and -1 in the two numeric paramters.  Second, at various
  58. // times during the compression cycle, it is called with
  59. // a 0 (null pointer) for the parameter name, and valid ratios
  60. // in the two numeric parameters.
  61. //
  62. // This simple callback function prints file names, and prints
  63. // both ratios during progress.
  64. //
  65.  
  66. void my_callback( const char AL_DLL_FAR *name,
  67.                   int object_ratio,
  68.                   int job_ratio )
  69. {
  70.     if ( name )
  71.         cout << "\n" << name << "  ";
  72.     if ( object_ratio >= 0 ) {
  73.         char buf[ 24 ];
  74.         sprintf( buf, "%d%%  %d%%", object_ratio, job_ratio );
  75.         cout << "          \b\b\b\b\b\b\b\b\b\b" << buf;
  76.         for ( int i = 0 ; i < (int) strlen( buf ) ; i++ )
  77.             cout << '\b';
  78.     }
  79.     cout.flush();
  80. }
  81.  
  82. main()
  83. {
  84.     cout << "Archive Library 2.0\nEX26CON.CPP\n\n";
  85.     cout << "This example program creates a temp directory, then\n";
  86.     cout << "extracts the contents of CON00.ZIP into that directory.\n";
  87.     cout << "You can create CON00.ZIP by running EX25CON.\n";
  88.     cout << "\nHit ESCAPE to abort, any other key to proceed..." << flush;
  89.     int c = getch();
  90.     cout << "\n" << flush;
  91.     if ( c == 0 || c == 0x1b || c == 3 )
  92.         exit( 1 );
  93.     mkdir( "temp" );
  94.     if ( chdir( "temp" ) == 0 ) {
  95.         struct ALZipDir *z = ALReadDir( "..\\con00.zip", 0, 0 );
  96.         if ( z != 0 ) {
  97.             int i = ALExtract( z, 0, my_callback );
  98.             cout << "\n\nALExtract returned " << i << "\n";
  99.             ALFreeDir( z );
  100.         } else
  101.             cout << "\n\nError reading zip file directory\n";
  102.         chdir( ".." );
  103.     }
  104.     cout << "\nHit any key to exit..." << flush;
  105.     getch();
  106.     return 0;
  107. }
  108.  
  109.