.KEY dest,help/s
.BRA {
.KET }

; :ts=3
; HDInstall - Install Professional Calc onto a hard drive.
;
; Inputs:
;    dest   Directory to install ProCalc into
;    help   Print instructions
;

Assign PCalcInstOrig: ""
Echo >ram:BlottoCD "CD PCalcInstOrig:"

; Make sure he's running WB 1.3!
; Under 1.3, the "1 gt 2" test fails; we proceed to "FAILAT 10".
; Under 1.2, however, the IF command itself dies, since GT is not defined;
; execution is not suspended, and the ECHO and SKIP are seen.
FAILAT 21
IF >NIL: 1 gt 2
        ECHO "*NVersion 1.3 of the Amiga Workbench software *E[;1mmust*E[m be"
        ECHO "present before this installation can proceed.*N"
        SKIP wrapup
ENDIF
FAILAT 10

; Start with a fresh copy, to avoid any potential problems
IF EXISTS RAM:PCalcInstall
   DELETE RAM:PCalcInstall all quiet
ELSE
   MAKEDIR RAM:PCalcInstall
ENDIF


IF EXISTS C:COPY
   C:COPY  C:Copy  RAM:PCalcInstall
ENDIF
CD ram:PCalcInstall    ; Search it without adding it to path
IF EXISTS C:Assign
   Copy C:Assign                   RAM:PCalcInstall
ENDIF
IF EXISTS C:Echo
   Copy C:Echo                     RAM:PCalcInstall
ENDIF
IF EXISTS C:FailAt
   Copy C:FailAt                   RAM:PCalcInstall
ENDIF
IF EXISTS C:If
   Copy C:If                       RAM:PCalcInstall
ENDIF
IF EXISTS C:Else
   Copy C:Else                     RAM:PCalcInstall
ENDIF
IF EXISTS C:Endif
   Copy C:Endif                    RAM:PCalcInstall
ENDIF
IF EXISTS C:Makedir
   Copy C:Makedir                  RAM:PCalcInstall
ENDIF
IF EXISTS C:Execute
   Copy C:Execute                  RAM:PCalcInstall
ENDIF

COPY ProCalc:misc RAM:PCalcInstall all quiet

Assign PCalcInst:       ; Make sure these start fresh, too.

;
; Make sure needed system assignments exist.
;
INSTUTIL isdir T:
IF WARN
   INSTUTIL isdir RAM:T
   IF WARN
      MAKEDIR ram:T
   ENDIF
   ASSIGN T: ram:T
ENDIF

INSTUTIL isdir ENV:
IF WARN
   INSTUTIL isdir RAM:ENV
   IF WARN
      MAKEDIR ram:ENV
   ENDIF
   ASSIGN ENV: ram:ENV
ENDIF


;
; HELP processing
;
IF "{help}" eq "HELP"
   SKIP showme
ENDIF

INSTUTIL ask -dy "Do you need instructions [Y/N]? Y"
IF WARN
   SKIP noshow
ENDIF

LAB showme
   ProCalc:showme ProCalc:HELP-Install
LAB noshow


;
; Make sure that the destination exists, that its name is
; in a useable form (ie. that it ends with a '/' if it's a directory),
; and that the user in fact wants to install into it.
;
IF NOT EXISTS "{dest$SYS:}"
   ECHO "*N ********** Couldn't find Hard Disk drawer {dest$SYS:} **********"
   SKIP forhelp
ENDIF

INSTUTIL isdir "{dest$SYS:}"
IF WARN
   CD RAM:PCalcInstall
   ECHO "*N ********** {dest$SYS:} is not a drawer! **********"
LAB forhelp
   ECHO "*N For help, type"
   ECHO "      EXECUTE ProCalc:HDInstall help"
   ECHO "*N or double-click on the *"Help-Install*" icon in this drawer*N"
   SKIP wrapup
ENDIF
CD RAM:PCalcInstall

ECHO "*N Answering *"No*" to the following question will cancel"
ECHO " the installation.  Your hard drive will not be changed.*N"
INSTUTIL ask -dy "Install Professional Calc onto {dest$SYS:} [Y/N]? Y"
IF warn
   ECHO " Installation aborted!*N"
   SKIP wrapup
ENDIF

ECHO >ram:PCalcInstall/DestPath1 "{dest$SYS:}"
INSTUTIL <ram:PCalcInstall/DestPath1 >ram:PCalcInstall/DestPath2 fixdir

ASSIGN >nil: PCalcInstDest: "{dest$SYS:}"

ECHO "*N*N ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*N"
ECHO " Begin installation of Professional Calc onto {dest$SYS:}*N"

INSTUTIL >ram:PCalcInstall/TempScript mergenl "==EXECUTE >nil: ram:PCalcInstall/Install-Proc """ ram:PCalcInstall/DestPath2 "=="""
EXECUTE ram:PCalcInstall/TempScript

ECHO "*N --------------------------------------------------------------------"
ECHO "*N*N Installation of Professional Calc complete."
ECHO "*N ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*N"

;
; Clean up after ourselves
;
LAB wrapup

Execute RAM:blottoCD
DELETE RAM:blottoCD quiet

Assign PCalcInst:
Assign PCalcInstDest:
Assign PCalcInstOrig:

RAM:PCalcInstall/InstUtil ask "Press RETURN."
IF EXISTS RAM:PCalcInstall
    DELETE >NIL: RAM:PCalcInstall all quiet
ENDIF

