unzipdll.pas 4.4 KB

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