Subversion Repositories autosfx

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 daniel-mar 1
unit ZMDelZip19;
2
 
3
(*
4
  ZMDelZip19.pas - port of DelZip.h (dll interface)
5
 Copyright (C) 2009, 2010  by Russell J. Peters, Roger Aelbrecht,
6
      Eric W. Engler and Chris Vleghert.
7
 
8
   This file is part of TZipMaster Version 1.9.
9
 
10
    TZipMaster is free software: you can redistribute it and/or modify
11
    it under the terms of the GNU Lesser General Public License as published by
12
    the Free Software Foundation, either version 3 of the License, or
13
    (at your option) any later version.
14
 
15
    TZipMaster is distributed in the hope that it will be useful,
16
    but WITHOUT ANY WARRANTY; without even the implied warranty of
17
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
    GNU Lesser General Public License for more details.
19
 
20
    You should have received a copy of the GNU Lesser General Public License
21
    along with TZipMaster.  If not, see <http://www.gnu.org/licenses/>.
22
 
23
    contact: problems@delphizip.org (include ZipMaster in the subject).
24
    updates: http://www.delphizip.org
25
    DelphiZip maillist subscribe at http://www.freelists.org/list/delphizip
26
************************************************************************)
27
 
28
interface
29
 
30
uses Windows;
31
 
32
(* zacArg - return string
33
   Arg1 = argument
34
 
35
     1 = password
36
     2 = RootDir
37
     3 = ExtractDir
38
     4 = FSpecArgs      Arg3 = index
39
     5 = FSpecArgsExcl  Arg3 = index
40
*)
41
 
42
type
43
  TActionCodes = (zacTick, zacItem, zacProgress, zacEndOfBatch,
44
    zacCount, zacSize, zacXItem, zacXProgress, zacMessage,
45
    zacNewName, zacPassword, zacCRCError, zacOverwrite, zacSkipped,
46
    zacComment, zacData, zacExtName, zacNone,
47
    zacKey, zacArg, zacWinErr);
48
 
49
  TCBArgs = (zcbFilename, zcbPassword, zcbRootDir, zcbExtractDir, zcbComment,
50
    zcbFSpecArgs, zcbFSpecArgsExcl, zcbSpecials, zcbTempPath);
51
 
52
  TZStreamActions = (zsaIdentify, zsaCreate, zsaClose, zsaPosition, zsaRead,
53
    zsaWrite);
54
 
55
//// structure used to 'identify' streams
56
//type
57
//   PZSStrats = ^TZSStats;
58
//   TZSStats = Packed Record
59
//      Size: int64;
60
//      Date: cardinal;
61
//      Attrs: cardinal;
62
//   end;
63
 
64
const
65
//  Callback_Except_No = 10106;
66
  ZCallBack_Check = $0707;
67
  ZStream_Check = $070B;
68
 
69
    { All the items in the CallBackStruct are passed to the Delphi
70
      program from the DLL.  Note that the "Caller" value returned
71
      here is the same one specified earlier in ZipParms by the
72
      Delphi pgm. }
73
type
74
  TZCallBackStruct = packed record
75
    Caller:  Pointer;         // "self" reference of the Delphi form }
76
    Version: Longint;         // version no. of DLL }
77
    IsOperationZip: Longbool; // True=zip, False=unzip }
78
    ActionCode: integer;
79
    HaveWide: integer;        // wide string passed
80
    MsgP: pByte;              // pointer to text/data or stream src/dst
81
    Msg2P: pByte;             // orig file comment
82
    File_Size: Int64;         // file size or stream position offset
83
    Written: Int64;
84
    Arg1: cardinal;
85
    Arg2: cardinal;
86
    Arg3: integer;            // 'older', stream cnt or from
87
    Check: cardinal;
88
  end;
89
  PZCallBackStruct = ^TZCallBackStruct;
90
 
