G4C  

; ViewFile FileName FileType Mode

; FileName = the File Name
; FileType = the File Type, as returned from the GetFileType routine
; Mode     = (optional) CLI or RUN (RUN is default)

; ======================================================================

xONLOAD filename filetype mode
guiopen viewfile $filename $filetype $mode

xONRELOAD filename filetype mode
guiopen viewfile $filename $filetype $mode


xONOPEN filename filetype mode

if $filename = ''
or $filetype = ''
   return
endif

docase $filetype

; ----- do special cases first.


case   = INFO				; icons
       copy $filename ram:t		; load gui which will show an icon
       ifexists file ram:t/GCXX.info	; named ram:t/GCXX.info
            delete ram:t/GCXX.info
       endif
       extract filename FILE rtn_info2
       joinfile ram:t $rtn_info2 rtn_info
       rename $rtn_info ram:t/GCXX.info
       guiload guis:tools/icon.gc
       guiopen icon.gc
       guiscreen icon.gc front
       return
       break

case   = G4C				; Yes.. you guessed it.
       GuiLoad $filename
       return
       break

case   = PPM				; who knows..
       CLI 'run >NIL: ppm2aga $filename T:temp'
       WAIT FILE T:Temp 1000
       CLI '$DEF.ILBM T:temp'
       RUN 'delete T:temp'
       return
       break

case   = LHA				; LhA - all these are CLI'ied
       cli 'Lha x $filename ram:'
       return
       break

case   = ZIP				; unzip
       cli '$*DEF.UNZIP $filename -d ram:'
       return
       break

case   = EXE				; A program ? - Use cli.gc to run it.
       GuiLoad guis:tools/cli.gc $viewfile/filename RUN
       return
       break

case   = TEXT	                      ; a text file (probably)
       GuiLoad guis:tools/read.gc $viewfile/filename
       return
       break

case   = UNKNOWN
       ; gui to deal with it..
       guiopen ViewFile2
       return
       break

endcase

; If we got this far, then it's one of the simple types such as
; GIF or ILBM etc - We just contruct & issue the command to run it.

com = '\$*DEF.$filetype'       ; construct command name
if $mode == CLI
   CLI '$com $filename' 	
else
   RUN '$com $filename' 	
endif


; routine ends here.

xOnQuit
guiquit ViewFile2


; ######################################################################

	NEWFILE Viewfile2     ; last chance gui

; ######################################################################

WinBig 0 0 80 75 ""
WinType 01001000
winonmouse 40 10
varpath viewfile	; merge variables with the above file

xOnRMB 
guiclose ViewFile2

xOnInactive
guiclose ViewFile2

xOnFail
ezreq "Error during operation" OK ""

;---------------> the Buttons

xbutton 0 0 0 15 MView
guiclose ViewFile2
run 'multiview $filename'

xbutton 0 15 0 15 List
GuiLoad  guis:tools/read.gc $viewfile/filename

xbutton 0 30 0 15 Run
guiclose ViewFile2
run '$filename'

xbutton 0 45 0 15 With..
guiclose ViewFile2
prog = ''
ReqFile  -1 -1 300 220 'Run file with..' LOAD prog c:
if $prog > ''
   run '$prog $filename'
endif

xbutton 0 60 0 15 'CliGui'
guiclose ViewFile2
setvar cl_Main '$filename '
GuiLoad guis:tools/cli.gc $viewfile/filename CLI
setgad cli.gc 1 ON


