'===========================================================================
' Subject: VIEW ZIP FILES                     Date: 10-25-99 (18:05)       
'  Author: Randall L. Glass                   Code: PB                     
'  Origin: rlglass@yahoo.com                Packet: PB.ABC
'===========================================================================
'-------------------------------------------------------------------------
'
'                   ViewZip BY Randall L Glass
'                      CopyRight Aug3,1999
'
'---------------------------------------------------------------------------
'
' Email rlglass@yahoo.com
'
'---------------------------------------------------------------------------
'
' This Program is Freeware
' You may do anything with this program AS long AS you give me credit
' somewhere in the documentation.
'
' No frills Program to view ZIP Files for PB by Randall Glass.
'
' Use this program to add an ZIP & Lzh viewer in Dosshell.
'
' You must SET the value of TEMP in your autoexec.bat file.
' Example SET TEMP = D:\TMP
'
' OR Rewrite the code in the program to set TempDir to your tempory directory.
' And Rewrite the code to your editor or file viewer.
'
' Example SET Association in Dosshell For ZIP and LZH Files.
'
' C:\path\Viewzip.exe edit.com
'
' Dosshell beats Win 95 Windows Explorer any old time.
'
' To Run from DOS.
'
' Syntax  ViewZip [Editor OR File View Program] [ Zip OR Lzh File]
'
' Example >  ViewZip edit wetspot.zip
'
'----------------------------------------------------------------------------

$STACK 15000
DEFINT A-Z

TYPE ZipType
    Signature      AS DWORD
    Version        AS WORD
    GPBFlag        AS WORD
    Compress       AS WORD
    FileTime       AS WORD
    Filedate       AS WORD
    CRC32          AS DWORD
    CompressSize   AS DWORD
    UnCompressSize AS DWORD
    FileNameLen    AS WORD
    ExtraField     AS WORD
END TYPE

TYPE LZHHead
     HeadSize       AS BYTE
     CheckSum       AS BYTE
     Id1            AS STRING * 3
     Method         AS BYTE
     Id2            AS BYTE
     CompressSize   AS DWORD
     UnCompressSize AS DWORD
     FileTime       AS WORD
     FileDate       AS WORD
     Attrs          AS BYTE
     HeaderLevel    AS BYTE
     FileNameLen    AS BYTE
     FileName       AS STRING * 12
END TYPE

DECLARE Function GetKey%() AS INTEGER
DECLARE SUB GetStrLoc()
DECLARE SUB BoxBorder ()
DECLARE SUB Scroll(BYVAL TopRow%,BYVAL TopLeftCol%,BYVAL BottomRow%,BYVAL BottomRightCol%,BYVAL TotalLines%,BYVAL Attr%,BYVAL WhichWay%)

DIM ScreenSegment AS shared WORD
DIM DirStack$(10)

SHARED Viewer$,TempDir$,Level%,StackPos%,DirStack$(),Archiver$,ViewCmd$
SHARED StartLine$,EndLine$,FileList$,Response$,ExtractCmd$,ExtractReponse$


%PkSig = &H04034B50             ' Signature
%UpArrow = -72:%DownArrow = -80:%Enter = 13:%Escape = 27
%Home = -71:%PageDown = -81:%PageUp = -73:%EndKey = -79
%Up = 6:%Down = 7:%LeftArrow = -75:%RightArrow = -77
%U = 85
%ReadOnly = 0:%Hidden = 1:%System = 2:%Volume = 3:%SubDir = 4:%Archive = 5
%TotalFiles = 0

IF(PBVScreenCARD AND 1) = 0 THEN
      ScreenSegment?? = 47104       '&HB800          'color monitor
ELSE
      ScreenSegment?? = 45056       '&HB000          'mono monitor
END IF

CLS
LOCATE 1,1,0
Cmd$ = UCASE$(COMMAND$)
Viewer$ = Extract$(Cmd$," ")
File$ = Trim$(Remove$(Cmd$,Viewer$))
Ext$ = Extension$(File$)
File$ = TrueName$(File$)
IF ISFALSE FileExist%(File$) THEN END

TempDir$ = ENVIRON$("TEMP")

PushDir TempDir$

ViewZip File$

COLOR 7,0
CLS
END

