' PowerBASIC source to read information from ZIP files. ' Written by Dave Navarro, Jr. ' Donated to the Public domain. $CPU 8086 $COMPILE UNIT $LIB ALL OFF $ERROR ALL OFF DEFINT A-Z 'GetZipInfo - Read the central dir of a zip file and return all the filenames ' and their info into an array. SUB GetZipInfo(F$, Aray$()) PUBLIC IF DIR$(F$) = "" THEN EXIT SUB ZipCount = ZipCenCount(F$) IF ZipCount = -1 THEN EXIT SUB IF ZipCount>UBOUND(Aray$(1)) THEN ZipCount = UBOUND(Aray$(1)) Offset& = Central&(F$) F = FREEFILE OPEN "B", F, F$ WHILE Count0 THEN Extra$ = Chunk$(F, Offset&+46+FilNamLen, Extra) ELSE Extra$ = "" END IF IF ComLen>0 THEN Comment$ = Chunk$(F, Offset&+46+FilNamLen+Extra, ComLen) ELSE Comment$ = "" END IF INCR Count INCR Offset&, 46+FilNamLen+Extra+ComLen Aray$(Count) = Info$+FilNam$+Extra$+Comment$ WEND CLOSE F END SUB 'ZSizeFile& - returns the zipped file size FUNCTION ZSizeFile&(Info$) PUBLIC ZSizeFile& = CVL(MID$(Info$, 17, 4)) END FUNCTION 'ZFileSize& - returns the unzipped size of the file FUNCTION ZFileSize&(Info$) PUBLIC ZFileSize& = CVL(MID$(Info$, 21, 4)) END FUNCTION 'ZCompMeth - returns the number corresponding to the compression method used ' on filename FUNCTION ZCompMeth(Info$) PUBLIC ZCompMeth = CVI(MID$(Info$, 7, 2)) END FUNCTION 'ZVerNeed - returns the version needed to unzip filename FUNCTION ZVerNeed(Info$) PUBLIC ZVerNeed = CVI(MID$(Info$, 3, 2)) END FUNCTION 'ZVerMade - returns the version used to create zipped file FUNCTION ZVerMade(Info$) PUBLIC ZVerMade = CVI(LEFT$(Info$, 2)) END FUNCTION 'ZFileAttr - returns the DOS attrbiute of the filename FUNCTION ZFileAttr(Info$) PUBLIC Tmp& = CVL(MID$(Info$, 35, 4)) ZFileAttr = Tmp& END FUNCTION 'ZFileTime$ - Converts ZIP integer into valid time FUNCTION ZFileTime$(Info$) PUBLIC Ft& = CVI(MID$(Info$, 9, 2)) hour = INT(Ft&/2048) hours = hour IF hour<0 THEN DECR hours, 12 hour$ = MID$(STR$(hours), 2) minutes = INT(Ft&-(hour*2048))\32 minutes$ = MID$(STR$(minutes), 2) seconds = hour AND 31 seconds$ = MID$(STR$(seconds*2), 2) IF LEN(seconds$) = 1 THEN seconds$ = "0"+seconds$ IF LEN(minutes$) = 1 THEN minutes$ = "0"+minutes$ IF LEN(hour$) = 1 THEN hour$ = " "+hour$ ZFileTime$ = hour$+":"+minutes$+":"+seconds$ END FUNCTION 'FilDate$ - Converts DOS integer into a valid date FUNCTION ZFileDate$(Info$) PUBLIC Fd = CVI(MID$(Info$, 11, 2)) Year = FD\512 Year$ = RIGHT$(STR$(Year+1980), 2) Month = (Fd-(Year*512))\32 Month$ = MID$(STR$(Month), 2) Day$ = MID$(STR$(Fd MOD 32), 2) IF LEN(day$) = 1 THEN day$ = "0"+day$ IF LEN(MONTH$) = 1 THEN MONTH$ = "0"+MONTH$ ZFileDate$ = Month$+"-"+Day$+"-"+Year$ END FUNCTION 'ZFileName$ - Parse a zip filename info line and retrieve the filename FUNCTION ZFileName$(Info$) PUBLIC FilNamLen = CVI(MID$(Info$, 25, 2)) ZFileName$ = MID$(Info$, 41, FilNamLen) END FUNCTION 'ZipCenCount - Query the end of central dir record for total number of ' zipped files. FUNCTION ZipCenCount(F$) PUBLIC IF DIR$(F$) = "" THEN ZipCenCount = -1 EXIT FUNCTION END IF F = FREEFILE OPEN "B", F, F$ FilLen& = LOF(F) OffSet& = FilLen&-1024 IF FilLen&<1024 THEN Search& = FilLen&:Offset& = 0 ELSE Search& = 1024 WHILE OffSet&> = 0 SEEK F, OffSet& GET$ F, Search&, Tmp$ CHead& = INSTR(Tmp$, "PK"+CHR$(5)+CHR$(6)) IF CHead& THEN CHead& = OffSet&+CHead&-1 OffSet& = -1 END IF DECR OffSet&, 1024 WEND IF CHead& = 0 THEN ZipCenCount = -1 CLOSE F EXIT FUNCTION END IF ZipCenCount = CVI(Chunk$(F, CHead&+11, 2)) CLOSE F END FUNCTION 'Central - Retrieve the offset of the central directory relative to the ' beginning of the ZIP file. FUNCTION Central&(F$) Tmp$ = "CopyRight 1991 by Dave Navarro, Jr." F = FREEFILE OPEN "B", F, F$ FilLen& = LOF(F) OffSet& = FilLen&-1024 IF FilLen&<1024 THEN Search& = FilLen& ELSE Search& = 1024 WHILE OffSet&> = 0 IF OffSet&<1 THEN Offset& = 0 SEEK F, OffSet& GET$ F, Search&, Tmp$ CHead& = INSTR(Tmp$, "PK"+CHR$(5)+CHR$(6)) IF CHead& THEN CHead& = OffSet&+CHead&-1 OffSet& = -1 END IF DECR OffSet&, 1024 WEND IF CHead& = 0 THEN Central& = -1 CLOSE F EXIT FUNCTION END IF Central& = CVL(Chunk$(F, CHead&+17, 4))+1 CLOSE F END FUNCTION FUNCTION Chunk$(F, Offset&, Length) SEEK F, Offset&-1 GET$ F, Length, Tmp$ Chunk$ = Tmp$ END FUNCTION