home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 15 / CD_ASCQ_15_070894.iso / vrac / 4utils83.zip / SCANZIPF.PAS < prev    next >
Pascal/Delphi Source File  |  1994-04-28  |  9KB  |  270 lines

  1. UNIT ScanZIPFiles;
  2. {$V-}
  3. (* ----------------------------------------------------------------------
  4.    Part of 4DESC - A Simple 4DOS File Description Editor
  5.        and 4FF   - 4DOS File Finder
  6.  
  7.    (c) 1992, 1993 Copyright by David Frey,
  8.                                Urdorferstrasse 30
  9.                                8952 Schlieren ZH
  10.                                Switzerland
  11.  
  12.    DISCLAIMER: This unit is freeware: you are allowed to use, copy
  13.                and change it free of charge, but you may not sell or hire
  14.                this part of 4DESC. The copyright remains in our hands.
  15.  
  16.                If you make any (considerable) changes to the source code,
  17.                please let us know. (send a copy or a listing).
  18.                We would like to see what you have done.
  19.  
  20.                We, David Frey and Tom Bowden, the authors, provide absolutely
  21.                no warranty of any kind. The user of this software takes the
  22.                entire risk of damages, failures, data losses or other
  23.                incidents.
  24.  
  25.  
  26.        Code created using Turbo Pascal 6.0 (c) Borland International 1990
  27.  
  28.    This unit provides the extraction of file names in .ZIP files.
  29.  
  30.    ----------------------------------------------------------------------- *)
  31.  
  32. INTERFACE USES Dos, Globals;
  33.  
  34. PROCEDURE SearchInZIPFile(FileSpec: FileSpecArrayType; FileSpecs: BYTE;
  35.                           VAR Dir: PathStr; VAR zipsearch: SearchRec);
  36. PROCEDURE ShowCompZIPFileData(VAR search,zipsearch: SearchRec;VAR Path: PathStr;
  37.                               csize: LONGINT);
  38. (* PROCEDURE ShowCompZIPFileData(VAR search,zipsearch: SearchRec;VAR Path: PathStr;
  39.                               csize: LONGINT;desc: DescStr); *)
  40.  
  41. VAR OldZIPFileName: PathStr;
  42.  
  43. IMPLEMENTATION USES Objects, Drivers, StringDateHandling;
  44.  
  45. PROCEDURE SearchInZIPFile(FileSpec: FileSpecArrayType; FileSpecs: BYTE;
  46.                           VAR Dir: PathStr; VAR zipsearch: SearchRec);
  47.  
  48. CONST StartOfCentralDir = $02014b50;
  49.       StartOfLocalHeader= $04034b50;
  50.       EndOfCentralDir   = $06054b50;
  51.  
  52. VAR i,l,cl,el  : WORD;
  53.     k,Dummy    : BYTE;
  54.     ZIPFileName: NameExtStr;
  55.     sig        : LONGINT;
  56.     Desc       : DescStr;
  57.  
  58. BEGIN (* SearchInZIPFile *)
  59.  Assign(f,zipsearch.Name); Reset(f,1);
  60.  
  61.  BlockRead(f,Buffer^,BufSize,BytesRead);
  62.  BufPtr := 0; FilePtr := 0;
  63.  
  64. (* REPEAT
  65.   sig := LONGINT(ReadByte) SHL 24 + LONGINT(ReadByte) SHL 16+
  66.          LONGINT(ReadByte) SHL  8 + ReadByte;
  67.   IF BufPtr > BufSize THEN
  68.    BEGIN
  69.     BlockRead(f,Buffer^,BufSize,BytesRead); BufPtr := 0;
  70.    END;
  71.  UNTIL (sig = StartOfCentralDir) OR
  72.        (sig = EndOfCentralDir) OR (BufPtr > BytesRead); *)
  73.  
  74.  REPEAT
  75.   REPEAT
  76.    sig := LONGINT(ReadByte) SHL 24 + LONGINT(ReadByte) SHL 16+
  77.           LONGINT(ReadByte) SHL  8 + ReadByte;
  78.    IF BufPtr > BufSize THEN
  79.     BEGIN
  80.      BlockRead(f,Buffer^,BufSize,BytesRead); BufPtr := 0;
  81.     END;
  82.   UNTIL (sig = StartOfLocalHeader (* StartOfCentralDir *) ) OR
  83.         (sig = StartOfCentralDir  (* EndOfCentralDir *) )   OR
  84.         (BufPtr > BytesRead);
  85.  
  86.   IF BufPtr > BytesRead THEN
  87.    BEGIN
  88.     WriteLn(output,'ZIP file error: local file header signature missing!');
  89.     WriteLn(output);
  90.    END;
  91.  
  92.   IF sig = StartOfLocalHeader (* StartCentralDir *) THEN
  93.    BEGIN
  94.     FOR i := 1 TO 6 DO dummy := ReadByte;
  95.     (* version needed to extract    2 bytes
  96.        version made by            2 bytes // not on local file header
  97.        general purpose bit flag            2 bytes
  98.        compression method        2 bytes *)
  99.  
  100.     Search.time := LONGINT(ReadByte) SHL 24 + LONGINT(ReadByte) SHL 16 + LONGINT(ReadByte) SHL 8 + ReadByte;
  101.     (* last mod file time               2 bytes,
  102.        last mod file date               2 bytes *)
  103.  
  104.     FOR i := 1 TO 4 DO dummy := ReadByte;
  105.     (* crc-32               4 bytes *)
  106.  
  107.     csize       := LONGINT(ReadByte) SHL 24 + LONGINT(ReadByte) SHL 16 + LONGINT(ReadByte) SHL 8 + ReadByte;
  108.     (* compressed size                4 bytes *)
  109.  
  110.     Search.size := LONGINT(ReadByte) SHL 24 + LONGINT(ReadByte) SHL 16 + LONGINT(ReadByte) SHL 8 + ReadByte;
  111.     (* uncompressed size        4 bytes *)
  112.  
  113.     l := ReadByte SHL 8+ReadByte;
  114.     (* filename length                2 bytes *)
  115.  
  116.     el:= ReadByte SHL 8+ReadByte;
  117.     (* extra field length        2 bytes *)
  118.  
  119. (*  cl:= ReadByte SHL 8+ReadByte; *)
  120.     (* file comment length        2 bytes *)
  121.  
  122. (*  FOR i := 1 TO 4 DO dummy := ReadByte; *)
  123.     (* disk number start        2 bytes
  124.        interrnal file attributes    2 bytes *)
  125.  
  126. (*  Search.Attr := ReadByte; *)
  127.     (* external file attributes            4 bytes , first byte *)
  128.  
  129. (*  FOR i := 1 TO 7 DO dummy := ReadByte; *)
  130.     (* relative offset of local header    4 bytes *)
  131.  
  132.     WITH Search DO
  133.      BEGIN
  134.       name := '';
  135.       FOR i := 1 TO l DO
  136.        IF i <= 12 THEN name := name+DownCase(Chr(ReadByte))
  137.                   ELSE dummy:= ReadByte;
  138.      END;
  139.     (* filename (variable size) *)
  140.  
  141.     FOR i := 1 TO el DO dummy := ReadByte;
  142.     (* extra field (variable size) *)
  143.  
  144. (*    Desc := '';
  145.     FOR i := 1 TO cl DO Desc := Desc + Chr(ReadByte); *)
  146.     (* file comment (variable size) *)
  147.  
  148.     FOR k := 1 TO FileSpecs DO
  149.      BEGIN
  150.       FSplit(FileSpec[k],Path,name,ext);
  151.       WHILE Length(name) < 8 DO name := name+' ';
  152.       IF Ext = '' THEN Ext := '.   '
  153.       ELSE
  154.        WHILE Length(ext)      < 4 DO ext := ext+' ';
  155.  
  156.       i := Pos('*',name);
  157.       IF  i > 0 THEN
  158.        WHILE i <= 8 DO
  159.         BEGIN
  160.          name[i] := '?'; INC(i);
  161.         END;
  162.  
  163.       i := Pos('*',ext);
  164.       IF  i > 0 THEN
  165.        WHILE i <= 4 DO
  166.         BEGIN
  167.          ext[i] := '?'; INC(i);
  168.         END;
  169.       FileSpec[k] := Path+name+ext;
  170.  
  171.       FSplit(Search.Name,Path,name,ext);
  172.       WHILE Length(name) < 8 DO name := name +' ';
  173.       IF Ext = '' THEN Ext := '.   '
  174.       ELSE
  175.        WHILE Length(ext)      < 4 DO ext := ext+' ';
  176.       ZIPFileName:= Path+name+ext;
  177.  
  178.       i := 1;
  179.       WHILE ((FileSpec[k][i] = '?') OR (FileSpec[k][i] = ZIPFileName[i])) AND
  180.              (i<12) DO
  181.        INC(i);
  182.  
  183.       IF ((ExactAttr AND (Search.Attr = Attr)) OR (NOT ExactAttr)) AND
  184.           (FileSpec[k][i] = '?') OR (FileSpec[k][i] = ZIPFileName[i]) THEN
  185.        ShowCompZIPFileData(search,zipsearch,Dir,csize);
  186. (*       ShowCompZIPFileData(search,zipsearch,Dir,csize,Desc); *)
  187.      END;
  188.  
  189.     INC(BufPtr,csize); INC(FilePtr,csize);
  190.     Seek(f,FilePtr);
  191.     IF BufPtr > BufSize THEN
  192.      BEGIN
  193.       BlockRead(f,Buffer^,BufSize,BytesRead); BufPtr := 0;
  194.      END;
  195.    END;
  196.  UNTIL (BufPtr > BytesRead) OR (sig = StartOfCentralDir);
  197.  
  198.  Close(f);
  199. END; (* SearchInZIPFile *)
  200.  
  201. (* PROCEDURE ShowCompZIPFileData(VAR search,zipsearch: SearchRec;VAR Path: PathStr;
  202.                               csize: LONGINT;desc: DescStr); *)
  203. PROCEDURE ShowCompZIPFileData(VAR search,zipsearch: SearchRec;VAR Path: PathStr;
  204.                               csize: LONGINT);
  205.  
  206. VAR i       : INTEGER;
  207.  
  208. BEGIN
  209.  IF NOT BareOutput THEN
  210.   BEGIN
  211.    IF FileCount = 0 THEN
  212.     BEGIN
  213.      WriteLn(Output); IF DoPage THEN TestForMoreMsg;
  214.      WriteLn(Output,Path); IF DoPage THEN TestForMoreMsg;
  215.     END;
  216.  
  217.    IF zipsearch.Name <> OldZIPFileName THEN
  218.     BEGIN
  219.      DownString(zipsearch.Name); OldZIPFileName := zipsearch.Name;
  220.  
  221.      InfoArray[0] := @zipsearch.Name;
  222.  
  223.      SizeStr := FormattedLongIntStr(zipsearch.Size,8);
  224.      InfoArray[1] := @SizeStr;
  225.  
  226.      UnpackTime(zipsearch.Time,DateRec);
  227.      Date := FormDate(DateRec); Time := FormTime(DateRec);
  228.      InfoArray[2] := @Date;
  229.      InfoArray[3] := @Time;
  230.  
  231.      AttrStr := '....';
  232.      IF zipsearch.Attr AND ReadOnly = ReadOnly THEN AttrStr[1] := 'r';
  233.      IF zipsearch.Attr AND Hidden   = Hidden   THEN AttrStr[2] := 'h';
  234.      IF zipsearch.Attr AND SysFile  = SysFile  THEN AttrStr[3] := 's';
  235.      IF zipsearch.Attr AND Archive  = Archive  THEN AttrStr[4] := 'a';
  236.      InfoArray[4] := @AttrStr;
  237.  
  238.      FormatStr(s,'(%-12s   %8s '+DateTempl+' '+TimeTempl+' %4s)',InfoArray);
  239.      WriteLn(Output,s); IF DoPage THEN TestForMoreMsg;
  240.     END;
  241.  
  242.    InfoArray[0] := @search.Name;
  243.  
  244.    SizeStr := FormattedLongIntStr(search.Size,8);
  245.    InfoArray[1] := @SizeStr;
  246.  
  247.    UnpackTime(search.Time,DateRec);
  248.    Date := FormDate(DateRec); Time := FormTime(DateRec);
  249.    InfoArray[2] := @Date;
  250.    InfoArray[3] := @Time;
  251.  
  252. (*   AttrStr := '----';
  253.    IF Search.Attr AND Archive  = Archive  THEN AttrStr[1] := 'a';
  254.    IF Search.Attr AND Hidden   = Hidden   THEN AttrStr[2] := 'h';
  255.    IF Search.Attr AND SysFile  = SysFile  THEN AttrStr[3] := 's';
  256.    IF Search.Attr AND ReadOnly = ReadOnly THEN AttrStr[4] := 'o'
  257.                                           ELSE AttrStr[4] := 'w';
  258.    InfoArray[4] := LONGINT(@AttrStr);
  259.    InfoArray[5] := LONGINT(@Desc); *)
  260.  
  261. (*   FormatStr(s,'+ %-12s   %8s '+DateTempl+' '+TimeTempl+' %4s %-s',InfoArray); *)
  262.    FormatStr(s,'+ %-12s  %8s '+DateTempl+' '+TimeTempl,InfoArray);
  263.    WriteLn(Output,s); IF DoPage THEN TestForMoreMsg;
  264.  
  265.    INC(TotalSize,csize); INC(DirSize,csize);
  266.    INC(TotalFileCount);  INC(FileCount);
  267.   END;
  268. END; (* ShowFileData *)
  269.  
  270. END.