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

  1. //
  2. // EX28CON.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. //   ALReadDir()
  12. //   ALFreeDir()
  13. //   ALSetName()
  14. //   ALSetComment()
  15. //
  16. // DESCRIPTION
  17. //
  18. //  This example program demonstrates ALSetName() and
  19. //  ALSetComment(), two of the ZIP file manipulation functions in the
  20. //  ArchiveLib simplified interface. It walks through the directory
  21. //  of CON00.ZIP, and prepends a "temp/" string to each of the
  22. //  objects in the directory.  A subsequent call to ALExtract()
  23. //  would then extract the files to a temp directory, instead of
  24. //  the current directory.
  25. //
  26. // REVISION HISTORY
  27. //
  28. //  February 1, 1996  2.0A  : Second release
  29. //
  30. //  April 5, 1996     2.01A : Added a little bit of info to the UI.  Note
  31. //                            that I have to flush the output stream before
  32. //                            doing getch(), since IBM Visual Age doesn't
  33. //                            do it for me at an end of line.
  34. //
  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. #include "alsimple.h"
  43.  
  44. //
  45. // A simple function that is used when I want to display a ratio
  46. //
  47. inline int ratio( struct ALZipDir *z )
  48. {
  49.     return int( 100L - ( ( 100L * z->compressed_size ) / (long) z->size ) );
  50. }
  51.  
  52. main()
  53. {
  54.     cout << "Archive Library 2.0\nEX28CON.CPP\n\n";
  55.     cout << "This example program prepends a temp/ string to \n";
  56.     cout << "the start of every file name in CON00.ZIP ALSetName()\n";
  57.     cout << "function in the simplified interface.  It also modifies\n";
  58.     cout << "the comment field for each file.  You can create CON00.ZIP\n";
  59.     cout << "by running EX25CON.\n";
  60.     cout << "\nHit ESCAPE to abort, any other key to proceed..." << flush;
  61.     int c = getch();
  62.     cout << endl;
  63.     if ( c == 0 || c == 0x1b || c == 3 )
  64.         exit( 1 );
  65.     cout << endl;
  66.  
  67.     cout << "\nModifying names and comments in con00.zip\n";
  68.     ALZipDir *z = ALReadDir( "con00.zip", 0, 0 );
  69.     int i;
  70.     if ( z != 0 ) {
  71.         for ( i = 0 ; z[ i ].size != -1 ; i++ ) {
  72.             char *p = new char[ ( strlen( z[ i ].name ) + 10 ) ];
  73.             strcpy( p, "temp/" );
  74.             strcat( p, z[ i ].name );
  75.             ALSetName( z + i, p );
  76.             delete[] p;
  77.             char buf[ 81 ];
  78.             sprintf( buf, "Modified path for entry %d", i );
  79.             ALSetComment( z + i, buf );
  80.         }
  81.         ALWriteDir( z );
  82.         ALFreeDir( z );
  83.     } else
  84.         cout << "Error reading zip file directory\n";
  85.     int count;
  86.     int error;
  87.     z = ALReadDir( "con00.zip", &count, &error );
  88.     if ( z != 0 && error == AL_SUCCESS ) {
  89.         cout << "Contents of CON00.ZIP:\n\n" << flush;
  90.         for ( i = 0 ; i < count ; i++ )
  91.             printf( "%7ld %7ld %3d%% %-20s %s\n",
  92.                     z[ i ].size,
  93.                     z[ i ].compressed_size,
  94.                     ratio( z + i ),
  95.                     z[ i ].name,
  96.                     z[ i ].comment );
  97.         ALFreeDir( z );
  98.     } else
  99.         cout << "Error reading zip file directory\n";
  100.     cout << "\nHit any key to exit..." << flush;
  101.     getch();
  102.     return 0;
  103. }
  104.  
  105.