6
{$Cdecl+,AlignRec-,OrgName+}
19
UnzipErr: longint = 0;
22
TArgV = array [0..1023] of PChar;
24
TCharArray = array [1..1024*1024] of char;
25
PCharArray = ^TCharArray;
26
TFileUnzipEx = function (SourceZipFile, TargetDirectory,
27
FileSpecs: PChar): integer;
29
function DllFileUnzipEx (SourceZipFile, TargetDirectory,
30
FileSpecs: PChar): integer;
33
FileUnzipEx: TFileUnzipEx = @DllFileUnzipEx;
35
(* Returns non-zero result on success. *)
44
{$IFDEF VirtualPascal}
48
{$ENDIF VirtualPascal}
58
UzpMainFunc = function (ArgC: longint; var ArgV: TArgV): longint; cdecl;
62
AllFiles: string [1] = '*';
65
AllFiles: string [3] = '*.*';
74
DLLName: string [8] = 'UNZIP32'#0;
75
UzpMain: UzpMainFunc = nil;
76
QuietOpt: array [1..4] of char = '-qq'#0;
77
OverOpt: array [1..3] of char = '-o'#0;
78
CaseInsOpt: array [1..3] of char = '-C'#0;
79
ExDirOpt: array [1..3] of char = '-d'#0;
87
function DLLInit: boolean;
90
ErrPath: array [0..259] of char;
98
FSplit (FExpand (ParamStr (0)), Dir, Name, Ext);
99
DLLPath := Dir + DLLName;
100
Insert ('.DLL', DLLPath, byte (DLLPath [0]));
102
if (DosLoadModule (@ErrPath, SizeOf (ErrPath), @DLLPath [1], DLLHandle) <> 0)
103
and (DosLoadModule (@ErrPath, SizeOf (ErrPath), @DLLName [1], DLLHandle) <> 0)
106
if ErrPath [0] <> #0 then
108
Write (#13#10'Error while loading module ');
109
WriteLn (PChar (@ErrPath));
112
end else DLLInit := DosQueryProcAddr (DLLHandle, UzpMainOrd, nil, pointer (UzpMain)) = 0;
114
end else DLLInit := DosQueryProcAddr (DLLHandle, UzpMainOrd, nil, @UzpMain) = 0;
118
DLLHandle := LoadLibrary (@DLLPath [1]);
119
if DLLHandle = 0 then DLLHandle := LoadLibrary (@DLLName [1]);
120
if DLLHandle = 0 then WriteLn (#13#10'Error while loading DLL.') else
122
(* UzpMain := UzpMainFunc (GetProcAddress (DLLHandle, 'UzpMain'));
124
UzpMain := UzpMainFunc (GetProcAddress (DLLHandle, 'Unz_Unzip'));
125
DLLInit := Assigned (UzpMain);
135
DosFreeModule (DLLHandle);
138
FreeLibrary (DLLHandle);
143
function DllFileUnzipEx (SourceZipFile, TargetDirectory,
144
FileSpecs: PChar): integer;
146
I, FCount, ArgC: longint;
149
StrLen: array [Succ (OptCount)..1023] of longint;
151
ArgV [0] := @DLLName;
152
ArgV [1] := @QuietOpt;
153
ArgV [2] := @OverOpt;
154
ArgV [3] := @CaseInsOpt;
155
ArgV [4] := SourceZipFile;
157
if FileSpecs^ <> #0 then
165
repeat Inc (I) until (FileSpecs^ = '"') or (FileSpecs^ = #0);
171
repeat Inc (I) until (FileSpecs^ = '''') or (FileSpecs^ = #0);
178
GetMem (ArgV [OptCount + FCount], I);
179
Move (P^, ArgV [OptCount + FCount]^, Pred (I));
180
PCharArray (ArgV [OptCount + FCount])^ [I] := #0;
181
StrLen [OptCount + FCount] := I;
182
while (FileSpecs^ = #9) or (FileSpecs^ = ' ') do Inc (FileSpecs);
192
until (FileSpecs^ = #0) and (I = 0);
196
StrLen [OptCount + FCount] := Succ (byte (AllFiles [0]));
197
GetMem (ArgV [OptCount + FCount], StrLen [OptCount + FCount]);
198
Move (AllFiles [1], ArgV [OptCount + FCount]^, StrLen [OptCount + FCount]);
200
ArgC := Succ (FCount + OptCount);
201
ArgV [ArgC] := @ExDirOpt;
203
ArgV [ArgC] := TargetDirectory;
205
ArgV [ArgC] := @ExDirOpt [3]; (* contains #0 *)
206
UnzipErr := UzpMain (ArgC, ArgV);
207
if UnzipErr <> 0 then DllFileUnzipEx := 0 else DllFileUnzipEx := FCount;
208
for I := 1 to FCount do FreeMem (ArgV [I + OptCount], StrLen [I + OptCount]);
213
if os_Mode <> osOS2 then
214
FileUnzipEx := TFileUnzipEx (@Unzip.FileUnzipEx)
220
ExitProc := @NewExit;
221
if GetEnv ('TZ') = '' then
223
WriteLn (#13#10'TZ variable was not found in your environment.');
224
WriteLn ('This variable is necessary for setting correct date/time of unpacked files.');
225
WriteLn ('Please, add it to your environment and restart this program afterwards.');
230
WriteLn (#13#10'Dynamic library UNZIP32.DLL from InfoZip is needed to unpack archives.');
231
WriteLn ('This library could not be found on your system, however.');
232
WriteLn ('Please, download the library, either from the location where you found');
233
WriteLn ('this package, or from any FTP archive carrying InfoZip programs.');
234
WriteLn ('If you already have this DLL, please, check your configuration (' + LibPath + ').');
235
WriteLn (#13#10'If you want to try unpacking the files with internal unpacking routine,');
236
WriteLn ('answer the following question with Y. However, this might not work correctly');
237
WriteLn ('under some conditions (e.g. for long names and drives not supporting them).');
238
Write (#13#10'Do you want to continue now (y/N)? ');
240
if UpCase (C) = 'Y' then FileUnzipEx := TFileUnzipEx (@Unzip.FileUnzipEx) else Halt (255);