ziptypes.pas 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. UNIT ziptypes;
  2. {
  3. Type definitions for UNZIP
  4. * original version by Christian Ghisler
  5. * extended
  6. and
  7. amended for Win32 by Dr Abimbola Olowofoyeku (The African Chief)
  8. Homepage: http://ourworld.compuserve.com/homepages/African_Chief
  9. }
  10. INTERFACE
  11. {$ifdef Win32}
  12. TYPE
  13. nWord = longint;
  14. {$else Win32}
  15. TYPE
  16. nWord = Word;
  17. {$endif Win32}
  18. {$ifdef VirtualPascal}
  19. TYPE
  20. Integer = Longint; // Default Integer is 16 bit!
  21. {$endif VirtualPascal}
  22. CONST
  23. tBufSize = {$ifdef Win32}256{$else}63{$endif} * 1024; {buffer size}
  24. tFSize = {$ifdef Win32}259{$else}79{$endif}; {filename length}
  25. { Record for UNZIP }
  26. TYPE buftype = ARRAY [ 0..tBufSize ] of char;
  27. TYPE TDirtype = ARRAY [ 0..tFSize ] of char;
  28. TZipRec = PACKED RECORD
  29. buf : ^buftype; {please} {buffer containing central dir}
  30. bufsize, {do not} {size of buffer}
  31. localstart : word; {change these!} {start pos in buffer}
  32. Time,
  33. Size,
  34. CompressSize,
  35. headeroffset : Longint;
  36. FileName : tdirtype;
  37. PackMethod : word;
  38. Attr : Byte;
  39. END; { TZipRec }
  40. { record for callback progress Reports, etc. }
  41. TYPE
  42. pReportRec = ^TReportRec; {passed to callback functions}
  43. TReportRec = PACKED RECORD
  44. FileName : tdirtype; {name of individual file}
  45. Time, {date and time stamp of individual file}
  46. Size, {uncompressed and time stamp of individual file}
  47. CompressSize : Longint;{compressed and time stamp of individual file}
  48. Attr : integer; {file attribute of individual file}
  49. PackMethod : Word; {compression method of individual file}
  50. Ratio : byte; {compression ratio of individual file}
  51. Status : longint; {callback status code to show where we are}
  52. IsaDir : Boolean; {is this file a directory?}
  53. END; {TReportRec}
  54. { callback status codes }
  55. CONST
  56. file_starting = -1000; {beginning the unzip process; file}
  57. file_unzipping = -1001; {continuing the unzip process; file}
  58. file_completed = -1002; {completed the unzip process; file}
  59. file_Failure = -1003; {failure in unzipping file}
  60. unzip_starting = -1004; {starting with a new ZIP file}
  61. unzip_completed = -1005; {completed this ZIP file}
  62. { procedural types for callbacks }
  63. TYPE
  64. UnzipReportProc = PROCEDURE ( Retcode : longint;Rec : pReportRec );
  65. {$ifdef Delphi32}STDCALL;{$endif}
  66. { procedural type for "Report" callback: the callback function
  67. (if any) is called several times during the unzip process
  68. Error codes are sent to the callback in "Retcode". Other
  69. details are sent in the record pointed to by "Rec".
  70. * Note particularly Rec^.Status - this contains information about
  71. the current status or stage of the unzip process. It can have
  72. any of the following values;
  73. (archive status)
  74. unzip_starting = starting with a new ZIP archive (rec^.filename)
  75. unzip_completed = finished with the ZIP archive (rec^.filename)
  76. (file status)
  77. file_starting = starting to unzip (extract) a file (from archive)
  78. file_unzipping = continuing to unzip a file (from archive)
  79. (when this status value is reported, the actual number of
  80. bytes written to the file are reported in "Retcode"; this is
  81. valuable for updating any progress bar)
  82. file_completed = finshed unzip a file (from archive)
  83. file_Failure = could not extract the file (from archive)
  84. }
  85. UnzipQuestionProc = FUNCTION ( Rec : pReportRec ) : Boolean;
  86. {$ifdef Delphi32}STDCALL;{$endif}
  87. { procedural type for "Question" callback:if a file already
  88. exists, the callback (if any) will be called to ask whether
  89. the file should be overwritten by the one in the ZIP file;
  90. the details of the file in the ZIP archive are supplied in the
  91. record pointed to by "Rec"
  92. in your callback function, you should;
  93. return TRUE if you want the existing file to be overwritten
  94. return FALSE is you want the existing file to be skipped
  95. }
  96. {Error codes returned by the main unzip functions}
  97. CONST
  98. unzip_Ok = 0;
  99. unzip_CRCErr = -1;
  100. unzip_WriteErr = -2;
  101. unzip_ReadErr = -3;
  102. unzip_ZipFileErr = -4;
  103. unzip_UserAbort = -5;
  104. unzip_NotSupported = -6;
  105. unzip_Encrypted = -7;
  106. unzip_InUse = -8;
  107. unzip_InternalError = -9; {Error in zip format}
  108. unzip_NoMoreItems = -10;
  109. unzip_FileError = -11; {Error Accessing file}
  110. unzip_NotZipfile = -12; {not a zip file}
  111. unzip_SeriousError = -100; {serious error}
  112. unzip_MissingParameter = -500; {missing parameter}
  113. { the various unzip methods }
  114. CONST
  115. Unzipmethods : ARRAY [ 0..9 ] of pchar =
  116. ( 'stored', 'shrunk', 'reduced 1', 'reduced 2', 'reduced 3',
  117. 'reduced 4', 'imploded', 'tokenized', 'deflated', 'skipped' );
  118. { unzip actions being undertaken }
  119. CONST
  120. UnzipActions : ARRAY [ 0..9 ] of pchar =
  121. ( 'copying', 'unshrinking', 'unreducing 1', 'unreducing 2', 'unreducing 3',
  122. 'unreducing 4', 'exploding', 'un-tokenizing', 'inflating', 'skipping' );
  123. { rudimentary "uppercase" function }
  124. FUNCTION Upper ( s : String ) : String;
  125. { remove path and return filename only }
  126. FUNCTION StripPath ( CONST s : String ) : String;
  127. IMPLEMENTATION
  128. FUNCTION Upper ( s : String ) : String;
  129. VAR i : integer;
  130. BEGIN
  131. FOR i := 1 TO length ( s ) DO s [ i ] := Upcase ( s [ i ] );
  132. Upper := s;
  133. END;
  134. FUNCTION StripPath ( CONST s : String ) : String;
  135. VAR
  136. i, j : Word;
  137. BEGIN
  138. StripPath := s;
  139. j := length ( s );
  140. FOR i := j DOWNTO 1 DO BEGIN
  141. IF s [ i ] in [ '\', ':', '/' ] THEN BEGIN
  142. StripPath := Copy ( s, succ ( i ), j -i );
  143. exit;
  144. END;
  145. END;
  146. END;
  147. END.