ziptypes.pas 6.0 KB

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