;-----------------------------------------------------------------------------
; TITLE        : Install
; VERSION      : 1.0
; DATE         : 28.08.1999
; DESCRIPTION  : Installer script for DelfInit
; INPUT        : -
; OUTPUT       : -
;-----------------------------------------------------------------------------
; MODIFICATIONS:
; 19.07.2000 Modification
;  Installation texts updated
;
; 31.07.2000 Modification
;  Installation texts updated
;-----------------------------------------------------------------------------
; LIMITATIONS AND BUGS
; 28.08.1999 Limitation
;  Doesn't install DelfInit command call to the user-startup file
;-----------------------------------------------------------------------------

; $VER: Install 1.0 (28.08.1999)

;-----------------------------------------------------------------------------
; VARIABLES VARIABLES VARIABLES VARIABLES VARIABLES VARIABLES VARIABLES VARIA
;-----------------------------------------------------------------------------
(set #config_ok 1)                       ; Default: configuration is ok
(set #cpu "???(20|30|40|60)")            ; Required CPU
(set #installer_ver 43)                  ; Minimum Installer version
(set #installer_rev 3)                   ; Minimum Installer revision
(set #os_ver 40)                         ; Minimum OS version
(set #os_rev 10)                         ; Minimum OS revision
(set #appsize 1000000)                   ; Required diskspace for application
                                         ; (bytes)
(set #configcheckmask %001)              ; Configuration check mask:
                                         ; bit0 (right)  = cpu
                                         ; bit1 (middle) = os version
                                         ; bit2 (left)   = disk space
(set #application "DelfInit")            ; Application

; Default language (English)
(set #string1 ("\nInstaller version %ld.%ld required.\nPlease check your configuration." #installer_ver #installer_rev))
(set #string2 ("\n%s\n\nCopyright © 1999-2000 Janne Peräaho.\nAll Rights Reserved." #application))
(set #string3 ("\n%s has now been installed.\nRead DelfInit.guide for instructions how to autoinitialize Delfina." #application))
(set #string4 "\nAt least 68020 CPU, Installer version 43.3 and delfina.library required.\n\nPlease check your configuration.")
(set #string5 "\nSelect components to be installed.")
(set #string50 "\nSOFTWARE COMPONENTS\n\nDelfInit package consists of binary executable (DelfInit) and Amiga guide documentation (DelfInit.guide).\n\nIn this section you may select the prefered software components to be installed.")
(set #string51 "DelfInit      (about 14 kB)")
(set #string52 "Documentation (about 20 kB)")
(set #string60 "\nSelect target directory for DelfInit (Delfina/bin directory recommended).")
(set #string61 "\nINSTALLING DELFINIT\n\nDelfInit command will be copied to the selected directory.")
(set #string62 "C:Delfina/bin/")
(set #string63 "\nSelect target directory for DelfInit documentation (Delfina/Docs directory recommended).")
(set #string64 "\nINSTALLING DELFINIT DOCUMENTATION\n\nDelfInit.guide and it's icon will be copied to the selected directory.")
(set #string65 "C:Delfina/Docs")
(set #string70 "\nInstalling DelfInit...")
(set #string71 "\nINSTALLING DELFINIT\n\nDelfInit command will be copied into the target directory.")
(set #string72 "DelfInit")
(set #string73 "#?")
(set #string74 "\nInstalling DelfInit documentation...")
(set #string75 "\nINSTALLING DOCUMENTATION\n\nDelfInit.guide and DelfInit.guide.info will be copied into the target directory.")
(set #string76 "")
(set #string77 "DelfInit(.guide|.guide.info)")

; Finnish language
(if (= @language "suomi")
   (
      (set #string1 ("\nAsennukseen tarvitaan Installer-ohjelman versio %ld.%ld." #installer_ver #installer_rev))
      (set #string2 ("\n%s\n\nOhjelmiston oikeudet © 1999-2000 omistaa Janne Peräaho.\nKaikki oikeudet pidätetään." #application))
      (set #string3 ("\n%s on nyt asennettu.\nJos haluat aktivoida Delfinan automaattisesti jokaisen käynnistyksen yhteydessä, lue asennusohjeet DelfInit-dokumentaatiosta (DelfInit.guide)." #application))
      (set #string4 "\nDelfInit vaatii vähintään 68020 CPU:n, Installer (versio 43.3) -ohjelman ja delfina-kirjaston.")
      (set #string5 "\nValitse ne ohjelmiston osat, jotka haluat asentaa.")
      (set #string50 "\nOHJELMISTON OSAT\n\nDelfInit-paketti koostuu ajokelpoisesta binääritiedostosta (DelfInit) ja Amiga guide -formaatissa olevasta dokumentaatiosta (DelfInit.guide).\n\nVoit valita haluamasi ohjelmiston osat, jotka asennetaan.")
      (set #string51 "DelfInit      (noin 14 kt)")
      (set #string52 "Dokumentaatio (noin 20 kt)")
      (set #string60 "\nValitse kohdehakemisto DelfInit-ohjelmalle (suositus: Delfina/bin-hakemisto).")
      (set #string61 "\nDELFINIT:N ASENNUS\n\nDelfInit-komento kopioidaan valittuun hakemistoon.")
      (set #string62 "C:Delfina/bin/")
      (set #string63 "\nValitse kohdehakemisto DelfInit-dokumentaatiolle (suositus: Delfina/Docs-hakemisto).")
      (set #string64 "\nDELFINIT-DOKUMENTAATION ASENNUS\n\nDelfInit.guide ja sen ikoni kopioidaan valittuun hakemistoon.")
      (set #string65 "C:Delfina/Docs")
      (set #string70 "\nDelfInit:n asennus...")
      (set #string71 "\nDELFINIT:N ASENNUS\n\nDelfInit-komento kopioidaan kohdehakemistoon.")
      (set #string72 "DelfInit")
      (set #string73 "#?")
      (set #string74 "\nDelfInit-dokumentaation asennus...")
      (set #string75 "\nDOKUMENTAATION ASENNUS\n\nDelfInit.guide ja DelfInit.guide.info kopioidaan kohdehakemistoon.")
      (set #string76 "")
      (set #string77 "DelfInit(.guide|.guide.info)")
   )
); if

;-----------------------------------------------------------------------------
; SUBROUTINES SUBROUTINES SUBROUTINES SUBROUTINES SUBROUTINES SUBROUTINES SUB
;-----------------------------------------------------------------------------
;-----------------------------------------------------------------------------
; TITLE        : p_DecodeVersion
; VERSION      : 0.10
; DATE         : 30.08.1998
; DESCRIPTION  : Get version and revision from raw version number
; INPUT        : #version - raw version number
; OUTPUT       : #ver     - version number
;                #rev     - revision number
;-----------------------------------------------------------------------------
; MODIFICATIONS: -
;-----------------------------------------------------------------------------
(procedure p_DecodeVersion #version
   (set #ver (/ #version 65536))
   (set #rev (- #version (* #ver 65536)))
)

;-----------------------------------------------------------------------------
; TITLE        : p_EncodeVersion
; VERSION      : 0.10
; DATE         : 30.08.1998
; DESCRIPTION  : Create raw version number from version and revision number
; INPUT        : #ver     - version number
;                #rev     - revision number
; OUTPUT       : #version - raw version number
;-----------------------------------------------------------------------------
; MODIFICATIONS: -
;-----------------------------------------------------------------------------
(procedure p_EncodeVersion #ver #rev
   (set #version (+ (* #ver 65536) #rev))
)

;-----------------------------------------------------------------------------
; TITLE        : p_CheckConfiguration
; VERSION      : 0.10
; DATE         : 30.08.1998
; DESCRIPTION  : Check if requirements match with current configuration
; INPUT        : -
; OUTPUT       : #config_ok - 0=not ok, 1=ok
;-----------------------------------------------------------------------------
; MODIFICATIONS: -
;-----------------------------------------------------------------------------
(procedure p_CheckConfiguration

   ; Variables
   (set #config_ok 1)

   ; Check CPU
   (if (in #configcheckmask 0)
      (
         (if (not (patmatch #cpu (database "cpu")))
            (
               (set #config_ok 0)
            )
         ); if
      )
   ); if

   ; Check OS version
   (if (in #configcheckmask 1)
      (
         (p_EncodeVersion #os_ver #os_rev)
         (if (< #version (getversion))
            (set #config_ok 0)
         ); if
      )
   ); if

   ; Check diskspace
   (if (in #configcheckmask 2)
      (
         (set #availdspace (getdiskspace @default-dest))
         ; Information not available
         (if (not (< #availdspace 0))
            ; Not enough room
            (if (< #availdspace #appsize)
               (set #config_ok 0)
            ); if
         ); if
      )
   ); if

); p_CheckConfiguration

;-----------------------------------------------------------------------------
; TITLE        : p_GetDestination
; VERSION      : 0.10
; DATE         : 30.08.1998
; DESCRIPTION  : Get destination directory
; INPUT        : -
; OUTPUT       : @default-dest
;-----------------------------------------------------------------------------
; MODIFICATIONS: -
;-----------------------------------------------------------------------------
(procedure p_GetDestination #d1string #d2string #d3string

   (set @default-dest
      (askdir
         (prompt #d1string)
         (help #d2string)
         (default #d3string)
         (disk)
      ); askdir
   )
); p_GetDestination

;-----------------------------------------------------------------------------
; TITLE        : p_CopyFiles
; VERSION      : 0.10
; DATE         : 30.08.1998
; DESCRIPTION  : Copy files
; INPUT        : -
; OUTPUT       : -
;-----------------------------------------------------------------------------
; MODIFICATIONS: -
;-----------------------------------------------------------------------------
(procedure p_CopyFiles #c1string #c2string #c3string #c4string

   (copyfiles
      (prompt #c1string)
      (help #c2string)
      (source #c3string)
      (dest @default-dest)
      (pattern #c4string)
      (optional "force")
   ); copyfiles

); p_CopyFiles

;-----------------------------------------------------------------------------
; MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN
;-----------------------------------------------------------------------------
; Welcome message
(welcome #string2)

; Check Installer version
(p_EncodeVersion #installer_ver #installer_rev)
(if (< @installer-version #version)
   (
      (exit #string1 (quiet))
   )
); if

; Ask options
(set #installoptions
   (askoptions
      (prompt #string5)
      (help #string50)
      (choices #string51 #string52)
      (default %11)
   ); askoptions
)

; First option (#string51)
(if (in #installoptions 0)
   (
      ; Get destination directory
      (p_GetDestination #string60 #string61 #string62)

      ; Check configuration
      (p_CheckConfiguration)
      (if (< #config_ok 1)
         (exit #string4 (quiet))
      ); if

      ; Copy files
      (p_CopyFiles #string70 #string71 #string72 #string73)
   )
); if

; Second option (#string52)
(if (in #installoptions 1)
   (
      ; Get destination directory
      (p_GetDestination #string63 #string64 #string65)

      ; Check configuration
      (p_CheckConfiguration)
      (if (< #config_ok 1)
         (exit #string4 (quiet))
      ); if

      ; Copy files
      (p_CopyFiles #string74 #string75 #string76 #string77)
   )
); if

; All done
(exit #string3 (quiet))
