TEST2.PAS
Upload User: qxf5203344
Upload Date: 2021-08-05
Package Size: 101k
Code Size: 3k
Development Platform:

Delphi

  1. {
  2. test program for unzip, using a simple Pascal object
  3. }
  4. PROGRAM test2;
  5. {$I unzip.Inc}
  6. {$ifdef windows}
  7. USES
  8. wintypes,
  9. winprocs,
  10. {$ifdef Delphi}sysutils, {$else}windos, strings, {$endif Delphi}
  11. unzip,
  12. ziptypes,
  13. wincrt;
  14. {$else}
  15. USES
  16. dos,
  17. crt,
  18. strings,
  19. unzip,
  20. ziptypes;
  21. {$endif}
  22. TYPE
  23. UnZipObject = OBJECT
  24.    CONSTRUCTOR Init ( CONST ZipFile, Directory, FileSpecs : String;Report : UnzipReportProc );
  25.    DESTRUCTOR  Done;virtual;
  26.    FUNCTION    Run : integer;virtual;
  27.    FUNCTION    View : integer;virtual;
  28.    PRIVATE
  29.       aName,
  30.       aDir,
  31.       aSpec : String;
  32.       ZipReport : UnzipReportProc;
  33. END;
  34. {/////////////////////////////////////////////////////}
  35. PROCEDURE Report ( Retcode : longint;R : pReportRec );
  36. {$ifdef Windows}{$ifdef win32}STDCALL;{$else}EXPORT;{$endif}{$endif}
  37. BEGIN
  38.   WITH r^ DO
  39.   CASE Status of
  40.   file_completed :
  41.    Writeln
  42.    ( 
  43.    UnzipMethods [ packmethod ] : 9,
  44.    '  ', Size : 9,
  45.    '  ', CompressSize : 9,
  46.    '  ', Ratio : 5, '%',
  47.    '  ', filename
  48.    );
  49.    unzip_completed :
  50.    Writeln
  51.    ( 
  52.    'Archived' : 9,
  53.    '  ', Size : 9,
  54.    '  ', CompressSize : 9,
  55.    '  ', Ratio : 5, '%',
  56.    '  ', filename
  57.    );
  58.  END {case}
  59. END; {Report}
  60. {/////////////////////////////////////////////////////}
  61. PROCEDURE Report2 ( Retcode : longint;R : pReportRec );
  62. {$ifdef Windows}{$ifdef win32}STDCALL;{$else}EXPORT;{$endif}{$endif}
  63. BEGIN
  64.    WITH r^ DO
  65.    Writeln
  66.    ( 
  67.    UnzipMethods [ packmethod ] : 9,
  68.    '  ', Size : 9,
  69.    '  ', CompressSize : 9,
  70.    '  ', Ratio : 5, '%',
  71.    '  ', filename
  72.    );
  73. END; {Report2}
  74. {/////////////////////////////////////////////////////}
  75. CONSTRUCTOR UnZipObject.Init;
  76. BEGIN
  77.   aName := ZipFile;
  78.   adir  := Directory + #0;
  79.   aSpec := FileSpecs + #0;
  80.   ZipReport := Report;
  81.   IF pos ( '.', aName ) = 0 THEN aName := aName + '.ZIP';
  82.   aName := aName + #0;
  83. END;
  84. DESTRUCTOR  UnZipObject.Done;
  85. BEGIN
  86. END;
  87. FUNCTION    UnZipObject.Run : integer;
  88. BEGIN
  89.   Run := FileUnzip ( @aName [ 1 ], @aDir [ 1 ], @aSpec [ 1 ], ZipReport, NIL );
  90. END;
  91. FUNCTION    UnZipObject.View : integer;
  92. BEGIN
  93.   View := ViewZip ( @aName [ 1 ], @aSpec [ 1 ], Report2 );
  94. END;
  95. VAR
  96. Zip : UnZipObject;
  97. i : integer;
  98. p : pchar;
  99. BEGIN
  100.   IF ( paramcount < 2 )
  101.   THEN BEGIN
  102.     getmem ( p, 512 );
  103.     strcopy ( p, 'Syntax=TEST2 <filename.ZIP> <[target dir] or [/v]> [specs]'#13#10#13#10 );
  104.     Strcat ( p, 'Examples: '#13#10 );
  105.     Strcat ( p, '    TEST2 TEST.ZIP C:TEMP'#13#10 );
  106.     Strcat ( p, '    TEST2 TEST.ZIP C:TEMP *.PAS'#13#10 );
  107.     Strcat ( p, '    TEST2 TEST.ZIP C:TEMP ZIP*.*'#13#10 );
  108.     Strcat ( p, '    TEST2 TEST.ZIP /V'#13#10 );
  109.     Strcat ( p, '    TEST2 TEST.ZIP /V *.EXE'#13#10 );
  110.   {$ifdef Windows}
  111.      Messagebox ( 0, p, 'Chief''s UNZIP', 0 );
  112.   {$else}
  113.      Writeln ( p );
  114.   {$endif}
  115.      freemem ( p, 512 );
  116.      halt;
  117.   END;
  118.   {$ifdef Windows}
  119.    WITH ScreenSize DO BEGIN
  120.         x := 75;
  121.         y := 500;
  122.    END;
  123.    WITH WindowOrg DO BEGIN
  124.         x := 1;
  125.         y := 1
  126.    END;
  127.   {$endif}
  128.   WITH Zip DO BEGIN
  129.       Init ( ParamStr ( 1 ), ParamStr ( 2 ), ParamStr ( 3 ), Report );
  130.       IF ( upper ( paramstr ( 2 ) ) = '/V' ) OR ( upper ( paramstr ( 2 ) ) = '-V' )
  131.       THEN i := View
  132.       ELSE i := Run;
  133.       Done;
  134.   END;
  135. END.