91
//ALL interface structures BYTE ALIGNED
92
(* stream operation arg usage
93
   zacStIdentify,
94
//      IN BufP = name
95
      IN Number = number
96
     OUT ArgLL = size, ArgD = Date, ArgA = Attrs
97
   zacStCreate,
98
//      IN BufP = name
99
      IN Number = number
100
     OUT StrmP = stream
101
   zacStClose,
102
      IN Number = number
103
      IN StrmP = stream
104
     OUT StrmP = stream (= NULL)
105
   zacStPosition,
106
      IN Number = number
107
      IN StrmP = stream, ArgLL = offset, ArgI = from
108
     OUT ArgLL = position
109
   zacStRead,
110
      IN Number = number
111
      IN StrmP = stream, BufP = buf, ArgI = count
112
     OUT ArgI = bytes read
113
   zacStWrite
114
      IN Number = number
115
      IN StrmP = stream, BufP = buf, ArgI = count
116
     OUT ArgI = bytes written
117
*)
118
type
119
  TZStreamRec = packed record
120
    Caller:  Pointer;         // "self" reference of the Delphi form }
121
    Version: Longint;         // version no. of DLL }
122
    StrmP: pointer;           // pointer to 'tstream'
123
    Number: Integer;
124
    OpCode: integer;          // TZStreamActions
125
    BufP: pByte;              // pointer to stream src/dst or identifier
126
    ArgLL: Int64;             // file size or stream position offset
127
    ArgI: integer;            // stream cnt or from
128
    ArgD: cardinal;           // date
129
    ArgA: cardinal;           // attribs
130
    Check: cardinal;          // ZStream_Check;
131
  end;
132
  PZStreamRec = ^TZStreamRec;
133
 
134
 
135
(* Declare a function pointer type for the BCB/Delphi callback function, to
136
 * be called by the DLL to pass updated status info back to BCB/Delphi.*)
137
type
138
  TZFunctionPtrType = function(ZCallbackRec: PZCallBackStruct): Longint; STDCALL;
139
 
140
  TZStreamFunctionPtrType = function(ZStreamRec: PZStreamRec): Longint; STDCALL;
141
 
142
type
143
  PZSSArgs = ^TZSSArgs;
144
  TZSSArgs = packed record     // used stream-stream
145
    Method: Cardinal;         // low word = method, hi word nz=encrypt
146
    CRC: cardinal;            // IN init encrypt crc OUT crc
147
    Size: Int64;
148
    fSSInput: pointer;
149
    fSSOutput: pointer;
150
  end;
151
 
152
 (* These records are very critical.  Any changes in the order of items, the
153
    size of items, or modifying the number of items, may have disasterous
154
    results.  You have been warned! *)
155
const    
156
  DLLCOMMANDCHECK = $03070505;
157
  DLL_OPT_OpIsZip           = $0000001;
158
  DLL_OPT_OpIsDelete        = $0000002; // delete - not used?
159
  DLL_OPT_OpIsUnz           = $0000004;
160
  DLL_OPT_OpIsTest          = $0000008;
161
  DLL_OPT_CanWide           = $0000010;
162
  DLL_OPT_Quiet             = $0000020;
163
//  DLL_OPT_NoSkip            = $0000040; // skipping is fatal
164
  DLL_OPT_Update            = $0000080;
165
  DLL_OPT_Freshen           = $0000100;
166
  DLL_OPT_Directories       = $0000200; // extract directories
167
  DLL_OPT_Overwrite         = $0000400; // overwrite all
168
  DLL_OPT_NoDirEntries      = $0000800;
169
  DLL_OPT_JunkDir           = $0001000;
170
  DLL_OPT_Recurse           = $0002000;
171
  DLL_OPT_Grow              = $0004000;
172
//  DLL_OPT_Force             = $0008000; // Force to DOS 8.3
173
  DLL_OPT_Move              = $0010000;
174
  DLL_OPT_System            = $0020000;
175
  DLL_OPT_JunkSFX           = $0040000; // remove sfx stub
176
  DLL_OPT_LatestTime        = $0080000; // set zip to latest file
177
  DLL_OPT_ArchiveFilesOnly  = $0100000; // zip when archive bit set
178
  DLL_OPT_ResetArchiveBit   = $0200000; // reset the archive bit after successfull zip
179
  DLL_OPT_Versioning        = $0400000; // rename old version instead of replace
180
  DLL_OPT_HowToMove         = $0800000;
