home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DP Tool Club 8
/
CDASC08.ISO
/
VRAC
/
ARCVIE13.ZIP
/
FILEVIEW.PRG
< prev
next >
Wrap
Text File
|
1993-09-05
|
11KB
|
298 lines
/*
FILEVIEW.PRG
AUTHOR: Eric J. Givler
WRITTEN: 06/05/92
MODS: 06/26/92 - Documented support for ARJ files. Some 'mite' fixes.
Added PAK support by modifying ARCDIR.PRG to not
choke on 2nd char after chr(26) being > 12.
06/28/92 - Support for Sorting [F8] by Name, Extension or Date.
03/13/93 - Fileviewing!
LowLevel byte determination of compressed file type.
Creates TEMP directory under current. DOES NOT REMOVE.
06/26/93 - #ifdef BLINKER for viewing inside archives.
SYNTAX: FileView( { <file1.ext> [, file2.ext] } )
PURPOSE: View .ARC, .ARJ, .LZH, .PAK, .ZIP, .ZOO. Will support more
later.
NOTES: Pass files to view INSIDE AN ARRAY.
Calls: FReadln(), IsDir(), MkDir(), ChDir(), Text_Browse()
IsTextFile(), SwpRunCmd()
*/
#include "box.ch"
#include "fileio.ch"
#include "inkey.ch"
#define F_NAME 1
#translate ext( <f> ) => ;
if( '.' $ <f>, substr(<f>, at('.', <f>) + 1), '')
STATIC unCompress_ := { { 'ZIP', 'pkunzip -e -o [COMPFILE] temp [FILENAME]' } ,;
{ 'ARJ', 'ARJ E -y -wtemp [COMPFILE] [FILENAME]' } ,;
{ 'LZH', 'LHA E -m -wtemp [COMPFILE] [FILENAME]' } ,;
{ 'ARC', 'PKXARC -E -o [COMPFILE] temp [FILENAME]' } }
*--------------------------------------------------[ FileView() ]------------*
FUNCTION FILEVIEW( aFiles_ )
LOCAL ncursor := setcursor(), ;
cCol := setcolor(), ;
c_ := { "W+/B,GR+/R", "W+/RB,W+/BG" }, ;
elems := len( aFiles_ ), ;
contents_:= {}, ;
n := 1, ; // FOR..NEXT counter.
cTestchar:= space(8), ;
nHandle, i, nkey
LOCAL b1, b2, cb, nCb, index1, index2
LOCAL scrn, longest, files_
LOCAL cConfig, cBuffer, aExtract_ := {}
if elems > 2 .or. VALTYPE(aFiles_) != "A"
RETURN NIL
endif
FOR i := 1 to elems
files_ := {}
if ( nHandle := fopen( aFiles_[n], FO_READ ) ) != F_ERROR
fseek( nHandle, 0, FS_SET )
fread( nHandle, @ctestchar, 8)
fclose( nHandle )
// cType := upper(right(aFiles_[n], 3))
ctestchar := upper(ctestchar)
do case
case left(cTestChar,1) = chr(26) // ARC oder PAK
files_ := ArcDir( afiles_[n] )
case left(cTestChar,2) = chr(96)+chr(234) // ARJ
files_ := ArjDir( afiles_[n] )
case at("-LH",cTestChar) > 0 // LZH
files_ := LzhDir( afiles_[n] )
case left(cTestChar,2) = "PK" // PKZIP
files_ := ZipDir( afiles_[n] )
case left(cTestChar,3) = "ZOO" // ZOO
files_ := ZooDir( afiles_[n] )
case Upper(right(aFiles_[n],3)) == "DWC" // DWC
// Actually, you should test last 3 characters in file.
files_ := DWCDir( aFiles_[n] )
endcase
endif
if ! empty( files_ )
aadd( contents_, files_ )
n++
else
adel( aFiles_, n )
asize( aFiles_, 1)
endif
NEXT i
if empty( contents_ )
ALERT("Could not view the filenames that were passed")
RETURN NIL
endif
// Read in viewer configuration information, else use what's
// defined above.
if EMPTY( cConfig := getenv('FILEVIEW') )
aExtract_ := unCompress_
else
if (nhandle := fopen( cConfig, FO_READ )) != F_ERROR
cbuffer := space(80)
do while freadln( nhandle, @cbuffer, 80 )
aadd( aExtract_, { left(cbuffer,at(' ',cBuffer)-1), ;
substr(cbuffer,at(' ',cbuffer)+1) } )
enddo
fclose(nhandle)
else
aExtract_ := unCompress_
endif
endif
scrn := savescreen( 0, 0, maxrow(), maxcol() )
elems := len( contents_ )
//---------------------[ Set up first browse ]--------------------------
index1 := 1
nCb := 1
setcolor(c_[1])
b1 := tbrowsenew( 8, 1, 23, if(elems==1, 78,38) )
dispbox(b1:nTop-1,b1:nLeft-1,b1:nBottom+1,b1:nRight+1, ;
B_DOUBLE + " ")
@ b1:nTop-1,b1:nLeft+1 say left(aFiles_[1],35)
b1:headsep := "═╤═"
b1:colsep := " │ "
// b1:footsep := "═╧═"
// b1:colorspec := m->c_normcol
b1:gotopblock := { || index1 := 1 }
b1:gobottomblock := { || index1 := len( contents_[1] ) }
b1:skipblock := { |n| ArraySkip( len( contents_[1] ), @index1, n ) }
b1:addcolumn( tbcolumnnew( "Filename", { || contents_[1][index1][1] } ))
b1:addcolumn( tbcolumnnew( "Compressed", { || contents_[1][index1][2] } ))
b1:addcolumn( tbcolumnnew( "UnCompress", { || contents_[1][index1][3] } ))
b1:addcolumn( tbcolumnnew( "FileDate", { || contents_[1][index1][4] } ))
// The following 3 lines allow for the embedded ARJ path too.
longest := 0
aeval( contents_[1], { |a| longest := max( len(a[1]), longest ) } )
b1:getcolumn(1):width := longest
b1:getcolumn(2):width := 10
b1:getcolumn(3):width := 10
b1:getcolumn(4):width := 9
if elems > 1
index2 := 1
setcolor(c_[2])
b2 := tbrowsenew(8, 41, 23, 78)
dispbox(b2:nTop-1,b2:nLeft-1,b2:nBottom+1,b2:nRight+1, ;
B_SINGLE + " ")
@ b2:nTop-1,b2:nLeft+1 say left(aFiles_[2],35)
b2:headsep := "═╤═"
b2:colsep := " │ "
// b2:footsep := "═╧═"
// b2:colorspec := "W+/RB,W+/BG"
b2:gotopblock := { || index2 := 1 }
b2:gobottomblock := { || index2 := len( contents_[2] ) }
b2:skipblock := { |n| ArraySkip( len( contents_[2] ), @index2, n ) }
b2:addcolumn( tbcolumnnew( "Filename", { || contents_[2][index2][1] } ))
b2:addcolumn( tbcolumnnew( "Compressed", { || contents_[2][index2][2] } ))
b2:addcolumn( tbcolumnnew( "UnCompress", { || contents_[2][index2][3] } ))
b2:addcolumn( tbcolumnnew( "FileDate", { || contents_[2][index2][4] } ))
longest := 0
aeval( contents_[2], { |a| longest := max( len(a[1]), longest ) } )
b2:getcolumn(1):width := longest
b2:getcolumn(2):width := 10
b2:getcolumn(3):width := 10
b2:getcolumn(4):width := 9
endif
if elems > 1
cb := b2
do while ! cb:stabilize()
enddo
cb:dehilite()
endif
cb := b1
DO WHILE .T.
do while ! cb:stabilize()
enddo
nKey := inkey(0)
if StdMeth(nKey, cb)
// The previous function handles standard Tbrowse keystrokes.
loop
else
do case
#ifdef BLINKER
case nKey == K_ENTER
ViewFile( aFiles_[nCb], ;
contents_[nCb][if(nCb=1,index1,index2)][1], ;
aExtract_ )
#endif
case nKey == K_TAB
if elems > 1
dispbox(cb:nTop-1,cb:nLeft-1,cb:nBottom+1,cb:nRight+1,;
B_SINGLE, c_[nCb])
@ cb:nTop-1,cb:nLeft+1 say left(aFiles_[nCb],35) color c_[nCb]
nCb := if(nCb == 1, 2, 1)
cb:dehilite()
cb := if(nCb == 1, b1, b2)
cb:hilite()
dispbox(cb:nTop-1,cb:nLeft-1,cb:nBottom+1,cb:nRight+1,;
B_DOUBLE, c_[nCb])
@ cb:nTop-1,cb:nLeft+1 say left(aFiles_[nCb],35) color c_[nCb]
endif
case nKey == K_F8
// Sort the array in current window
nKey := ALERT("Select a different sort order.", ;
{"Filename", "Extension", "Date" })
do case
case nKey == 1
//---------------[ FileName ]-------------------
asort( contents_[nCb],,, ;
{ |a,b| a[F_NAME] < b[F_NAME] } )
case nKey == 2
//---------------[ Extension ]------------------
asort( contents_[nCb],,, ;
{ |a,b| if( ext(a[F_NAME]) == ext(b[F_NAME]), ;
a[F_NAME] < b[F_NAME], ;
ext(a[F_NAME]) < ext(b[F_NAME]) ) } )
case nKey == 3
//----------------[ Date ]----------------------
asort( contents_[nCb],,, ;
{ |a,b| if( a[4] == b[4], ;
a[F_NAME] < b[F_NAME], ;
a[4] < b[4]) } )
endcase
cb:refreshall()
case nKey == K_ESC
exit
endcase
endif
ENDDO
setcursor(ncursor)
restscreen( ,,,, scrn )
setcolor(cCol)
RETURN NIL
#ifdef BLINKER
// View compressed file internal to other (based on extension here!)
STATIC FUNCTION ViewFile( cMainFile, cInternal, aMethods_ )
STATIC Istemp := .F. // Whether temp directory created.
LOCAL cCommand, cExtension, n, cCurDir, cScrn, nBkSlsh
cExtension := upper(right(cMainFile,3))
IF ( n := ascan( aMethods_, { |a_| a_[1] == cExtension } ) ) != 0
cCurDir := '\' + CURDIR()
if ! ISDIR( 'TEMP' )
Istemp := MKDIR( 'TEMP' )
else
Istemp := .T.
endif
IF Istemp
// Build extraction command with file and dump to TEMP <dir>
cCommand := aMethods_[ n ][ 2 ]
cCommand := strtran( cCommand, '[COMPFILE]', cMainFile )
cCommand := strtran( cCommand, '[FILENAME]', cInternal )
cCommand += ' >NUL'
cScrn := SAVESCREEN(0,0,maxrow(),maxcol())
// Check to make sure this is not a file in a nested directory
// If there is a /, remove the path info from the filename.
cInternal := IF( ( nBkSlsh := RAT( '/', cInternal) ) <> 0, ;
STUFF( cInternal, 1, nBkSlsh, ''), cInternal )
IF cExtension == 'ARJ' .OR. cExtension == 'LZH'
CHDIR( 'TEMP' )
ENDIF
IF SWPRUNCMD( cCommand, 0, "", "")
CHDIR( 'TEMP' )
IF FILE( cInternal ) .AND. IsTextFile( cInternal )
Text_Browse( cInternal )
ENDIF
FERASE( cInternal )
ENDIF
CHDIR( cCurDir )
RESTSCREEN(,,,,cScrn)
ENDIF
ENDIF
RETURN NIL
#endif