unzipdll.pas 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. {
  2. $Id$
  3. }
  4. unit UnzipDLL;
  5. {$Cdecl+,AlignRec-,OrgName+}
  6. interface
  7. const
  8. {$IFDEF OS2}
  9. AllFiles: string [1] = '*';
  10. {$ELSE}
  11. AllFiles: string [3] = '*.*';
  12. {$ENDIF}
  13. type
  14. TArgV = array [0..1024] of PChar;
  15. PArgV = ^TArgV;
  16. TCharArray = array [1..1024*1024] of char;
  17. PCharArray = ^TCharArray;
  18. function FileUnzipEx (SourceZipFile, TargetDirectory,
  19. FileSpecs: PChar): integer;
  20. implementation
  21. uses
  22. {$IFDEF OS2}
  23. {$IFDEF FPC}
  24. DosCalls,
  25. {$ELSE FPC}
  26. {$IFDEF VirtualPascal}
  27. OS2Base,
  28. {$ELSE VirtualPascal}
  29. BseDos,
  30. {$ENDIF VirtualPascal}
  31. {$ENDIF FPC}
  32. {$ENDIF OS2}
  33. Dos;
  34. type
  35. UzpMainFunc = function (ArgC: longint; var ArgV: TArgV): longint;
  36. const
  37. {$IFDEF OS2}
  38. LibPath = 'LIBPATH';
  39. {$ELSE}
  40. LibPath = 'PATH';
  41. {$ENDIF}
  42. UzpMainOrd = 4;
  43. DLLName: string [8] = 'UNZIP32'#0;
  44. UzpMain: UzpMainFunc = nil;
  45. QuiteOpt: array [1..4] of char = '-qq'#0;
  46. OverOpt: array [1..3] of char = '-o'#0;
  47. CaseInsOpt: array [1..3] of char = '-C'#0;
  48. ExDirOpt: array [1..3] of char = '-d'#0;
  49. OptCount = 4;
  50. var
  51. DLLHandle: longint;
  52. OldExit: pointer;
  53. function DLLInit: boolean;
  54. var
  55. ErrPath: array [0..259] of char;
  56. DLLPath: PathStr;
  57. Dir: DirStr;
  58. Name: NameStr;
  59. Ext: ExtStr;
  60. begin
  61. DLLInit := false;
  62. FSplit (FExpand (ParamStr (0)), Dir, Name, Ext);
  63. DLLPath := Dir + DLLName;
  64. Insert ('.DLL', DLLPath, byte (DLLPath [0]));
  65. if (DosLoadModule (@ErrPath, SizeOf (ErrPath), @DLLPath [1], DLLHandle) <> 0)
  66. and (DosLoadModule (@ErrPath, SizeOf (ErrPath), @DLLName [1], DLLHandle) <> 0)
  67. then
  68. begin
  69. if ErrPath [0] <> #0 then
  70. begin
  71. Write (#13#10'Error while loading module ');
  72. WriteLn (PChar (@ErrPath));
  73. end;
  74. end else DLLInit := DosQueryProcAddr (DLLHandle, UzpMainOrd, nil, @UzpMain) = 0;
  75. end;
  76. procedure NewExit;
  77. begin
  78. ExitProc := OldExit;
  79. DosFreeModule (DLLHandle);
  80. end;
  81. function FileUnzipEx;
  82. var
  83. I, FCount, ArgC: longint;
  84. ArgV: TArgV;
  85. P: PChar;
  86. StrLen: array [Succ (OptCount)..1024] of longint;
  87. begin
  88. ArgV [0] := @DLLName;
  89. ArgV [1] := @QuiteOpt;
  90. ArgV [2] := @OverOpt;
  91. ArgV [3] := @CaseInsOpt;
  92. ArgV [4] := SourceZipFile;
  93. FCount := 0;
  94. if FileSpecs^ <> #0 then
  95. begin
  96. P := FileSpecs;
  97. I := 0;
  98. repeat
  99. case FileSpecs^ of
  100. '"': begin
  101. Inc (FileSpecs);
  102. repeat Inc (I) until (FileSpecs^ = '"') or (FileSpecs^ = #0);
  103. Inc (FileSpecs);
  104. Inc (I);
  105. end;
  106. '''': begin
  107. Inc (FileSpecs);
  108. repeat Inc (I) until (FileSpecs^ = '''') or (FileSpecs^ = #0);
  109. Inc (FileSpecs);
  110. Inc (I);
  111. end;
  112. #0, ' ', #9: begin
  113. Inc (I);
  114. Inc (FCount);
  115. GetMem (ArgV [OptCount + FCount], I);
  116. Move (P^, ArgV [OptCount + FCount]^, Pred (I));
  117. PCharArray (ArgV [OptCount + FCount])^ [I] := #0;
  118. StrLen [OptCount + FCount] := I;
  119. while (FileSpecs^ = #9) or (FileSpecs^ = ' ') do Inc (FileSpecs);
  120. P := FileSpecs;
  121. I := 0;
  122. end;
  123. else
  124. begin
  125. Inc (I);
  126. Inc (FileSpecs);
  127. end;
  128. end;
  129. until (FileSpecs^ = #0) and (I = 0);
  130. end else
  131. begin
  132. FCount := 1;
  133. StrLen [OptCount + FCount] := Succ (byte (AllFiles [0]));
  134. GetMem (ArgV [OptCount + FCount], StrLen [OptCount + FCount]);
  135. Move (AllFiles [1], ArgV [OptCount + FCount]^, StrLen [OptCount + FCount]);
  136. end;
  137. ArgC := Succ (FCount + OptCount);
  138. ArgV [ArgC] := @ExDirOpt;
  139. Inc (ArgC);
  140. ArgV [ArgC] := TargetDirectory;
  141. Inc (ArgC);
  142. ArgV [ArgC] := @ExDirOpt [3]; (* contains #0 *)
  143. if UzpMain (ArgC, ArgV) <> 0 then FileUnzipEx := 0 else FileUnzipEx := FCount;
  144. for I := 1 to FCount do FreeMem (ArgV [I + OptCount], StrLen [I + OptCount]);
  145. end;
  146. begin
  147. if DLLInit then
  148. begin
  149. OldExit := ExitProc;
  150. ExitProc := @NewExit;
  151. end else
  152. begin
  153. WriteLn (#13#10'Dynamic library UNZIP32.DLL from InfoZip is needed to install.');
  154. WriteLn ('This library could not be found on your system, however.');
  155. WriteLn ('Please, download the library, either from the location where you found');
  156. WriteLn ('this installer, or from any FTP archive carrying InfoZip programs.');
  157. WriteLn ('If you have this DLL on your disk, please, check your configuration (' + LIBPATH + ').');
  158. Halt (255);
  159. end;
  160. end.
  161. {
  162. $Log$
  163. Revision 1.2 1999-06-10 07:28:29 hajny
  164. * compilable with TP again
  165. Revision 1.1 1999/02/19 16:45:26 peter
  166. * moved to fpinst/ directory
  167. + makefile
  168. }