ZIPINTER.PAS
Upload User: qxf5203344
Upload Date: 2021-08-05
Package Size: 101k
Code Size: 6k
Development Platform:

Delphi

  1. UNIT ZipInter;
  2. {
  3. Interface to the UNZIP DLL
  4.   * original version by Christian Ghisler
  5.   * extended by Dr Abimbola Olowofoyeku (The African Chief)
  6.   * amended for Win32 by the African Chief
  7.  Homepage: http://ourworld.compuserve.com/homepages/African_Chief
  8. }
  9. {$i unzip.inc}
  10. INTERFACE
  11. USES
  12. WinTypes,
  13. WinProcs,
  14. Ziptypes;
  15. {*********************************************************************}
  16. {*********************************************************************}
  17. {************** The African Chief's functions ************************}
  18. {*********************************************************************}
  19. {*********************************************************************}
  20. FUNCTION FileUnzip
  21. ( SourceZipFile, TargetDirectory, FileSpecs : pChar;
  22.  Report : UnzipReportProc;Question : UnzipQuestionProc ) : integer;
  23. {$ifdef Win32}STDCALL;{$endif}
  24. FUNCTION FileUnzipEx ( SourceZipFile, TargetDirectory, FileSpecs : pChar ) : integer;
  25. {$ifdef Win32}STDCALL;{$endif}
  26. FUNCTION Viewzip ( SourceZipFile, FileSpecs : pChar; Report : UnzipReportProc ) : integer;
  27. {$ifdef Win32}STDCALL;{$endif}
  28. FUNCTION UnZipSize ( SourceZipFile : pChar;VAR Compressed : Longint ) : longint;
  29. {$ifdef Win32}STDCALL;{$endif}
  30. FUNCTION  SetUnZipReportProc ( aProc : UnzipReportProc ) : Pointer;
  31. {$ifdef Win32}STDCALL;{$endif}
  32. FUNCTION  SetUnZipQuestionProc ( aProc : UnzipQuestionProc ) : Pointer;
  33. {$ifdef Win32}STDCALL;{$endif}
  34. PROCEDURE ChfUnzip_Init;
  35. {$ifdef Win32}STDCALL;{$endif}
  36. {*********************************************************************}
  37. {*********************************************************************}
  38. {*************************** original functions **********************}
  39. {*********************************************************************}
  40. {*********************************************************************}
  41. {******************* DLL version *************************************}
  42. FUNCTION GetUnzipDllVersion : word;
  43. {$ifdef Win32}STDCALL;{$endif}
  44. {Hi byte=number before period, Lo byte=number after period}
  45. {Later versions will be downward compatible}
  46. {******************** ZIP central directory access *******************}
  47. {The following 3 functions can be called in a loop to retreive all
  48.  the files in the given zip file.
  49.  Use these functions similar to findfirst and findnext:
  50.  Example:
  51.  var r:tziprec;
  52.  rc:=GetFirstInZip(zipname,r);
  53.  while rc=zip_ok do
  54.    DosomethingWithData(r);
  55.    rc:=GetNextInZip(r);
  56.  end;
  57.  closezipfile(r);
  58.  case rc of
  59.    zip_FileError:messagebox(hwindow,'Error reading ZIP file!',zipname,mb_ok);
  60.    zip_InternalError:messagebox(hwindow,'Internal error in ZIP file!',zipname,mb_ok);
  61.  end;
  62. }
  63. FUNCTION GetFirstInZip ( zipfilename : pchar;VAR zprec : tZipRec ) : integer;
  64. {$ifdef Win32}STDCALL;{$endif}
  65. {zipfilename: filename of zip file}
  66. {zprec:       record, will be filled with zipfile data}
  67. FUNCTION GetNextInZip ( VAR Zprec : tZiprec ) : integer;
  68. {$ifdef Win32}STDCALL;{$endif}
  69. {zprec:       record, will be filled with zipfile data,
  70.  do not change the 'internal' field received from previous calls!}
  71. PROCEDURE CloseZipFile ( VAR Zprec : tZiprec );
  72. {$ifdef Win32}STDCALL;{$endif}
  73. {Call after last GetNextInZip call to free buffer}
  74. {********************* Test if file is a ZIP file ********************}
  75. FUNCTION isZip ( filename : pchar ) : boolean;
  76. {$ifdef Win32}STDCALL;{$endif}
  77. {Tests if given file is a zip file (only test for PK#3#4 at the beginning)}
  78. {***************** Get Unzip Methods supported by DLL ****************}
  79. {Currently (version 1.0) these are stored (0), shrunk (1),
  80.                             imploded (6) and deflated (8)}
  81. FUNCTION GetSupportedMethods : longint;
  82. {$ifdef Win32}STDCALL;{$endif}
  83. {Method 0 supported -> bit 0 = 1,
  84.  Method 8 supported -> bit 8 = 1,
  85.  etc.}
  86. {********************* unzip a file from ZIP-file ********************}
  87. FUNCTION unzipfile ( in_name : pchar;out_name : pchar;offset : longint;
  88.   hFileAction : hwnd;cm_index : integer ) : integer;
  89. {$ifdef Win32}STDCALL;{$endif}
  90. {usage:
  91.  in_name:      name of zip file with full path
  92.  out_name:     desired name for out file
  93.  offset:       header position of desired file in zipfile, found in tZiprec
  94.  hFileAction:  handle to dialog box showing advance of decompression (optional),
  95.                or zero when only keyboard shall be checked
  96.  cm_index:     - if hfileaction<>0 : notification code sent in a wm_command
  97.                  message to the dialog to update percent-bar
  98.                - if hfileaction=0  : virtual key code of key the user must press
  99.                  to interrupt unzipping, i.e. vk_escape
  100.  Return value: one of the above unzip_xxx codes
  101.  Example for handling the cm_index message in a progress dialog:
  102.  unzipfile(......,cm_showpercent);
  103.  ...
  104.  procedure TFileActionDialog.wmcommand(var msg:tmessage);
  105.  var ppercent:^word;
  106.  begin
  107.    TDialog.WMCommand(msg);
  108.    if msg.wparam=cm_showpercent then begin
  109.      ppercent:=pointer(lparam);
  110.      if ppercent<>nil then begin
  111.        if (ppercent^>=0) and (ppercent^<=100) then
  112.          SetProgressBar(ppercent^);
  113.        if UserPressedAbort then
  114.          ppercent^:=$ffff
  115.        else
  116.          ppercent^:=0;
  117.        end;
  118.      end;
  119.    end;
  120.  end;
  121. }
  122. IMPLEMENTATION
  123. CONST
  124. DllName = {$ifdef Win32}'UNZIPDLL.DLL'{$else}'UNZIPDLL'{$endif Win32};
  125. FUNCTION  GetUnzipDllVersion;  external DllName index 1;
  126. FUNCTION  GetFirstInZip;       external DllName index 2;
  127. FUNCTION  GetNextInZip;        external DllName index 3;
  128. PROCEDURE CloseZipFile;        external DllName index 4;
  129. FUNCTION  IsZip;               external DllName index 5;
  130. FUNCTION  GetSupportedMethods; external DllName index 6;
  131. FUNCTION  UnzipFile;           external DllName index 7;
  132. {The Chief!}
  133. FUNCTION  FileUnzip;           external DllName index 8;
  134. FUNCTION  ViewZip;             external DllName index 9;
  135. FUNCTION  UnZipSize;           external DllName index 10;
  136. FUNCTION  SetUnZipReportProc;  external DllName index 11;
  137. FUNCTION  SetUnZipQuestionProc;external DllName index 12;
  138. FUNCTION  FileUnzipEx;         external DllName index 13;
  139. PROCEDURE ChfUnzip_Init;       external DllName index 14;
  140. END.