home *** CD-ROM | disk | FTP | other *** search
/ Black Box 4 / BlackBox.cdr / clipper / arcvie.arj / ARC_VIEW.PRG next >
Encoding:
Text File  |  1992-06-05  |  5.3 KB  |  155 lines

  1. /*
  2.     ARC_VIEW.PRG
  3.     Author:  Eric J. Givler
  4.     Date:    06/05/92
  5.     Purpose: View .ARC, .LZH, .ZIP, .ZOO.  Will support more later.
  6.              secondfile option added as quick-kludge to show off multi-browse.
  7. */
  8. #include "box.ch"
  9. #include "inkey.ch"
  10.  
  11.  
  12. FUNCTION Main( filetoview, secondfile )
  13. LOCAL lmissing := .F., ncursor := setcursor(0)
  14.  
  15.     if ! empty( filetoview ) .and. (lmissing := file(filetoview))
  16.         File_Viewer({ filetoview, secondfile })
  17.     else
  18.         ? 'ARC_VIEW 1.0, (c)1991,1992, Eric J. Givler, All Rights Reserved.'
  19.         ? 'Supports ARC, LZH, ZIP, ZOO files.'
  20.         ? 'Syntax: ARC_VIEW <arcname>'
  21.         ? 'Error: ' + if(lMissing, '<File not found>', '<Argument Missing>')
  22.     endif
  23.     setcursor(ncursor)
  24.  
  25. RETURN NIL
  26.  
  27.  
  28. STATIC FUNCTION FILE_VIEWER( aFiles_ )
  29. LOCAL cType, i, nkey, ncursor := setcursor()
  30. LOCAL b1, b2, cb, nCb, contents_, elems := len( aFiles_ ), index1, index2
  31. LOCAL scrn, cCol := setcolor(), c_ := { "W/B,GR+/R", "W+/RB,W+/BG" }
  32.  
  33.     if elems > 2 .or. valtype(aFiles_) != "A"
  34.         return NIL
  35.     endif
  36.  
  37.     contents_ := array(elems)
  38.     for i := 1 to elems
  39.         cType := upper(right(aFiles_[i], 3))
  40.         do case
  41.             case cType == "ARC"
  42.                 contents_[i] := ArcDir( aFiles_[i] )
  43.             // case cType == "ARJ"
  44.             //    contents_[i] := ArjView( aFiles_[i] )
  45.             case cType == "LZH"
  46.                 contents_[i] := LzhDir( aFiles_[i] )
  47.             case cType == "ZIP"
  48.                 contents_[i] := ZipDir( aFiles_[i] )
  49.             case cType == "ZOO"
  50.                 contents_[i] := ZooDir( aFiles_[i] )
  51.         endcase
  52.         if empty( contents_[i] )
  53.             adel( contents_[i] )
  54.             asize( contents_, len(contents_) -1)
  55.         endif
  56.     next i
  57.  
  58.     if empty( contents_ )
  59.         return NIL
  60.     endif
  61.  
  62.     scrn  := savescreen( 0, 0, maxrow(), maxcol() )
  63.     elems := len( contents_ )
  64.     //---------------------[ Set up first browse ]--------------------------
  65.     index1 := 1
  66.     nCb := 1
  67.     setcolor(c_[1])
  68.     b1 := tbrowsenew( 8, 1, 23, if(elems==1, 78,38) )
  69.     dispbox(b1:nTop-1,b1:nLeft-1,b1:nBottom+1,b1:nRight+1, ;
  70.             B_DOUBLE)
  71.     @ b1:nTop-1,b1:nLeft+1 say left(aFiles_[1],35)
  72.     b1:headsep := "═╤═"
  73.     b1:colsep  := " │ "
  74.     // b1:footsep := "═╧═"
  75.     // b1:colorspec := m->c_normcol
  76.     b1:gotopblock    := { || index1 := 1 }
  77.     b1:gobottomblock := { || index1 := len( contents_[1] ) }
  78.     b1:skipblock := { |n| ArraySkip( len( contents_[1] ), @index1, n ) }
  79.     b1:addcolumn( tbcolumnnew( "Filename",   { || contents_[1][index1][1] } ))
  80.     b1:addcolumn( tbcolumnnew( "Compressed", { || contents_[1][index1][2] } ))
  81.     b1:addcolumn( tbcolumnnew( "UnCompress", { || contents_[1][index1][3] } ))
  82.     b1:addcolumn( tbcolumnnew( "FileDate",   { || contents_[1][index1][4] } ))
  83.     b1:getcolumn(1):width := 12
  84.     b1:getcolumn(2):width := 10
  85.     b1:getcolumn(3):width := 10
  86.     b1:getcolumn(4):width :=  9
  87.  
  88.     if elems > 1
  89.         index2 := 1
  90.         setcolor(c_[2])
  91.         b2 := tbrowsenew(8, 41, 23, 78)
  92.         dispbox(b2:nTop-1,b2:nLeft-1,b2:nBottom+1,b2:nRight+1, ;
  93.             B_SINGLE)
  94.         @ b2:nTop-1,b2:nLeft+1 say left(aFiles_[2],35)
  95.         b2:headsep := "═╤═"
  96.         b2:colsep  := " │ "
  97.         // b2:footsep := "═╧═"
  98.         // b2:colorspec := "W+/RB,W+/BG"
  99.         b2:gotopblock    := { || index2 := 1 }
  100.         b2:gobottomblock := { || index2 := len( contents_[2] ) }
  101.         b2:skipblock := { |n| ArraySkip( len( contents_[2] ), @index2, n ) }
  102.         b2:addcolumn( tbcolumnnew( "Filename",   { || contents_[2][index2][1] } ))
  103.         b2:addcolumn( tbcolumnnew( "Compressed", { || contents_[2][index2][2] } ))
  104.         b2:addcolumn( tbcolumnnew( "UnCompress", { || contents_[2][index2][3] } ))
  105.         b2:addcolumn( tbcolumnnew( "FileDate",   { || contents_[2][index2][4] } ))
  106.         b2:getcolumn(1):width := 12
  107.         b2:getcolumn(2):width := 10
  108.         b2:getcolumn(3):width := 10
  109.         b2:getcolumn(4):width :=  9
  110.     endif
  111.  
  112.     if elems > 1
  113.         cb := b2
  114.         do while ! cb:stabilize()
  115.         enddo
  116.         cb:dehilite()
  117.     endif
  118.     cb := b1
  119.  
  120.     do while .t.
  121.  
  122.         do while ! cb:stabilize()
  123.         enddo
  124.  
  125.         nKey := inkey(0)
  126.         if StdMeth(nKey, cb)
  127.             // The previous function handles standard Tbrowse keystrokes.
  128.             loop
  129.         else
  130.             do case
  131.                 case nKey == K_TAB
  132.                     if elems > 1
  133.                         dispbox(cb:nTop-1,cb:nLeft-1,cb:nBottom+1,cb:nRight+1,;
  134.                            B_SINGLE, c_[nCb])
  135.                         @ cb:nTop-1,cb:nLeft+1 say left(aFiles_[nCb],35) color c_[nCb]
  136.                         nCb := if(nCb == 1, 2, 1)
  137.                         cb:dehilite()
  138.                         cb  := if(nCb == 1, b1, b2)
  139.                         cb:hilite()
  140.                         dispbox(cb:nTop-1,cb:nLeft-1,cb:nBottom+1,cb:nRight+1,;
  141.                            B_DOUBLE, c_[nCb])
  142.                         @ cb:nTop-1,cb:nLeft+1 say left(aFiles_[nCb],35) color c_[nCb]
  143.                     endif
  144.  
  145.                 case nKey == K_ESC
  146.                     exit
  147.             endcase
  148.         endif
  149.     enddo
  150.  
  151.     setcursor(ncursor)
  152.     restscreen( ,,,, scrn )
  153.  
  154. RETURN NIL
  155.