SUB ViewZip(File$)
IF ISFALSE FileExist%(File$) THEN
	LOCATE 5,15:PRINT File$;" doesn't exist !";
      EXIT SUB
END IF
DIM ArchiveFiles$(1000),ArchiveInfo$(1000),ArchiveDir$(1000)
  Choice% = 1:DisplayPos% = 1:LowFIle% = 1:HiFile% = 18
  Ky% = 0
  InfoLine$ = "   FileName"+"       Size"+"     Date" + "       Time"
  CLS
  Ext$ = Extension$(File$)
   IF Ext$ = ".ZIP" OR Ext$ = ".LZH" THEN
      PresentDir$ = CURDIR$
      PresentDrive$ = CURDRIVE$
      CHDRIVE Left$(File$,1)
      CHDIR GetDirectory$(File$)
      SELECT CASE Ext$
          CASE ".ZIP"
                ZipView GetFileName$(File$), ArchiveFiles$(), ArchiveInfo$(), FilesInfo$,Success%
          CASE ".LZH"
                LzhView GetFileName$(File$), ArchiveFiles$(), ArchiveInfo$(), FilesInfo$
      END SELECT
      CHDRIVE PresentDrive$
      CHDIR PresentDir$
      TotalFiles?? = CVWRD(ArchiveFiles$(%TotalFiles))
      'ARRAY SORT ArchiveFiles$(1) FOR TotalFiles??,TAGARRAY ArchiveInfo$()
      DO
               Pick% = ChooseProgram%( ArchiveInfo$(),ArchiveFiles$(),FilesInfo$,InfoLine$,Choice%,DisplayPos%,LowFile%,HiFile%,Ky%)
               Choice% = Pick%
                SELECT CASE Ky%
                        CASE %Escape
                                EXIT SUB
                        CASE %Enter
                                IF Pick% > 0 THEN
                                		Pick$ = UCASE$(ArchiveFiles$(Pick%))
                                          RealName$ = GetFileName$(Pick$)
                                        	PickExt$ = Extension$(Pick$)
                                        	IF PickExt$ =".ZIP" OR PickExt$ = ".LZH" THEN
                                                PushDir "TEMP"
                                                RealDir$ = TrueDir$ + "\"
                                                IF ISFALSE FileExist%(RealDir$+Pick$) THEN
                                                        CLS
                                                        SELECT CASE Ext$
                                                        CASE ".ZIP"
                                                                SHELL "PkUnzip -e -o " + File$ + " " + Pick$ + " " + RealDir$ + " >NUL"
                                                        CASE ".LZH"
                                                                SHELL "lha e /pn2 " + File$ + " " + RealDir$ + " "+ Pick$
                                                  END SELECT
                                                END IF

                                                ViewZip RealDir$ + RealName$
                                                SHELL "DELTREE /Y " + Rtrim$(RealDir$,"\") + " >NUL"
                                                PopDir
                                                CLS
                                                DELAY .2
                                                ITERATE LOOP
                                        	ELSE
                                                CLS
                                                RealDir$ = TrueDir$ + "\"
                                                SELECT CASE Ext$
                                                        CASE ".ZIP"
                                                                SHELL "PkUnzip -e -o " + File$ + " " + Pick$ + " " + RealDir$ + " >NUL"
                                                        CASE ".LZH"
                                                                SHELL "lha e /pn2 " + File$ + " " + RealDir$ + " "+ Pick$
                                                END SELECT
                                        	END IF
                                        'CLS
                                        PresentDir$ = CURDIR$
                                        PresentDrive$ = CURDRIVE$
                                        CHDRIVE LEFT$(TrueDir$,1)
                                        CHDIR TrueDir$
                                        SHELL Viewer$ + " " + RealName$
                                        CLS
                                        KILL RealName$
                                        CHDRIVE PresentDrive$
                                        CHDIR PresentDir$
                                        DELAY .2
                                        COLOR 7,0
                                    END IF
                        'CASE %U
                END SELECT
      LOOP
   END IF
END SUB

FUNCTION ChooseProgram%(ArchiveInfo$(),ArchiveFile$(),InfoLine1$,InfoLine2$ ,Choice%, DisplayPos%,LowFile%, HiFile%,Ky%)
   DIM PrintLine AS STRING * 47
   DIM DirLine AS STRING * 80
   DisplayLine% = 18

   TotalFiles% = CVWRD(ArchiveInfo$(0))
   IF TotalFiles% < DisplayLine% THEN HiFile% = TotalFiles%

     BottomDisplayLine% = DisplayLine%
     COLOR 7,1
     CLS
     COLOR 0,7
     LOCATE 1,1:PRINT SPACE$(80);
     COLOR 7,1
     LOCATE 2,2:PRINT Ltrim$(InfoLine1$)
     LOCATE 4,2:PRINT InfoLine2$

   DO
      COLOR 15, 1
      LinePos% = 0
      IF TotalFiles% < 15 THEN BottomDisplayLine% = TotalFiles%
      IF ScrollIt% = 0 THEN
	      'POKE$ 0, SaveScreen$ : LOCATE y%, x%       'restore old screen
	      FOR ArchiveFile% = LowFile% TO HiFile%
	         INCR LinePos%
               LSET PrintLine$ = ArchiveInfo$(ArchiveFile%)
	         IF LinePos% = DisplayPos% THEN
	            QPrint 5 + LinePos%,1, PrintLine$ ,71
	         ELSE
	            QPRINT 5 + LinePos%,1,PrintLine$,23
	         END IF
	      NEXT ArchiveFile%
		LSET PrintLine$ = ""
            FOR I% = LinePos% + 1 To DisplayLine%
	            QPRINT 5 + I%,1,PrintLine$,23
            NEXT I%
      ELSE
		LSET PrintLine$ = ArchiveInfo$(Choice%)
            QPRINT 5 + DisplayPos%,1,PrintLine$,71
      END IF

      DirLine$ = SPACE$(80)
      MID$(DirLine$,2) = ArchiveFile$(Choice%)
      COLOR 0,7:LOCATE 25,1:PRINT DirLine$;

      ScrollIt% = 0
      ClearBuffer
      DO: k$ = UCASE$(INKEY$): LOOP WHILE k$ = ""
      Ky% = ASC(k$): IF Ky% = 0 THEN Ky% = -ASC(MID$(k$, 2))
       SELECT CASE Ky%
         CASE %Enter
         	ChooseProgram% = choice%: EXIT DO
         CASE %Escape
         	ChooseProgram% = 0: EXIT DO
         CASE %Home
         	choice% = 1:LowFile% = 1
            HiFile% = BottomDisplayLine%
            DisplayPos% = 1
         CASE %EndKey
            Choice% = TotalFiles%
            DisplayPos% = MODTYPE(Choice%, BottomDisplayLine%)
            LowFile% = Choice% - DisplayPos% + 1
            HiFile% = TotalFiles%
         CASE %PageDown
            INCR Choice%, DisplayLine%
            INCR LowFile%,DisplayLine%
            HiFile% = LowFile% + BottomDisplayLine% -1
            IF HiFile% > TotalFiles% THEN HiFile% = TotalFiles%
		IF choice% > TotalFiles% THEN
			Choice% = TotalFiles%
                        DisplayPos% = ModType(Choice%, BottomDisplayLine%)
			LowFile% = Choice% - DisplayPos% + 1
			HiFile% = TotalFiles%
	      END IF

         CASE %PageUp
            DECR Choice%,DisplayLine%
            DECR LowFile%,DisplayLine%
            HiFile% = LowFile% + DisplayLine% -1
            IF LowFile% < 1 THEN LowFile% = 1:HiFile% = BottomDisplayLine%
	      IF Choice% <=1 THEN
              Choice% = 1
              LowFile% = 1
              HiFile% = BottomDisplayLine%
              DisplayPos% = 1
      	END IF
         CASE %DownArrow
            INCR Choice%
            IF Choice% <= TotalFiles% THEN
                  INCR DisplayPos%
            ELSE
            	Choice% = TotalFiles%
            END IF
	      IF DisplayPos% > BottomDisplayLine% THEN
                DisplayPos% = BottomDisplayLine%
                LowFile% = Choice% -BottomDisplayLine% + 1
                IF HiFile%  >= TotalFiles% THEN
                   HiFile% = TotalFiles%
                ELSE
                   HiFile% = LowFile% + BottomDisplayLine% -1
                END IF
                PrintAtr BottomDisplayLine%+5, 1, 47, 23
                Scroll 5,1, BottomDisplayLine%+4,47, 1,23,%Up
                ScrollIt% = 1
      	END IF
         CASE %UpArrow
             DECR choice%
             DECR DisplayPos%
             IF choice% <=1 THEN
             	choice% = 1
             	LowFile% = 1
             	HiFile% = BottomDisplayLine%
             	DisplayPos% = 1
             ELSE
	            IF DisplayPos% < 1 THEN
		             DisplayPos% = 1
		             LowFile% = Choice%
		             HiFile% = Choice% + BottomDisplayLine% -1
                         IF HiFile%  >= TotalFiles% THEN
            		       HiFile% = TotalFiles%
                         ELSE
            		       HiFile% = LowFile% + BottomDisplayLine% -1
                         END IF
                         PrintAtr 6, 1, 47, 23
                         Scroll 5,1, BottomDisplayLine%+4,47, 1,23,%Down
                         ScrollIt% = 1
                  END IF
             END IF
      	CASE ELSE
            	EXIT DO
      END SELECT
   LOOP
   COLOR 7,0
END FUNCTION


SUB Scroll(BYVAL TopRow%,BYVAL TopLeftCol%,BYVAL BottomRow%,BYVAL BottomRightCol%,BYVAL TotalLines%,BYVAL Attr%,BYVAL WhichWay%)
!       PUSH DS
!       PUSH BP
!       MOV AH,WhichWay%
!       MOV AL, TotalLines%
!       MOV BH, Attr%
!       MOV CH, TopRow%
!       MOV CL, TopLeftCol%
!       MOV DH, BottomRow%
!       MOV DL, BottomRightCol%
!       INT &H10
!       POP BP
!       POP DS
END SUB

SUB QPrint(BYVAL Row, BYVAL Col, BYVAL Text$, BYVAL attr) PUBLIC
ScreenSeg??  = ScreenSegment??

   ! push DS                 ; save DS for PowerBASIC
   ! mov             ax,Row%         ; get the row
   ! dec             al              ; convert row to zero base
   ! mov             bl,80           ; get the number of cols
   ! mul             bl              ; multiply # of cols * rows
   ! add             ax,Col%         ; add the column
   ! dec             al              ; convert column to zero base
   ! mov             di,ax           ; offset within video page
   ! shl             di,1            ; account for color/attribute

   ! push WORD PTR Text$     ; push string handle on the stack
   ! call GetStrLoc          ; find the string
   ! jcxz QPExit             ; if it's Null, exit
   ! mov  DS, DX             ; put segment in DS
   ! mov  SI, AX             ; put offset in SI
   ! mov  ES, ScreenSeg??    ; move to ES
   ! mov  AH, attr           ; put attribute in AH
   WriteChar:
   ! lodsb                   ; get Char from string
   ! stosw                   ; write Char and attribute to screen
   ! loop WriteChar          ; do it all CX times
   QPExit:
   ! pop  DS                 ; restore DS for PowerBASIC
END SUB

SUB PrintAtr(byval Row%, byval Col%,ByVal LineWidth%, byval Attr%)
ScreenSeg??  = ScreenSegment??
!           push    ds              ;save the good stuff
!           mov     ax,Row%         ; get the row
!           dec     al              ; convert row to zero base
!           mov     bl,80           ; get the number of cols
!           mul     bl              ; multiply # of cols * rows
!           add     ax,Col%         ; add the column
!           dec     al              ; convert column to zero base
!           mov     di,ax           ; offset within video page
!           shl     di,1            ; account for color/attribute
!           mov     es,ScreenSeg??  ;put video segment into ax
!           mov     ah,Attr%        ;the color attribute will be needed
!           mov     cx,LineWidth%
forloop:
!           inc     di              ;increment to the next vidram position
!           mov     es:[di],ah      ;poke the attribute into vidram
!           inc     di
!           loop    forloop         ;loop until cx = 0
!           pop     ds
END SUB

FUNCTION GetKey%() Public
While ISFALSE INSTAT:Wend
ky$ = Inkey$
IF len(ky$) = 2 then
	GetKey% = -ascii(right$(ky$,1))
ELSE
	GetKey% = ascii(ky$)
END IF
END FUNCTION

SUB ClearBuffer
DO:LOOP UNTIL INKEY$ = ""
END SUB

SUB GetDir(Spec$,Attr%,Directory$(),TotalFiles%)
DirFile$ = DIR$(Spec$,Attr%)
IF DirFile$ <> "" THEN
	Attribute% = Attrib(DirFile$)
	IF BIT(Attribute%,Attr%) THEN
      	INCR FileNum%
      	Directory$(FileNum%) = DirFile$
	END IF
ELSE
      TotalFiles% = 0
	EXIT SUB
END IF

DO
	DirFile$ = DIR$
	IF DirFile$ <> "" THEN
		Attribute% = Attrib(DirFile$)
		IF BIT(Attribute%,Attr%) THEN
	      	INCR FileNum%
	      	Directory$(FileNum%) = DirFile$
	      END IF
	ELSE
		EXIT SUB
	END IF
LOOP
END SUB

SUB GetRegDir(Spec$,Attr%,Directory$(),TotalFiles%)
DirFile$ = DIR$(Spec$,Attr%)
IF DirFile$ <> "" THEN
	INCR FileNum%
	Directory$(FileNum%) = DirFile$
ELSE
      TotalFiles% = 0
	EXIT SUB
END IF

DO
	DirFile$ = DIR$
	IF DirFile$ <> "" THEN
      	INCR FileNum%
      	Directory$(FileNum%) = DirFile$
	ELSE
		EXIT SUB
	END IF
LOOP
END SUB

FUNCTION Extension$(File$)
      FOR I% = LEN(File$) TO 1 STEP -1
		Period$ = MID$(File$,I%,1)
            IF Period$ = "." THEN Extension$ = MID$(File$,I%):EXIT FUNCTION
	NEXT I%
END FUNCTION

FUNCTION Trim$(S$)
Trim$ = Ltrim$(Rtrim$(S$))
END FUNCTION

FUNCTION GetFileName$(F$)
FOR I% = LEN(F$) TO 1 STEP -1
	Char$ = MID$(F$,I%,1)
	IF Char$ = "\" OR CHAR$ = "/" THEN
      	GetFileName$ = File$
            EXIT FUNCTION
	ELSE
      	File$ = Char$ + File$
      END IF
NEXT I%
GetFileName$ = File$
END FUNCTION

FUNCTION GetDirectory$(D$)
Ln% = LEN(D$)
FOR I% = Ln% TO 1 STEP -1
      Char$ = MID$(D$,I%,1)
	IF Char$ = "\" OR CHAR$ = "/" THEN EXIT FOR
NEXT I%
IF I% <> 3 THEN
	TheDir$ = LEFT$(D$,I%-1)
ELSE
	TheDir$ = LEFT$(D$,I%)
END IF
GetDirectory$ = TheDir$
END FUNCTION

FUNCTION FileDirExist%(d$)
Ln% = LEN(D$)
FOR I% = Ln% TO 1 STEP -1
      Char$ = MID$(D$,I%,1)
	IF Char$ = "\" OR CHAR$ = "/" THEN EXIT FOR
NEXT I%
FileDirExist% = I%
END FUNCTION

SUB PushDir(Directory$)
INCR StackPos%
DirStack$(StackPos%) = Directory$
IF Directory$ = "" THEN EXIT SUB
IF  DirExist%(TrueDir$) = 0 THEN MKDIR TrueDir$
END SUB

SUB PopDir
DECR StackPos%
END SUB

FUNCTION TrueDir$()
D$ = DirStack$(1)
FOR I% = 2 to StackPos%
D$ = D$ + "\" + DirStack$(I%)
NEXT I%
TrueDir$ = D$
END FUNCTION

FUNCTION DirExist%(Directory$)
DirName$ = DIR$(Directory$,16)
IF DirName$ = "" THEN EXIT FUNCTION
Exists% = ATTRIB(Directory$)
Exists% = BIT(Exists%,4)
IF Exists% THEN DirExist% = 1
END FUNCTION

FUNCTION FileExist%(Directory$)
D$ = DIR$(Directory$)
IF D$ <> "" THEN FileExist% = 1
END FUNCTION

FUNCTION TrueName$(Directory$)
DIM DirName2 AS STRING * 128
DirName$ = Directory$ +CHR$(0)
DirNamePtr??? = STRPTR32(DirName$)
DirNamePtr2??? = VARPTR32(DirName2$)
LOCAL DosError??
!PUSH DS
!LDS SI,DirNamePtr???
!LES DI,DirNamePtr2???
!MOV AH,&H60
!INT &H21
!MOV DosError??,Ax
!POP DS
IF DosError?? = 2 OR DosError?? = 3 THEN PRINT "Can't Get TrueName !":END
TrueName$ = EXTRACT$(DirName2$,CHR$(0))
END FUNCTION

FUNCTION CURDRIVE$
Curdrive$ = LEFT$(CURDIR$,1)
END FUNCTION

FUNCTION MODTYPE??(Number%,ModNumber%)
 M% = Number% MOD ModNumber%
 IF M% = 0 THEN
 	ModType% = ModNumber%
 ELSE
 	ModType% = M%
 END IF
END FUNCTION

SUB LzhView(LzhFile$,ArchiveFiles$(),ArchiveInfo$(), FilesInfo$)
 DIM Lzh AS LZHHead
 DIM FileName AS STRING * 8
 DIM Ext AS STRING * 4

  FilePos??? = 0: QUIT% = 0

  Handle% = FREEFILE

  OPEN LzhFile$ FOR BINARY AS Handle%
  RestOfFileSize??? = LOF(Handle%)
  IF RestOfFileSize??? = 0 THEN
    CLOSE Handle%
    PRINT LzhFile$+" has an FileSize of Zero !"
    EXIT SUB
  END IF


  DO
          GET  Handle%,FilePos???,Lzh
          IF Lzh.Id1 = "-lh" Or Lzh.Id1 = "-lz" Or Lzh.Id1 = "-lZ" THEN
            IF Lzh.HeadSize AND (Lzh.HeadSize < RestOfFileSize???) THEN
                Get Handle%,FilePos??? + Lzh.HeadSize,DirLen??
                SEEK Handle%,FilePos??? + Lzh.HeadSize+3

                IF DirLen?? > 0 AND DirLen?? < 256 THEN
                              GET$ Handle%,DirLen??-3,Directory$
                              REPLACE  CHR$(255) WITH "\" IN Directory$
                ELSE
                              Directory$ = ""
                END IF

                INCR FilePos???, Lzh.CompressSize + Lzh.HeadSize + 2
                DECR RestOfFileSize???, FilePos???

                INCR FileNumber??

                File$ = LEFT$(Lzh.FileName,Lzh.FileNameLen)
                LSET FileName$ = Extract$(File$,".")
                LSET Ext$ = Extension$(File$)
                GetDateAndTime Lzh.Filedate,Lzh.FileTime,Filedate$,FileTime$
                IF DirLen?? THEN
                	DirSign$ = " + "
                ELSE
                	DirSign$ = "   "
                END IF
                ArchiveFiles$(FileNumber??) = Directory$ + File$
                ArchiveInfo$(FileNumber??)  = DirSign$ + FileName$ + Ext$ + USING$("########",Lzh.UnCompressSize) + " " + Filedate$ + "  "+FileTime$
            END IF
          ELSE
                INCR FilePos???, 2
           	    DECR RestOfFileSize???, FilePos???
          END IF

  Loop UNTIL Lzh.HeadSize = 0 Or Lzh.HeadSize > RestOfFileSize??? OR FilePos??? = RestOfFileSize???

  Close Handle%
  FilesInfo$ =  LzhFile$ + ":" + STR$(FileNumber??)+" Files"
  ArchiveFiles$(0) = MKWRD$(FileNumber??)
  ArchiveInfo$(0)  = MKWRD$(FileNumber??)

END SUB

SUB ZipView(ZipFile$,ArchiveFiles$(),ArchiveInfo$(),FilesInfo$,Success%)  ' View the ZIP File
 DIM Zip AS ZipType
 DIM FileName AS STRING * 8
 DIM Ext AS STRING * 4
 FileNumber?? = 0
 Success% = 0

  Handle% = FREEFILE
  OPEN ZipFile$ FOR BINARY AS Handle%
  FileSize??? = LOF(Handle%)
  IF FileSize??? = 0 THEN               ' Check if files exists
    '?ZipFile;" has an FileSize of Zeor !"    ' if not, exit
    CLOSE Handle%
    EXIT SUB
  END IF

    DO
    	GET Handle%,ZipPos???,SIG???                   ' Read File Header
      IF Sig??? = %PkSig Then FilePos??? = ZipPos???:EXIT LOOP
      INCR ZipPos???,2
      IF ZipPos??? > 200 THEN CLOSE Handle%:EXIT SUB
    LOOP

  DO
    GET Handle%,FilePos???,Zip                   ' Read File Header

    IF (Zip.Signature = %PkSig) THEN
      INCR FilePos???, Zip.CompressSize + 30 + Zip.FileNameLen + ZIP.ExtraField
      INCR FileNumber??
	GET$ Handle%,Zip.FileNameLen,File$
      TheFile$ = GetFileName$(File$)
      IF TheFile$ = "" THEN
      	DECR FileNumber??
            ITERATE DO
      END IF

      LSET FileName$ = Extract$(TheFile$,".")
      LSET Ext$ = Extension$(File$)
      GetDateAndTime Zip.Filedate,Zip.FileTime,Filedate$,FileTime$
      ArchiveFiles$(FileNumber??) = File$

	IF FileDirExist%(File$) THEN
		DirSign$ = " + "
	ELSE
		DirSign$ = "   "
	END IF

      ArchiveInfo$(FileNumber??)  = DirSign$ + FileName$ + Ext$ + USING$("########",Zip.UnCompressSize) + "  "+Filedate$+"  "+FileTime$
  END IF

  LOOP WHILE Zip.Signature = %PkSig
  CLOSE Handle%

  FilesInfo$ =  ZipFile$ + ":" + STR$(FileNumber??)+" Files"
  ArchiveInfo$(0) = MKWRD$(FileNumber??) 'Total Number of FIles
  ArchiveFiles$(0) = MKWRD$(FileNumber??)
  IF FileNumber?? > 1 THEN ARRAY SORT ArchiveFiles$(1) FOR FileNumber??,TAGARRAY ArchiveInfo$()
  Success% = 1

END SUB

SUB GetDateAndTime(Filedate??,FileTime??,Filedate$,FileTime$)
       Year?? = (Filedate?? AND &B1111111000000000):SHIFT RIGHT Year??,9
       INCR Year??,1980
       Month?? = Filedate?? AND &B0000000111100000:SHIFT RIGHT Month??,5
       Day?? = Filedate?? AND &B0000000000011111
       Hours?? = FileTime?? AND &B1111100000000000:SHIFT RIGHT Hours??,11
       Minutes?? = FileTime?? AND &B0000011111100000:SHIFT RIGHT Minutes??,5
       Seconds?? = (FileTime?? AND &B0000000000011111) * 2

       Month$ = LTRIM$(STR$(Month??))
       Day$ = LTRIM$(STR$(Day??))
       IF LEN(Month$) = 1 THEN Month$="0"+Month$
       IF LEN(Day$) = 1 THEN Day$ = "0"+Day$
       'IF Hours?? > 12 THEN
       '	Hours?? = Hours?? -12:AmPm$ = "p & "
       'ELSE
       '	AmPm$ = "a & "
       'END IF
       Hours$ = LTRIM$(STR$(Hours??))
       Minutes$ = LTRIM$(STR$(Minutes??))
       Seconds$ = LTRIM$(STR$(Seconds??))
       IF LEN(Hours$) = 1 THEN Hours$="0"+Hours$
       IF LEN(Minutes$) = 1 THEN Minutes$="0"+Minutes$
       IF LEN(Seconds$) = 1 THEN Seconds$="0"+Seconds$

       Filedate$ = Month$ + "-" + Day$ + "-" + LTRIM$(STR$(Year??))
       FileTime$ = Hours$ + ":" + Minutes$ + ":" + Seconds$
       'FileTime$ = Hours$ + ":" + Minutes$ + AmPm$ + Seconds$ +"s"

END SUB