181
  DLL_OPT_NoPrecalc         = $1000000; // don't precalc crc when encrypt
182
  DLL_OPT_Encrypt           = $2000000; // General encrypt, if not superseded
183
  DLL_OPT_Volume            = $4000000;
184
  DLL_OPT_NTFSStamps        = $8000000; // Generate or use NTFS time stamps
185
 
186
type
187
  TDLLCommands = packed record
188
    fHandle: HWND;
189
    fCaller: Pointer;
190
    fVersion: Longint;
191
    ZCallbackFunc: TZFunctionPtrType;
192
    ZStreamFunc: TZStreamFunctionPtrType;
193
    fVerbosity: integer;
194
    fEncodedAs: Cardinal;               // Assume name encoded as (auto, raw, utf8, oem)
195
    fSS: PZSSArgs;         // used stream-stream   
196
    fFromPage: cardinal;      // country to use
197
    fOptions: cardinal;   // DLL_OPT_?
198
    fPwdReqCount: cardinal;
199
    fEncodeAs: cardinal;    // encode names as 
200
    fLevel: integer;                
201
    // General Date, if not superseded by FileData.fDate
202
    fDate: cardinal;    
203
    fNotUsed: array[0..3] of Cardinal;
204
    fCheck: cardinal;
205
  end;
206
  pDLLCommands = ^TDLLCommands;
207
 
208
  const
209
  ZPasswordFollows = '<';
210
  ZSwitchFollows = '|';
211
  ZForceNoRecurse = '|'; // leading
212
  ZForceRecurse = '>'; // leading
213
 
214
type
215
  TDLLExecFunc = function(Rec: pDLLCommands): Integer; STDCALL;
216
  TDLLVersionFunc = function: Integer; STDCALL;
217
  TDLLPrivVersionFunc = function: Integer; STDCALL;
218
  TAbortOperationFunc = function(Rec: Cardinal): Integer; STDCALL;
219
  TDLLPathFunc = function: pAnsiChar; STDCALL;
220
  TDLLBannerFunc = function: PAnsiChar; STDCALL;
221
  TDLLNameFunc = function(var buf; bufsiz: integer; wide: boolean): integer; STDCALL;
222
 
223
const
224
  _DZ_ERR_GOOD   = 0; // ZEN_OK
225
  _DZ_ERR_CANCELLED  = 1;
226
  _DZ_ERR_ABORT   = 2;
227
  _DZ_ERR_CALLBACK  = 3;
228
  _DZ_ERR_MEMORY   = 4;
229
  _DZ_ERR_STRUCT   = 5;
230
  _DZ_ERR_ERROR   = 6;
231
  _DZ_ERR_PASSWORD_FAIL  = 7;
232
  _DZ_ERR_PASSWORD_CANCEL = 8;
233
  _DZ_ERR_INVAL_ZIP      = 9 ; // ZEN_FORM
234
  _DZ_ERR_NO_CENTRAL     = 10;  // UEN_EOF01
235
  _DZ_ERR_ZIP_EOF        = 11;  // ZEN_EOF
236
  _DZ_ERR_ZIP_END        = 12;  // UEN_EOF02
237
  _DZ_ERR_ZIP_NOOPEN     = 13;
238
  _DZ_ERR_ZIP_MULTI      = 14;
239
  _DZ_ERR_NOT_FOUND      = 15;
240
  _DZ_ERR_LOGIC_ERROR    = 16;  // ZEN_LOGIC
241
  _DZ_ERR_NOTHING_TO_DO  = 17;  // ZEN_NONE
242
  _DZ_ERR_BAD_OPTIONS    = 18;  // ZEN_PARM
243
  _DZ_ERR_TEMP_FAILED    = 19;  // ZEN_TEMP
244
  _DZ_ERR_NO_FILE_OPEN   = 20;  // ZEN_OPEN
245
  _DZ_ERR_ERROR_READ     = 21;  // ZEN_READ
246
  _DZ_ERR_ERROR_CREATE   = 22;  // ZEN_CREAT
247
  _DZ_ERR_ERROR_WRITE    = 23;  // ZEN_WRITE
248
  _DZ_ERR_ERROR_SEEK     = 24;
