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

  1. //
  2. // EX27CON.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. //   ALDelete()
  12. //   ALReadDir()
  13. //   ALFreeDir()
  14. //
  15. // DESCRIPTION
  16. //
  17. //  This example program demonstrates ALDelete(), one of the
  18. //  ZIP file manipulation functions in the simplified interface.
  19. //  It goes through the directory read in from CON00.ZIP, and marks
  20. //  every other file for deletion.  It then calls ALDelete() to
  21. //  actually delete the objects.  You can create a copy of CON00.ZIP
  22. //  with EX25CON.CPP.
  23. //
  24. //  This program also demonstrates the use of the callback function
  25. //  in the simplified interface.
  26. //
  27. // REVISION HISTORY
  28. //
  29. //  February 1, 1996  2.0A  : Second release
  30. //
  31. //  April 5, 1996     2.01A : Added a little bit of info to the UI.  Note
  32. //                            that I have to flush the output stream before
  33. //                            doing getch(), since IBM Visual Age doesn't
  34. //                            do it for me at an end of line.
  35.  
  36. #include <iostream.h>
  37. #include <iomanip.h>
  38. #include <conio.h>
  39. #include <string.h>
  40. #include <stdlib.h>
  41. #include <stdio.h>
  42.  
  43. #if defined( AL_BORLAND )
  44. #include <dir.h>
  45. #else
  46. #include <direct.h>
  47. #endif
  48.  
  49. #include "alsimple.h"
  50.  
  51. //
  52. // The callback function for the simplified interface gets
  53. // called at at two different times.  First, when an object
  54. // is being added to the archive, the callback function
  55. // is called with a valid filename in parameter name,
  56. // and -1 in the two numeric paramters.  Second, at various
  57. // times during the compression cycle, it is called with
  58. // a 0 (null pointer) for the parameter name, and valid ratios
  59. // in the two numeric parameters.
  60. //
  61. // Note that the monitor function acts kind of funky when you
  62. // are performing a delete operation.  Instead of writing the
  63. // names of files that it is deleting, it prints the names
  64. // of the files that are being kept.  That's because those are
  65. // the files that are being copied from the old archive to the
  66. // new archive.
  67. //
  68.  
  69. void my_callback( const char AL_DLL_FAR *name,
  70.                   int object_ratio,
  71.                   int job_ratio )
  72. {
  73.     if ( name )
  74.         cout << "\n" << name << "  ";
  75.     if ( object_ratio >= 0 ) {
  76.         char buf[ 24 ];
  77.         sprintf( buf, "%d%%  %d%%", object_ratio, job_ratio );
  78.         cout << "          \b\b\b\b\b\b\b\b\b\b" << buf;
  79.         for ( int i = 0 ; i < (int) strlen( buf ) ; i++ )
  80.             cout << '\b';
  81.     }
  82. }
  83.  
  84. main()
  85. {
  86.     cout << "Archive Library 2.0\nEX27CON.CPP\n\n";
  87.     cout << "This example program deletes every other file from\n";
  88.     cout << "CON00.ZIP using the ALDelete() simplified interface\n";
  89.     cout << "function. You can create CON00.ZIP by running EX25CON.\n";
  90.     cout << "\nHit ESCAPE to abort, any other key to proceed..." << flush;
  91.     int c = getch();
  92.     cout << endl;
  93.     if ( c == 0 || c == 0x1b || c == 3 )
  94.         exit( 1 );
  95.     cout << endl;
  96.  
  97.     int i;
  98.     int count;
  99.     struct ALZipDir *z = ALReadDir( "con00.zip", &count, 0 );
  100.     if ( z != 0 ) {
  101.         for ( i = 0 ; i < count ; i++ )
  102.             if ( i % 2 )
  103.                 z[ i ].mark = 0;
  104.             else
  105.                 cout << "Deleting " << z[ i ].name << endl;
  106.         int j = ALDelete( z, my_callback );
  107.         cout << "\n\nALDelete returned " << j << endl;
  108.         ALFreeDir( z );
  109.     } else
  110.         cout << "\n\nError reading zip file directory\n";
  111.     cout << "\nHit any key to exit..." << flush;
  112.     getch();
  113.     return 0;
  114. }
  115.  
  116.