;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Install Scion Genealogist Version 4
;;;
;;; $VER: Install_Scion 1.0 (1 Apr 1995)
;;;
;;; This is the installation script for Scion Genealogist version 4.
;;;
;;; Copyright © 1993-1995 Robbie J Akins, Wellington, New Zealand.
;;; All Rights Reserved
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(set TESTING 0) ; 1 = test mode (relatively safe, 0 = distribution mode

(if (= TESTING 1)
    (user 2))	; Force "expert" mode regardless of installer defaults. Naughty!

(set @user-level 2) ; "Expert" mode preferred

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Initialize variables
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
(set ProgramName	"Scion Genealogist")		; programme name
(set ProgramBaseName	"Scion")			; programme base name
(set VersionNum		"4.07")				; programme version number

(set PrefsName		"Scion Preferences")		; preferences programme name
(set PrefsBaseName	"ScionPrefs")			; preferences programme base name
(set PrefsVersionNum	"1.06")				; preferences programme version number

(set ArchiveName	"ScionSupport.lha")		; archive name
(set ArchiveLocn	"")				; archive location
(set ScionArchive (tackon ArchiveLocn ArchiveName))

(set ArexxArchiveName	"ScionArexx.lha")		; archive name
(set ArexxArchiveLocn	"")				; archive location
(set ArexxArchive (tackon ArexxArchiveLocn ArexxArchiveName))

(set InstallScion	0)		; 1 = install, 0 = don't install
(set InstallPrefs	0)		; 1 = install, 0 = don't install
(set InstallArexx	0)		; 1 = install, 0 = don't install
(set InstallOnlineHelp	0)		; 1 = install, 0 = don't install
(set InstallExample	0)		; 1 = install, 0 = don't install
(set InstallReadMe	0)		; 1 = install, 0 = don't install
(set InstallScionCats	0)		; 1 = install, 0 = don't install
(set InstallPrefsCats	0)		; 1 = install, 0 = don't install

(set InstallEnglish	0)		; 1 = install, 0 = don't install
(set InstallDutch	0)		; 1 = install, 0 = don't install
(set InstallGerman	0)		; 1 = install, 0 = don't install
(set InstallNorwegian	0)		; 1 = install, 0 = don't install
(set InstallItalian	0)		; 1 = install, 0 = don't install
(set InstallSwedish	0)		; 1 = install, 0 = don't install
(set InstallFrench	0)		; 1 = install, 0 = don't install
(set Localised		0)		; 1 = localised, 0 = only english

; Set whether wish to confirm lha extraction was okay
(set xconfirmCopy	0)		; 1 = don't confirm, 0 = confirm
(set delscionarchive 0)			; 1 = delete archive, 0 = don't
(set delarexxarchive 0)			; 1 = delete archive, 0 = don't

;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; English and foreign language messages and "variables"
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; NOTE: The next three variables must appear before the rest of the strings
(set #ArexxScripts	"ARexx Scripts")
(set #OnLineHelp	"On-line Help")
(set #Example		"Example Database")
(set #CatFiles		"Language Support Files")
(set #ReadmeFiles	"Documentation Files")

(set #copyingscion	"Copying the Scion archive to RAM:...")
(set #copyingarexx	"Copying the ARexx archive to RAM:...")
(set #copy_err1		"An error occurred during the copying of %s")
(set #err_msg (cat	"\n\n"
			"Press the Proceed button to stop the installation procedure.\n"))
(set #install_msg (cat "\n\nScion Genealogist installation script.\n\n"
			"This script installs Scion Genealogist\n"
			(" Version %s on your Amiga, " VersionNum)
			"along with associated support files.\n\n"
			"Scion Genealogist © 1993-1995 Robbie Akins\n"
			"All rights reserved."))

(set #dirselect		"Please select the directory where you want to install %s.")
(set #prevselect (cat	"Please chose the location where %s is currently located "
			"so that %s can be installed in the correct location."))
(set #setDirPathHelp (cat "This part of the installation is asking you where you "
			"would like to place %s.\n\nFor current %s owners, you "
			"should select the directory that is the current location "
			"of %s. If you choose a different location, then the "
			"current (existing) module(s) will be in a different "
			"place than the newly-installed module(s).\n"))

(set #setPrevLocHelp (cat "This part of the installation is asking you where "
			"to place %s.\n\nFor current %s owners, you must "
			"select the directory that is the current location "
			"of %s. If you choose a different location, then the "
			"%s will not be installed in the correct place and "
			"hence will not be available.\n\nYou CAN install "
			"%s before installing %s, but you must select the "
			"directory where you eventually intend to install %s.\n"))
(set #setPrevLocHelp (#setPrevLocHelp #OnLineHelp ProgramName ProgramName #OnLineHelp #OnLineHelp ProgramName ProgramName))
(set #pathhelpextra (cat "\n"
			"NOTE: If you will using the Installer program's "
			"function to create a new directory (using \"Make New Drawer...\"), "
			"it is highly recommended that you DO NOT include "
			"spaces in the drawer name.  Following this advice "
			"will avoid any problems accessing the directory, "
			"especially from ARexx scripts.\n"
			"\n"
			@askdir-help))
(set #installing "Installing...")

(set #lha_error1 	"Error decompressing %s from %s into the %s directory.\n")
(set #lha_error2 (cat	"\n"
			"Be sure that the directory you have specified as the "
			"destination exists and has enough free space in it "
			"to accept new files. Also be sure that if the file to "
			"be copied already exists, that the existing file "
			"isn't protected from being overwritten or deleted."))
(set #ver_err1		("\%s version %s requires at least AmigaOS 2.04 to run." ProgramName VersionNum))
(set #installoptions (cat ("Select the parts of the %s package you want to install " ProgramName)
			"at this time."))
(set #installopthelp (cat "This part of the installation procedure lets you select the "
			"parts of the distribution you want to install at this time.\n"
			"\n"
			@askoptions-help))
(set #languageoptions (cat "Select those languages that you want to install at this time.\n\n"
			"NOTE: Not all languages are fully supported."))
(set #languageopthelp (cat "This part of the installation procedure lets you select the "
			"languages that you want to install at this time.\n\n"
			"Not all languages are fully supported, so even if you "
			"select a particular language, on-line help and/or "
			"'localization' may not actually be available at this "
			"time. If you would like to help with a translation, "
			"please contact the author.\n\n"
			@askoptions-help))
(set #libcopy 		"Copying %s to %s")
(set #copyLibFileHelp (cat "If you already have a copy of this library in the "
			"selected destination directory, the library included "
			"on the distribution disk will be compared to the one "
			"you already have. If your current library is an old "
			"version, the newer version will be installed.\n\n"
			@copylib-help))
(set #makedir 		"The directory that has been specified does not exist and is about to be created.")
(set #nolocale		"\n\n\nYour computer does not have support for languages other than English, and so only the English version of the distribution will be installed.")
(set #fontprompt (cat	"\n\nDo you want to install \"sciongen.font\"?\n\nIt is not "
			"required, but makes the user-interfaces look better!"))
(set #fonthelp1 (cat	"\"sciongen.font\" is not required for %s to function, "
			"however, it makes the user-interface look a lot better "
			"if you do decide to install it."))
(set #fonthelp		(#fonthelp1 programname))
(set #oldscionprompt (cat "\n\nYou currently have version %ld.%s of %s installed "
                        "in the directory you have selected. Do you want to "
			"replace it with version %s?"))
(set #oldscionhelp (cat "The directory that you have selected already has a "
                        "copy of %s installed. If you wish to overwrite this "
			"existing copy with version %s, select \"Yes\". "
			"If you select \"No\", you will be asked to once again "
			"select the location where you want to install the "
			"programme. Select another destination if you do not "
			"want to overwrite your existing copy."))

;=============================================================================
; Dutch strings
;
(if (= @language "nederlands")
;(
; Include the Dutch versions of above strings in here.
;)
)
;
;=============================================================================
; German strings
;
(if (= @language "deutsch")
;(
; Include the German versions of above strings in here.
;)
)
;
;=============================================================================
; Norwegian strings
;
(if (= @language "norsk")
;(
; Include the Norwegian versions of above strings in here.
;)
)
;
;=============================================================================
; Italian strings
;
(if (= @language "italiano")
;(
; Include the Italian versions of above strings in here.
;)
)
;
;=============================================================================
; Swedish strings
;
(if (= @language "svenska")
;(
; Include the Swedish versions of above strings in here.
;)
)
;
;=============================================================================
; French strings
;
(if (= @language "français")
;(
; Include the French versions of above strings in here.
;)
)
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Some useful procedures
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Ask the user for a directory name.
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; INPUTS:
;    SDP_ModuleName    ; Name of 'module' to install
;    SDP_DefDir        ; Default directory to start with
;
;    #setDirPathHelp   ; Any help text. Note: This is set globally at the start.
;
; OUTPUTS:
;    SDP_DirPath       ; The selected directory
;
(procedure setDirPath
    (
    (set moveon    FALSE)
    (while (NOT moveon)
        (
        (set SDP_DirPath
            (askdir    (prompt    (#dirselect SDP_ModuleName))
                (help (#setDirPathHelp SDP_ModuleName ProgramBaseName SDP_ModuleName) #pathhelpextra)
                (default SDP_DefDir)
                (newpath)
            )
        )

        ; Don't try and create directory in pretend mode (gets stuck in a loop!)
        (if (<> @pretend 1)
            (
                (if (= (exists SDP_DirPath) 0)
                    (makedir SDP_DirPath
                        (prompt #makedir)
                        (help @makedir-help)
                        (confirm)
                        (infos)
                    )
                    (set moveon    TRUE)
                )
            )(set moveon TRUE))
        )
    )
    )
)

;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Ask user where Scion was previously installed so help can be installed correctly
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; INPUTS:
;    SPL_ModuleName    ; Name of 'module' to install (#OnLineHelp)
;    SPL_DefDir        ; Default directory to start with
;
;    #setPrevLocHelp   ; Any help text. Note: This is set globally at the start.
;
; OUTPUTS:
;    SPL_DirPath       ; The selected directory
;
(procedure setPrevLoc
    (
    (set SPL_DirPath
        (askdir    (prompt    (#prevselect ProgramName SPL_ModuleName))
            (help (#setPrevLocHelp))
            (default SPL_DefDir))
        )
    )
)

;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Extract a file from an 'lha' archive file using 'lx'
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; INPUTS:
;    xarcFileName    ; Name of archive (eg "fred.lha")
;    xsrcFileName    ; Name of file within archive (including "internal" dir structure)
;    xdestDirName    ; "Base" location to copy file to (will recreate "internal"
;                      dir structure of archive)
;    xconfirmCopy    ; 0 = confirm extraction okay, else don't confirm
;
(procedure extractLhaFile2Dir
    (
    (set lha_rc (run ("lx -qf x %s \"%s\" \"%s\"" xarcFileName xsrcFileName xdestDirName)))
    (if (<> lha_rc 0)
        (message
            (#lha_error1 xsrcFileName xarcFileName xdestDirName) #lha_error2
        )
    )
    (if (= 0 xconfirmCopy)
        (
        (if (= 0 (exists (tackon xdestDirName xsrcFileName)))
            (abort (#copy_err1 xsrcFileName) #err_msg)
        )
	)
    )
    )
)

;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Fix up "lha" destinations which must end with ":" or "/"
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; INPUTS:
;    xdestDirName    ; "Base" location to fix up
;
(procedure fixLhaDest
(set len (strlen xdestDirName))
(if (<> (substr xdestDirName (- len 1) 1) ":")
    (set xdestDirName (cat xdestDirName "/")))
)

;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Ask the user which parts of the package should be installed.
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
(procedure setPkgOpts
    (
    (set PkgOpts
        (askoptions
            (prompt #installoptions)
            (help #installopthelp
            )
            (choices
                ; bit position 0 -- install Scion ( AND ReadMe files)
                ;
                ("%s" ProgramName)

                ; bit position 1 -- install ScionPrefs
                ;
                ("%s" PrefsName)

                ; bit position 2 -- install ARexx scripts
                ;
                ("%s" #ArexxScripts)

                ; bit position 3 -- install Guides
                ;
                ("%s" #OnLineHelp)

                ; bit position 4 -- install Example database
                ;
                ("%s" #Example)

            )
        )
    )
    )
)

;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Ask the user which languages should be installed.
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
(procedure setLanguages
    (
    (set LanguageOpts
        (askoptions
            (prompt #languageoptions)
            (help #languageopthelp)

            (choices
                ; bit position 0 -- install English
                ;
                "English"

                ; bit position 1 -- install Dutch
                ;
                "Nederlands"

                ; bit position 2 -- install German
                ;
                "Deutsch"

                ; bit position 3 -- install Norwegian
                ;
                "Norsk"

                ; bit position 4 -- install French
                ;
                "Français"

                ; bit position 5 -- install Italian
                ;
                "Italiano"

                ; bit position 6 -- install Swedish
                ;
                ;"Svenska" NOTE: Not currently supported

	    )
        )
    )
    )
)

;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Copy the specific library file from T: to the CLF_LibPath directory.
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; INPUTS:
;    CLF_LibFileName     ; Library name
;    CLF_LibPath         ; Location to save library
;
;    #copyLibFileHelp    ; 'Base" help for this operation
;
(procedure copyLibFile
    (
    (if (= (exists (tackon CLF_LibPath CLF_LibFileName)) 1)
        (
        (protect (tackon CLF_LibPath CLF_LibFileName) "+rwed")
        )
    )
    (if (<> @pretend 1)
        (copylib
            (prompt (#libcopy CLF_LibFileName CLF_LibPath))
            (help    #copyLibFileHelp)
            (source (cat "T:" CLF_LibFileName))
            (dest CLF_LibPath)
            (confirm))
        )
    )
)

;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Get the version and revision number of file/device/library/OS/etc
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; INPUTS: WV_Item	; Name of device/file/library/etc. "" for OS version
;
; OUTPUTS: WV_VerNum	; (long) version/revision number
;          WV_Ver	; Version number
;          WV_Rev	; Revision number
; NOTE: Both WV_Ver and WV_Rev returned as 0 if "WV_Item" does not exist
;
(procedure WhatVersion
    (
    (if (= WV_Item "")
        (set WV_VerNum (getversion))		; For OS
        (set WV_VerNum (getversion WV_Item)))	; For other "files"
    (set WV_Ver (/ WV_VerNum 65536))
    (set WV_Rev (- WV_VerNum (* WV_Ver 65536)))
    )
)

;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Fix revision numbers because I use 'x.05' style instead of 'x.5' style
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; INPUTS:  WV_Rev	; Revision number
;
; OUTPUTS: FR_Rev	; Revision # modified to give leading '0' where needed
;
(procedure FixRevision
    (
    (if (< WV_Rev 10)
        (set FR_Rev (cat "0" WV_Rev))
	(set FR_Rev (cat WV_Rev))
    )
))

;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; See if Multiview and/or AmigaGuide exist
;;;
;;; This is less than perfect! I can't get "run" to return a command result
;;; from the "which" command when run from Workbench! Okay from a shell.
;;; I wanted to use "which"command to locate viewer, but doesn't bloody work!
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; OUTPUT: ViewerType = 1 for MultiView (preferred)
;                    = 2 for AmigaGuide
;                    = 0 for neither
;
(procedure WhichGuideViewer
    (
    (if (= (exists "SYS:Utilities/MultiView" (noreq)) 1)
        (set ViewerType 1)
        (if (= (exists "SYS:Utilities/AmigaGuide" (noreq)) 1)
            (set ViewerType 2)
	(set ViewerType 0)))
    )
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;                                                                       ;;;
;;;                START OF ACTUAL INSTALLATION PROCESS                   ;;;
;;;                                                                       ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Make sure we are running under a 2.04 ROM (at least)
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;

(set WV_Item "")	; Want OS version
(WhatVersion)
(if (< WV_Ver 37)
    (abort (cat #ver_err1 #err_msg))
    )

;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Display startup message and make sure t: exists
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;

(message #install_msg)

(if (= (getassign "t") "")
    (makeassign "t" RAM:)
)

;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Do installation
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;

; Try and determine the best place to set as destination for the installation.
; NOTE: For "novice" mode, the installer uses the value of @default-dest.

(if (= (exists "Work:" (noreq)) 2)          ; Check for WORK:
    (set @default-dest ("Work:%s" ProgramBaseName))
    (set @default-dest ("SYS:%s" ProgramBaseName))
)

; NOTE: For test purposes, over-ride default location with RAM:
(if (= TESTING 1)
    (set @default-dest ("RAM:%s" ProgramBaseName)))

(set Scion-dest @default-dest)              ; Default location to install Scion programme
(setPkgOpts)                                ; Ask for installation options

(if (= (exists "LIBS:locale.library" (noreq)) 1) ;Is there locale support?
    (
    (set Localised 1)                       ; Set "localisation" supported
    ; Only ask for languages for Scion, ScionPrefs or On-line help
    (if (OR (IN PkgOpts 0) (IN PkgOpts 1) (IN PkgOpts 3))
        (setLanguages)                      ; Ask for languages to install
        )
    )
    (message #nolocale))                    ; Give bad news about no locale

(set SDP_DefDir @default-dest)              ; Start with default location

;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Set up installation options and destinations for files
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; bit position 0 -- install Scion & ReadMe files
(set Scion_Really 0)                        ; Do NOT install Scion at the moment
(if (IN PkgOpts 0)                          ; if bit position 0 (Scion option) is on
    (
    (while (<> Scion_Really 1)
        (
        (set SDP_ModuleName ProgramBaseName); First module is Scion
        (setdirpath)                        ; Returns user selected location in 'SDP_DirPath'
        (set @default-dest SDP_DirPath)     ; Reset default location (for 'completed' message)

        (set Scion-dest SDP_DirPath)        ; Location to install Scion programme
        (set InstallScion 1)                ; 1 = install Scion
    
        (set readme-dest Scion-dest)        ; Default to "base" location where Scion is
        (set InstallReadMe 1)               ; 1 = install ReadMe files

        (set WV_Item (tackon Scion-dest ProgramBaseName))
        (if (exists WV_Item (noreq))        ; Existing Scion installed?
	    (
            (WhatVersion)                   ; Get existing Scion version number
            (FixRevision)                   ; Kludge for my revision numbering!
            (set Scion_Really (askbool
	        (prompt (#oldscionprompt WV_Ver FR_Rev ProgramName VersionNum)
		(help (#oldscionhelp ProgramName VersionNum))
		(default 1))))
	    )
	    ; 'else'
	    (set Scion_Really 1)            ; Nothing there - really install
        ))
     )
    ))

; bit position 1 -- install ScionPrefs
(if (IN PkgOpts 1)                          ; if bit position 1 (Scion preferences option) is on
    (
    (set SDP_ModuleName PrefsBaseName)      ; Next module is preferences programme
    (set SDP_DefDir "SYS:Prefs")
    (setdirpath)                            ; Returns user selected location in 'SDP_DirPath'

    (set prefs-dest SDP_DirPath)            ; Location to install preferences programme
    (set InstallPrefs 1)                    ; 1 = install preferences
    ))

; bit position 2 -- install ARexx scripts
(if (IN PkgOpts 2)                          ; if bit position 2 (ARexx scripts option) is on
    (
    (set SDP_ModuleName #ArexxScripts)      ; Next 'section' is ARexx scripts

    (if (<> (getassign "REXX") "")
        (set SDP_DefDir "REXX:")            ; Preferred default location is REXX:
        (
	(if (IN PkgOpts 0)                  ; Was Scion location chosen?
	    (set SDP_DefDir (tackon Scion-dest "Rexx")) ; 'Root' is location of Scion
	    (set SDP_DefDir "S:")           ; Last chance default
	)
    ))

    (setdirpath)                            ; Returns user selected location in 'SDP_DirPath'

    (set arexx-dest SDP_DirPath)            ; Location to install ARexx scripts
    (set InstallArexx 1)                    ; 1 = install ARexx scripts
    ))

; bit position 3 -- install Guides
(if (IN PkgOpts 3)                          ; if bit position 3 (On-line help option) is on
    (
    (set InstallOnlineHelp 1)               ; 1 = install ".guide" files
    (if (IN PkgOpts 0)                      ; Installing Scion at this time?
        (
        (set guide-dest Scion-dest)         ; Default to "base" location where Scion is
        )
	; Not installing Scion - ask where it is
	(
        (set SPL_ModuleName #OnLineHelp)
        (set SPL_DefDir scion-dest)
        (setPrevLoc)
	(set guide-dest SPL_DirPath)        ; Set guide "root" location
	(set Scion-dest SPL_DirPath)        ; Reset Scion location
	(set @default-dest SPL_DirPath)     ; Reset default location too!
	))
    ))

; bit position 4 -- install Example database
(if (IN PkgOpts 4)                          ; if bit position 4 ("Example" option) is on
    (
    (if (IN PkgOpts 0)
        (set example-dest Scion-dest)       ; Default to "base" location where Scion is
	; Not installing Scion at this time. Ask for location
	(
        (set SDP_DefDir Scion-dest)         ; Start with Scion's default location
        (set SDP_ModuleName #Example)       ; Ask for Example location
        (setdirpath)                        ; Returns user selected location in 'SDP_DirPath'
        (set example-dest SDP_DirPath)      ; Location to install Example
	))
    (set InstallExample 1)                  ; 1 = install "Example" file
    ))

;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Set up "locale" options and destinations
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;

(if (= Localised 1)                                 ; Is "localisation" support available?
    (

    (if (<> (getassign "LOCALE") "")                ; Is there a LOCALE: assign?
        (
        (set scioncat-dest "LOCALE:")               ; Preferred default location is LOCALE:
        (set prefscat-dest "LOCALE:")               ; Preferred default location is LOCALE:
        )
        (
        ; "else"
        ; Where should we install locales for Scion?
        (if (IN PkgOpts 0)                          ; if bit position 0 (Scion option) is on
            (set scioncat-dest Scion-dest)          ; Location to install Scion catalogs
            )
        ; Where should we install locales for ScionPrefs?
        (if (IN PkgOpts 1)                          ; if bit position 1 (Scion preferences option) is on
            (set prefscat-dest prefs-dest)          ; Location to install preferences catalogs
            )
        ))


    ; Should we install locales for Scion?
    (if (IN PkgOpts 0)                              ; if bit position 0 (Scion option) is on
        (set InstallScionCats 1)                    ; 1 = install Scion catalogs
        )
    ; Should we install locales for ScionPrefs?
    (if (IN PkgOpts 1)                              ; if bit position 1 (Scion preferences option) is on
        (set InstallPrefsCats 1)                    ; 1 = install Preferences catalogs
        )

    (if (IN LanguageOpts 0)                         ; if bit position 0 (English)
        (set InstallEnglish 1))
    (if (IN LanguageOpts 1)                         ; if bit position 1 (Dutch)
        (set InstallDutch 1))
    (if (IN LanguageOpts 2)                         ; if bit position 2 (German)
        (set InstallGerman 1))
    (if (IN LanguageOpts 3)                         ; if bit position 3 (Norwegian)
        (set InstallNorwegian 1))
    (if (IN LanguageOpts 4)                         ; if bit position 4 (French)
        (set InstallFrench 1))
    (if (IN LanguageOpts 5)                         ; if bit position 5 (Italian)
        (set InstallItalian 1))
    (if (IN LanguageOpts 6)                         ; if bit position 6 (Swedish)
        (set InstallSwedish 1))
    )) ;;;;; (if (= Localised 1)


; If on-line help is requested, always install default English .guide file
(if (= InstallOnlineHelp 1)
        (set InstallEnglish 1))
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Copy scion and ARexx archives to RAM: (without asking for confirmation)
;;; if archives are not already on RAM: volume
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;

(if (<> (getdevice ScionArchive) "RAM") ; Are the archives already on RAM:?
    (
    (copyfiles
        (prompt "\n" #copyingscion)
        (source ScionArchive)
        (dest "RAM:"))
    (set delscionarchive 1)		; Set RAM: based file for deletion
    (set ScionArchive (tackon "RAM:" ArchiveName))
    ))

(if (= InstallArexx 1)
    (
    (if (<> (getdevice ArexxArchive) "RAM")
        (
        (copyfiles
            (prompt "\n" #copyingarexx)
            (source ArexxArchive)
            (dest "RAM:"))
        (set delarexxarchive 1)		; Set RAM: based file for deletion
	(set ArexxArchive (tackon "RAM:" ArexxArchiveName))
	))
    ))
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; De-archive the appropriate files to their intended destinations
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; The following installation "flags" and locations are now set appropriately:
; - InstallScion
; - InstallPrefs
; - InstallArexx
; - InstallOnlineHelp
; - InstallExample
; - InstallReadMe
; - Scion-dest             ; Location to install Scion programme
; - prefs-dest             ; Location to install preferences programme
; - arexx-dest             ; Location to install ARexx scripts
; - guide-dest             ; "Base" location to install guide scripts
; - example-dest           ; Location to install example database
; - readme-dest            ; Location to install readme files
;
; NOTE: "language" flags are used for BOTH ".guide" AND ".catalog" files
; NOTE: ALWAYS install English ".guide" if InstallOnlineHelp is set
; - InstallEnglish
; - InstallDutch
; - InstallGerman
; - InstallNorwegian
; - InstallItalian
; - InstallSwedish
; - InstallFrench
; Localised             ; 1 if user's system support localisation
;
; - InstallScionCats
; - InstallPrefsCats
; - scioncat-dest         ; "Base" location to install Scion catalogs
; - prefscat-dest         ; "Base" location to install preferences catalogs
;

; Install Scion
(if (= InstallScion 1)
    (
    (copyfiles
        (prompt "\n" ProgramName)
        (source ProgramBaseName)
        (dest scion-dest)
   	(files)
	(infos))
    ))

; Install Scion Preferences
(if (= InstallPrefs 1)
    (
    (set CurrentFile "ScionPrefs")
    (set MyWorkinMsg (cat #Installing CurrentFile))
    (working MyWorkinMsg)
    (set xarcFileName ScionArchive)
    (set xsrcFileName CurrentFile)
    (set xdestDirName prefs-dest)
    (fixLHADest)
    ; Don't try and de-archive files in pretend mode
    (if (<> @pretend 1)
        (
        (extractLhaFile2Dir)
        ))

    (set CurrentFile "ScionPrefs.info")
    (set MyWorkinMsg (cat #Installing CurrentFile))
    (working MyWorkinMsg)
    (set xsrcFileName CurrentFile)
    ; Don't try and de-archive files in pretend mode
    (if (<> @pretend 1)
        (
        (extractLhaFile2Dir)
        ))
    ))

; Install on-line help as required
(if (= InstallOnlineHelp 1)
    (
    (set xconfirmCopy 1)		; Turn off confirmation for possible omissions
    (set xsrcFileName "guides.info")	; Main drawer icon
    (set MyWorkinMsg (cat #Installing #OnLineHelp))
    (working MyWorkinMsg)
    (set xarcFileName ScionArchive)
    (set xdestDirName guide-dest)
    (fixLHADest)
    ; Don't try and de-archive files in pretend mode
    (if (<> @pretend 1)
        (
        (extractLhaFile2Dir)
        ))
    (set n 0)
    (while (set whichlanguage (select n "English" "Nederlands" "Deutsch" "Norsk" "Italiano" "Svenska" "Français" ""))
        (
	(set dolanguage (select n InstallEnglish InstallDutch InstallGerman InstallNorwegian InstallItalian InstallSwedish InstallFrench 0))
	(set n (+ n 1))
	; Now dearchive appropriate ".guide" files and drawer icons (what a pain!)
        (if (= dolanguage 1)
	    (
	    (set xsrcFileName (cat "guides/" whichlanguage ".info"))
            ; Don't try and de-archive files in pretend mode
            (if (<> @pretend 1)
                (
                (extractLhaFile2Dir)
                ))
	    (set xsrcFileName (cat "guides/" whichlanguage "/Scion.guide#?"))
            ; Don't try and de-archive files in pretend mode
            (if (<> @pretend 1)
                (
                (extractLhaFile2Dir)
                (WhichGuideViewer) ; What guide viewer is available?
                (set scratch (cat "guides/" whichlanguage "/Scion.guide"))
                (set scratch (tackon guide-dest scratch))
                (if (= (exists scratch (noreq)) 1)
		    (
		    ; Set guide viewer tooltype
                    (if (= ViewerType 1)
		        (
			;Set to multiview
			(tooltype
			    (prompt "")
			    (help "")
			    (dest scratch)
			    (setdefaulttool "MultiView"))
			)
			(if (= ViewerType 2)
			    (
			    ;Set to AmigaGuide
			    (tooltype
			        (prompt "")
			        (help "")
			        (dest scratch)
			        (setdefaulttool "AmigaGuide"))
			    )
			    (
			    ;Neither in "SYS:Utilities" - hope that "Amigaguide" is somewhere!
			    (tooltype
			        (prompt "")
			        (help "")
			        (dest scratch)
			        (setdefaulttool "Amigaguide"))
			    ))
		    )))
                ))

	    ))
	))

    ; If installing Scion, install amigaguide.library as well
    (set xsrcFileName "amigaguide.library")
    (set MyWorkinMsg (cat #Installing "amigaguide.library in T:"))
    (working MyWorkinMsg)
    (set xarcFileName ScionArchive)
    (set xdestDirName "T:")
    ; Don't try and de-archive files in pretend mode
    (if (<> @pretend 1)
        (
        (extractLhaFile2Dir)
        ))
    (set CLF_LibFileName "amigaguide.library")
    (set CLF_LibPath "LIBS:")
    (copyLibFile)
    ))
(set xconfirmCopy	0)		; Turn confirmation back on

; Install foreign language catalogs as required
; Firstly for Scion
(if (= InstallScionCats 1)
    (
    (set xconfirmCopy 1)		; Turn off confirmation for possible omissions
    (set MyWorkinMsg (cat #Installing #CatFiles))
    (working MyWorkinMsg)
    (set xarcFileName ScionArchive)
    (set xdestDirName scioncat-dest)
    (fixLHADest)
    (set n 0)
    (while (set whichlanguage (select n "English" "Nederlands" "Deutsch" "Norsk" "Italiano" "Svenska" "Français" ""))
        (
	(set dolanguage (select n InstallEnglish InstallDutch InstallGerman InstallNorwegian InstallItalian InstallSwedish InstallFrench 0))
	(set n (+ n 1))
	; Now dearchive appropriate ".catalog" files
        (if (= dolanguage 1)
	    (
	    (set xsrcFileName (cat "catalogs/" whichlanguage "/scion.catalog"))
            ; Don't try and de-archive files in pretend mode
            (if (<> @pretend 1)
                (
                (extractLhaFile2Dir)
                ))
	    ))
	))
    ))
; Secondly for ScionPrefs
(if (= InstallPrefsCats 1)
    (
    (set xconfirmCopy 1)		; Turn off confirmation for possible omissions
    (set MyWorkinMsg (cat #Installing #CatFiles))
    (working MyWorkinMsg)
    (set xarcFileName ScionArchive)
    (set xdestDirName prefscat-dest)
    (fixLHADest)
    (set n 0)
    (while (set whichlanguage (select n "English" "Nederlands" "Deutsch" "Norsk" "Italiano" "Svenska" "Français" ""))
        (
	(set dolanguage (select n InstallEnglish InstallDutch InstallGerman InstallNorwegian InstallItalian InstallSwedish InstallFrench 0))
	(set n (+ n 1))
	; Now dearchive appropriate ".catalog" files
        (if (= dolanguage 1)
	    (
	    (set xsrcFileName (cat "catalogs/" whichlanguage "/scionprefs.catalog"))
            ; Don't try and de-archive files in pretend mode
            (if (<> @pretend 1)
                (
                (extractLhaFile2Dir)
                ))
	    ))
	))
    ))
(set xconfirmCopy	0)		; Turn confirmation back on

; Install sciongen.font if either Scion or ScionPrefs is being installed
(if (OR (= InstallScion 1) (= InstallPrefs 1))
    (
    (set result (askbool
        (prompt #fontprompt)
	(help #fonthelp)
	(default 1))
    )
    (if (= result 1)
        (
        (set xconfirmCopy 1)		; Turn off confrimation for multiple files
        (set CurrentFile "sciongen#?")
        (set MyWorkinMsg (cat #Installing "sciongen font"))
        (working MyWorkinMsg)
        (set xarcFileName ScionArchive)
        (set xsrcFileName CurrentFile)
        (set xdestDirName "FONTS:")
        ; Don't try and de-archive files in pretend mode
        (if (<> @pretend 1)
            (
            (extractLhaFile2Dir)
            ))
        ))
    ))
(set xconfirmCopy	0)		; Turn confirmation back on

; Install Example database
(if (= InstallExample 1)
    (
    (set CurrentFile "Example")
    (set MyWorkinMsg (cat #Installing CurrentFile))
    (working MyWorkinMsg)
    (set xarcFileName ScionArchive)
    (set xsrcFileName CurrentFile)
    (set xdestDirName example-dest)
    (fixLHADest)
    ; Don't try and de-archive files in pretend mode
    (if (<> @pretend 1)
        (
        (extractLhaFile2Dir)
        ))

    (set CurrentFile "Example.info")
    (set MyWorkinMsg (cat #Installing CurrentFile))
    (working MyWorkinMsg)
    (set xsrcFileName CurrentFile)
    ; Don't try and de-archive files in pretend mode
    (if (<> @pretend 1)
        (
        (extractLhaFile2Dir)
        ))
    ))

; Install ARexx
(if (= InstallArexx 1)
    (
    (set CurrentFile "#?")
    (set MyWorkinMsg (cat #Installing #ArexxScripts))
    (working MyWorkinMsg)
    (set xarcFileName ArexxArchive)
    (set xsrcFileName CurrentFile)
    (set xdestDirName arexx-dest)
    (fixLHADest)
    (set xconfirmCopy 1)		; Turn off confrimation for multiple files
    ; Don't try and de-archive files in pretend mode
    (if (<> @pretend 1)
        (
        (extractLhaFile2Dir)
        ))

    ))

(set xconfirmCopy	0)		; Turn confirmation back on

; Lastly any "readme" files (and icons)
(if (= InstallReadMe 1)
    (
    (set n 0)
    (while (<> (set dolanguage (select n InstallEnglish InstallDutch InstallGerman InstallNorwegian InstallItalian InstallSwedish InstallFrench 99)) 99)
        (
	(set readme_name (select n "ReadMe" "LeesMij" "LiesMich" "LesMeg" "Leggimi" "Swedish???" "Lisez-moi" ""))
	(set n (+ n 1))
	; Now copy appropriate readme file(s)
        (if (AND (= dolanguage 1) (= (exists readme_name (noreq)) 1))
	    (
            (copyfiles
		((optional "nofail" ))	; This doesn't seem to work properly!?
                (prompt "\n" #ReadmeFiles)
                (source readme_name)
                (dest readme-dest)
   	        (files)
	        (infos))
	    ))
	))
    ))

;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Delete files no longer required from RAM: (if they've been copied there)
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;

(if (= delscionarchive 1)
    (delete ScionArchive))
(if (= delarexxarchive 1)
    (delete ArexxArchive))
(exit)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