249
  _DZ_ERR_EMPTY_ZIP      = 25;
250
  _DZ_ERR_INVAL_NAME     = 26;
251
  _DZ_ERR_GENERAL        = 27;
252
  _DZ_ERR_MISS           = 28;  // ZEN_MISS UEN_MISC03
253
  _DZ_ERR_WARNING        = 29;  // PK_WARN
254
  _DZ_ERR_ERROR_DELETE   = 30;  // PK_NODEL
255
  _DZ_ERR_FATAL_IMPORT   = 31;
256
  _DZ_ERR_SKIPPING       = 32;
257
  _DZ_ERR_LOCKED         = 33;
258
  _DZ_ERR_DENIED         = 34;
259
  _DZ_ERR_DUPNAME        = 35;
260
  _DZ_ERR_NOSKIP         = 36;
261
 
262
  _DZ_ERR_MAX          = 36;
263
 
264
//  DZ_ERR_SKIPPING       = 37;
265
//  DLLPARAMCHECK      = $07070505;
266
(*    Message code format
267
0FFF FFFF  LLLL LLLL   LLLL MTTT  EEEE EEEE  {31 .. 0}
268
F = file number (7 bits = 128 files)
269
L = line number (12 bits=4096 lines)
270
M = message instead of error string
271
T = type  (3 bits=8)
272
E = error/string code (8 bits = 256 errors)
273
*)
274
  DZM_Type_Mask = $700;
275
  DZM_General = $000;
276
  DZM_Error   = $600;   // 1 1 x (E... is identifier)
277
  DZM_Warning = $400;   // 1 0 x
278
  DZM_Trace   = $300; // 0 1 1
279
  DZM_Verbose = $100;   // 0 0 1
280
  DZM_Message = $200; // 0 1 0 (E... is identifier)
281
 
282
  DZM_MessageBit = $800;    // mask for message bit
283
 
284
  // callback return values
285
//  CALLBACK_FALSE     =      0;
286
  CALLBACK_UNHANDLED =      0;
287
  CALLBACK_TRUE      =      1;
288
  CALLBACK_2         =      2;
289
  CALLBACK_3         =      3;
290
  CALLBACK_4         =      4;
291
  CALLBACK_IGNORED   =     -1;  // invalid ActionCode
292
  CALLBACK_CANCEL    =     -2;  // user cancel
293
  CALLBACK_ABORT     =     -3;
294
  CALLBACK_EXCEPTION =     -4;  // handled exception
295
  CALLBACK_ERROR     =     -5;  // unknown error
296
 
297
const
298
//  NEW_ENCODING_OS  = 0;
299
//  NEW_ENCODING_VER = 25;//30;
300
//  NEW_ENCODING_VEM = 25;//$001E;
301
  OUR_VEM = 30;
302
  Def_VER = 20;
303
 
304
const
305
  DelZipDLL_Name = 'DelZip190.dll';
306
  DelZipDLL_Execfunc = 'DZ_Exec';
307
  DelZipDLL_Abortfunc = 'DZ_Abort';
308
  DelZipDLL_Versfunc = 'DZ_Version';
309
  DelZipDLL_Privfunc = 'DZ_PrivVersion';
310
  DelZipDLL_Pathfunc = 'DZ_Path';    
311
  DelZipDLL_Bannerfunc = 'DZ_Banner';
312
  DelZipDLL_Namefunc = 'DZ_Name';
313
(*
314
// 'static' loaded dll functions
315
function DZ_Exec(C: pDLLCommands): Integer; STDCALL; EXTERNAL DelZipDLL_Name;
316
function DZ_Abort(C: Cardinal): Integer; STDCALL; EXTERNAL DelZipDLL_Name;
317
function DZ_Version: Integer; STDCALL; EXTERNAL DelZipDLL_Name;
318
function DZ_PrivVersion: Integer; STDCALL; EXTERNAL DelZipDLL_Name;
319
function DZ_Path: pChar; STDCALL; EXTERNAL DelZipDLL_Name;      
320
function DZ_Banner: pChar; STDCALL; EXTERNAL DelZipDLL_Name;
321
 *)
322
 
323
implementation
324
 
325
end.
326