'----------------------------[ ZIP Viewer ]-------------------------------
' No frills .ZIP Viewer for PB by William Yu (12-03-97)  Public Domain.
' With help from: Steve Wierenga (his Pascal code to be precise).
'
' If you're wondering how I got the Date/Time thing to work, check this:
'
'   bits     field              It's just one long 32-bit number
'   ----     -----              Pretty cool for only 4 bytes worth.
'   0-5   =  seconds
'   6-11  =  minutes
'   12-16 =  hours
'   17-21 =  days
'   22-25 =  months
'   26-31 =  years
'
'-------------------------------------------------------------------------
' Signature
' Zip File Header
' Not sure
' Compression type
' Took a while to figure out
' Not sure
".ZIP Viewer (Public Domain) by William Yu, with help from Steve Wierenga"' View the ZIP File
' We don't need the upper 2 bytes anymore.
' Works both ways.
"""Usage: ZIPVIEW [Path:\]filename.ZIP
    EXIT SUB
  END IF
 
  ' Init Variables
  totalu = 0: totalc = 0: totalf = 0
 
  ZIP = FREEFILE
  OPEN ZIPFile FOR BINARY AS ZIP
  IF LOF(ZIP)=0 THEN               ' Check if files exists
    ?ZipFile;""    ' if not, exit
    CLOSE ZIP
    KILL ZipFile
    EXIT SUB
  END IF
  ? "Searching: ";ZIPFile:?
  ? USING "\          \ \      \ \     \ \  \ \      \ \      \ \       \ \      \";_
           "";"";" Size";"Rate";" Date";"  Time";"  Method";" CRC-32"
  ? USING "\          \ \      \ \     \ \  \ \       \ \      \ \       \ \      \";_
          "------------";"--------";"-------";"----";"--------";"--------";"--------";"--------"
  DO
    GET ZIP,,Hdr                   ' Read File Header
    IF (Hdr.Signature = %Sig) Then ' Is a header
      F=SPACE$(Hdr.FileNameLen)      ' Grab filename
      GET ZIP,LOC(ZIP)-2,F
      Year=Hdr.DateTime:Shift Right Year, 25:Year=Year AND &H7F
      Month=Hdr.DateTime:Shift Right Month, 21:Month=Month AND &H0F
      Day=Hdr.DateTime:Shift Right Day, 16: Day=Day AND &H1F
      Hour=Hdr.DateTime:Shift Right Hour, 11: Hour=Hour AND &H1F
      Minute=Hdr.DateTime:Shift Right Minute, 5:Minute=Minute AND &H3F
      Secs=Hdr.DateTime AND &H1F
      M$=LTRIM$(STR$(Month))
      D$=LTRIM$(STR$(Day))
      IF LEN(M$)=1 THEN M$="0"+M$
      IF LEN(D$)=1 THEN D$="0"+D$
      A$=M$+"-"+D$+"-"+LTRIM$(STR$(Year+80))  ' Year starts at 1980
      H$=LTRIM$(STR$(Hour))
      M$=LTRIM$(STR$(Minute))
      S$=LTRIM$(STR$(Secs))
      IF LEN(H$)=1 THEN H$="0"+H$
      IF LEN(M$)=1 THEN M$="0"+M$
      IF LEN(S$)=1 THEN S$="0"+S$
      B$=H$+":"+M$+":"+S$
      ? USING "\          \ \      \ \     \ \  \ \       \ \       \ \      \ \      \";F;STR$(Hdr.USize);_
       STR$(Hdr.CSize);STR$(INT(100-Hdr.CSize/Hdr.USize*100))+"%";A$;B$;_
        CompTypes(Hdr.Compress);lcase$(HEX$(Hdr.CRC32))
      Incr TotalU,Hdr.USize  ' Increment size uncompressed
      Incr TotalC,Hdr.CSize  ' Increment size compressed
      Incr TotalF
    END IF
    SEEK ZIP,LOC(ZIP)+Hdr.CSize '+Hdr.ExtraField
  LOOP Until Hdr.Signature <> %SIG '  No more Files
  ?STRING$(72,"-")
  ? USING "\          \ \      \ \     \ \  \ \       \ \       \";_
   STR$(TotalF);STR$(TotalU);STR$(TotalC);STR$(INT(100-TotalC/TotalU*100))+"%";
  CLOSE ZIP
END SUB