ziptypes.pas 6.1 KB

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