;; Install script for Delfina by T. Suikki
;; Based on AHI installer by Martin Blom
 
(set #complete 0)
(set #completeadd (/ 1000 18))	; There are 18 complete statements!

(set #osversion (/ (getversion "exec.library" (resident)) 65536))

(complete (/ #complete 10)) (set #complete (+ #complete #completeadd))


;**
;** All the strings
;**

	(set #t_wc_user		(cat
		" Welcome to Delfina software installation."
		" This archive contains Delfina's user software."
		" Developer material is available on separate archive."
		" You need AHI V4 too, it can be found from the AHI"
		" homepage at http://www.lysator.liu.se/~lcs/ahi.html"
	))
	(set #t_wc_dev		(cat
		" Welcome to Delfina software installation."
		" This archive contains the developer material."
		" User archive should be installed BEFORE this one."
	))
	(set #t_wc_both		" Welcome to Delfina Lite installation.")
	
	(set #t_wrongcpu	(cat
		" Delfina software, including this installer, requires"
		" at least a 68020 processor. Your machine does not have"
		" it, so the software does not work on your machine."
		" If this a real problem with you, contact us to get"
		" 68000 versions.."
	))

	(set #t_oldinstaller	(cat
		" Installer 43.3 or higher is required. You have an older"
		" version. You can find Installer from the Delfina's MUI"
		" disk.\nYou can continue installation, but there is no"
		" guarantee it will works as it's supposed to do."
		" Do you wish to continue anyway?"
	))
	(set #t_oldinstallerhelp (cat
		" The version of Installer you use is too old. You can"
		" find a more recent version on the Internet, for example"
		" on Aminet, in the util/misc directory. The current"
		" file name is \"Installer-43_3.lha\":\n"
		" <URL:ftp://ftp.germany.aminet.org/pub/aminet/util/misc/Installer-43_3.lha"
	
	))
	(set #t_installaborted	"Installation aborted.")

	(set #t_nofiles		"No files to install.")

	(set #t_nohelp		"No help available.")

	(set #t_userparts	"Select parts of user software you wish to install.")
	(set #t_devparts	"Select parts of developer software you wish to install.")
	(set #t_usersoft     	"User software")
	(set #t_userser     	"Serial port driver")
	(set #t_userpar     	"Parallel port driver")
	(set #t_useralab	"Driver for AudioLab16")
	(set #t_userahi		"AHI driver")
	(set #t_userdoc		"User documentation")
	(set #t_devsoft		"Developer software")
	(set #t_devdoc		"Developer documents")
	(set #t_devinc          "Include files")
	(set #t_devsrc		"Example source files")
	(set #t_devhist		"History files for all software")

	(set #t_userhelp	(cat
		"User software:\n"
		" This is the basic package that should always be installed."
		" It contains delfina.library and some applications.\n\n"
		
		"Serial port driver:\n"
		" This is the driver for Delfina's serial port, delfser.device.\n\n"
		
		"Parallel port driver:\n"
		" This is the driver for Delfina's parallel port, delfpar.device.\n\n"

		"Driver for AudioLab16:\n"
		" If you have the Delfina version of AudioLab16, get the new"
		" driver from here.\n\n"

		"User documentation:\n"
		" Software manuals and User's Manual in AmigaGuideŽ format.\n\n"

	))
	(set #t_devhelp		(cat
		
		"Developer software:\n"
		" A56 assembler to compile DSP programs, some CLI utilities.\n\n"
		
		"Developer documents:\n"
		" Autodocs and Developer's Manual in AmigaGuideŽ format.\n\n"
		
		"Include files:\n"
		" Include files for SAS/C, Asm and A56.\n\n"
		
		"Example source files:\n"	
		" Some example programs showing various things to do with Delfina.\n\n"
		
		"History files for all software\n"
		" Version information for most of the files.\n\n"
	))

	(set #t_delfpath	(cat
		" Where do you want to install Delfina software?"
		" A directory called Delfina will be created there."
	))
	(set #t_delfpathhelp	(cat
		" All Delfina applications and documentation are" 
		" copied to this directory.\n\n"
	))
	(set #t_alabpath	(cat
		" In which directory is your AudioLab16? Delfina driver"
		" will be copied to the Drivers/ subdirectory."
	))
	(set #t_libspath	" Where do you want to install delfina.library?")
	(set #t_libspathhelp	" This path must be under your LIBS: assign.\n\n")

	(set #t_devspath	" Where do you want to install delfser and delfpar devices?")
	(set #t_devspathhelp	" This path must be under your DEVS: assign.\n\n")


	(set #t_olddelf		(cat
		" There is already a directory called Delfina here."
		" Some of the old files will be deleted or overwritten."
	))

	(set #t_incpath		" Where are your include files located?")
	(set #t_incpathhelp	"Installer will place C, Asm and A56 includes here.\n\n")
	
	(set #t_startup	 	" Few lines are added to your s:user-startup file.")
;** 
;** Main installation procedure starts here...
;**


(set	#usersoft	1	;User software
	#userser	2	;delfser
	#userpar	4	;delfpar
	#useralab	8	;AL16
	#userahi	16	;ahi
	#userdoc	32	;user doc
)
(set
	#devsoft	1	;dev soft
	#devdoc		2	;dev doc
	#devinc		4	;includes
	#devsrc		8	;sources
	#devhist	16	;history
)

(set	#userpack	1	;user pack
	#devpack	2	;dev pack
)

;**
;** Make sure we're using a recent version of the installer
;**

(if (< @installer-version (+ (* 43 65536) 3))
(
	(if (not (askbool
		(prompt #t_oldinstaller)
		(help #t_oldinstallerhelp)
	))
	(
		(abort (cat #t_installaborted "\n\n" #t_oldinstallerhelp))
	))
))


;**
;** CPU check
;**

(if (patmatch "68000|68010" (database "cpu"))
(
	(abort #t_wrongcpu)
))

;**
;** check which files are available 
;**
(set #packs 0)
(if (exists "data/user.lzx") (set #packs (bitor #packs #userpack)))
(if (exists "data/dev.lzx") (set #packs (bitor #packs #devpack)))
(if (not (exists "data/delfina.audio"))
(
	(set #userahi "")
	(set #t_userahi "")
))

;**
;** Welcome!
;**

(if (= #packs 1) (welcome #t_wc_user))
(if (= #packs 2) (welcome #t_wc_dev))
(if (= #packs 3) (
	(welcome #t_wc_both)
	(set #userser "")
	(set #userpar "")
	(set #t_userser "")
	(set #t_userpar "")
))


;**
;** Find out which parts should be installed
;**

(set #userparts 0)

;**
;**  Ask which user parts should be installed
;**

(if (bitand #packs #userpack)
(
	(set #default (bitor #usersoft #userser #userpar #userahi #userdoc))
	(if (= @user-level 0)
	(
		(set #userparts #default)
	)
	( ; Average or Expert
		(set #userparts (askoptions
			(prompt #t_userparts)
			(help (cat #t_userhelp @askoptions-help))
			(choices #t_usersoft #t_userser #t_userpar #t_useralab #t_userahi #t_userdoc)
			(default #default)
		))
	))
))
(complete (/ #complete 10)) (set #complete (+ #complete #completeadd))

;**
;**  Ask which dev parts should be installed
;**

(if (bitand #packs #devpack)
(
	(set #default (bitor #devsoft #devdoc #devinc #devsrc #devhist))
	(if (<> @user-level 0)
	( ; Average or Expert
		(set #devparts (askoptions
			(prompt #t_devparts)
			(help (cat #t_devhelp @askoptions-help))
			(choices #t_devsoft #t_devdoc #t_devinc #t_devsrc #t_devhist)
			(default #default)
		))
	))
))
(complete (/ #complete 10)) (set #complete (+ #complete #completeadd))

;**
;** Find out where the files should be installed
;**

(if (exists "env:DelfinaDir")
(
	(set @default-dest (getenv "DelfinaDir"))
))

(set #libspath		"Libs:")
(set #devspath		"Devs:")
(set #alabpath		@default-dest)
(set #incpath		@default-dest)
(set #parentpath	@default-dest)

(if (exists "Include:" (noreq)) (set #incpath "Include:"))

(set #delold 1)

;**
;** Novice
;**
(if (= @user-level 0)
(
	(set #delfpath (tackon @default-dest "Delfina/"))
)

;**
;** Average & Expert
;**
(
	(set #parentpath (askdir 
		(prompt #t_delfpath)
		(help (cat #t_delfpathhelp @askdir-help))
		(default @default-dest)
	))
	(set #delfpath (tackon #parentpath "Delfina/"))

	(if (exists #delfpath)
	(
		(set #delold (askbool 
			(prompt #t_olddelf)
			(help #t_nohelp)
			(choices "Proceed" "Skip this part")
		))
	))

	(if (bitand #userparts #useralab)
	(
		(set #alabpath (askdir
			(prompt #t_alabpath)
			(help @askdir-help)
			(default #alabpath)
		))
	))
	(if (exists (tackon #alabpath "Drivers/"))
		(set #alabpath (tackon #alabpath "Drivers/"))
	)

	(if (bitand #devparts #devinc)
	(
		(set #incpath (askdir 
			(prompt #t_incpath)
			(help (cat #t_incpathhelp @askdir-help))
			(default #incpath)
		))
	))

;**
;** Let's bore "experts" with stupid questions. :}
;**
	(if (= @user-level 2)
	(
		(if (bitand #userparts #usersoft)
		(
			(set #libspath (askdir 
				(prompt #t_libspath)
				(help (cat #t_libspathhelp @askdir-help))
				(default #libspath)
			))	
		))

		(if (bitand #userparts (bitor #userser #userpar))
		(
			(set #devspath (askdir 
				(prompt #t_devspath)
				(help (cat #t_libspathhelp @askdir-help))
				(default #devspath)
			))	
		))
	))
))
(complete (/ #complete 10)) (set #complete (+ #complete #completeadd))


;**
;** make delfina directory
;**

(makedir #delfpath)
(set @default-dest #delfpath)

;**
;** create ENV:DelfinaDir
;**
(textfile
	(dest "ENV:DelfinaDir")
	(append #parentpath)
)
(textfile
	(dest "ENVARC:DelfinaDir")
	(append #parentpath)
)
(complete (/ #complete 10)) (set #complete (+ #complete #completeadd))

;******************************************************************************
;**** Install *****************************************************************
;******************************************************************************

;**
;** Extract user archive, if needed
;**
(delete "ram:delftemp" (all))
(if #userparts 
(
	(working "Extracting user archive...")
	(run "c/unlzx -m x data/user.lzx ram:Delftemp/")
))
(complete (/ #complete 10)) (set #complete (+ #complete #completeadd))
	

;**
;** Install the user software
;**

(if (bitand #userparts #usersoft)
(
	(if #delold 
	(
		(delete (tackon #delfpath "bin/DelfPlay") (all) (optional "force"))
	))

	(if (not (exists (tackon #parentpath "Delfina.info")))
		(copyfiles 
			(help @copyfiles-help)
			(prompt "Installing icon for Delfina directory" )
			(source "ram:delftemp/stuff/")
			(choices "Delfina.info")
			(dest #parentpath)
			(if (= @user-level 2) (confirm))
		)
	)

	(copylib
		(help @copylib-help)
		(prompt "Installing delfina.library")
		(source "ram:delftemp/stuff/delfina.library")
		(dest #libspath)
		(confirm average)
	)
	(copyfiles
		(help @copyfiles-help)
		(prompt "Installing user software" )
		(source "ram:delftemp/")
		(dest #delfpath)
		(pattern "Delf#?")
		(if (= @user-level 2) (confirm))
		(infos)
	)
	(copyfiles
		(help @copyfiles-help)
		(prompt "Installing user Shell commands" )
		(source "ram:delftemp/bin/")
		(dest (tackon #delfpath "bin"))
		(all)
		(if (= @user-level 2) (confirm))
	)
	(copyfiles
		(help @copyfiles-help)
		(prompt "Installing effect presets for DelFX" )
		(source "ram:delftemp/effects/")
		(dest (tackon #delfpath "effects"))
		(all)
		(if (= @user-level 2) (confirm))
	)

	(startup "Delfina DSP"
		(prompt #t_startup)
		(help @startup-help)
		(command (cat 
			"path " #delfpath " " (tackon #delfpath "bin") " add\n"
			"DelfMem >NIL:"
		))
	)
))
(complete (/ #complete 10)) (set #complete (+ #complete #completeadd))

;**
;** Install delfser
;**
(if (bitand #userparts #userser)
(
	(copylib
		(help @copylib-help)
		(prompt "Installing delfser.device")
		(source "ram:delftemp/stuff/delfser.device")
		(dest #devspath)
		(confirm average)
	)
))
(complete (/ #complete 10)) (set #complete (+ #complete #completeadd))

;**
;** Install delfpar
;**
(if (bitand #userparts #userpar)
(
	(copylib
		(help @copylib-help)
		(prompt "Installing delfpar.device")
		(source "ram:delftemp/stuff/delfpar.device")
		(dest #devspath)
		(confirm average)
	)
))
(complete (/ #complete 10)) (set #complete (+ #complete #completeadd))

;**
;** Install audiolab driver
;**
(if (bitand #userparts #useralab)
(
	(copyfiles
		(help @copyfiles-help)
		(prompt "Installing AudioLab16 driver")
		(source "ram:delftemp/stuff/")
		(choices "DelfinaOut")
		(dest #alabpath)
		(if (= @user-level 2) (confirm))
	)
))
(complete (/ #complete 10)) (set #complete (+ #complete #completeadd))

;**
;** Install AHI driver
;**
(if (bitand #userparts #userahi)
(
	(copyfiles
		(help @copyfiles-help)
		(prompt "Installing AHI mode descriptor")
		(source "data/")
		(choices "DELFINA")
		(dest "devs:audiomodes/")
		(if (= @user-level 2) (confirm))
	)
	(copylib
		(help @copylib-help)
		(prompt "Installing AHI driver")
		(source "data/delfina.audio")
		(dest "devs:ahi/")
		(confirm average)
	)

))
(complete (/ #complete 10)) (set #complete (+ #complete #completeadd))

;**
;** Install user docs
;**
(if (bitand #userparts #userdoc)
(
	(if #delold 
	(
		(delete (tackon #delfpath "Docs/Main#?") (all) (optional "force"))
	))

	(if (and (not (bitand #devparts #devdoc)) (not (exists (tackon #delfpath "Docs.info"))))
		(copyfiles 
			(help @copyfiles-help)
			(prompt "Installing icon for Docs directory" )
			(source "ram:delftemp/")
			(choices "Docs.info")
			(dest #delfpath)
			(if (= @user-level 2) (confirm))
		)
	)

	(copyfiles
		(help @copyfiles-help)
		(prompt "Installing user documentation")
		(source "ram:delftemp/Docs/")
		(all)
		(dest (tackon #delfpath "Docs"))
		(if (= @user-level 2) (confirm))
		(infos)
	)
))
(complete (/ #complete 10)) (set #complete (+ #complete #completeadd))

;**
;** Delete tempdir, extract developer stuff
;**

(delete "ram:delftemp" (all))
(if #devparts
( 
	(working "Extracting developer archive...")
	(run "c/unlzx -m x data/dev.lzx ram:Delftemp/")
))
(complete (/ #complete 10)) (set #complete (+ #complete #completeadd))

;**
;** Install dev software
;**
(if (bitand #devparts #devsoft)
(
	(if (not (exists (tackon #parentpath "Delfina.info")))
		(copyfiles 
			(help @copyfiles-help)
			(prompt "Installing icon for Delfina directory" )
			(source "ram:delftemp/stuff/")
			(choices "Delfina.info")
			(dest #parentpath)
			(if (= @user-level 2) (confirm))
		)
	)

	(copyfiles
		(help @copyfiles-help)
		(prompt "Installing developer Shell commands" )
		(source "ram:delftemp/bin/")
		(dest (tackon #delfpath "bin"))
		(all)
		(if (= @user-level 2) (confirm))
	)
))
(complete (/ #complete 10)) (set #complete (+ #complete #completeadd))

;**
;** Install dev docs
;**
(if (bitand #devparts #devdoc)
(
	(if #delold 
	(
		(delete (tackon #delfpath "Docs/A56#?") (all) (optional "force"))
	))

	(if (or (not (exists (tackon #delfpath "Docs.info"))) (not (exists (tackon #delfpath "Autodocs.info"))))
		(copyfiles 
			(help @copyfiles-help)
			(prompt "Installing icons.." )
			(source "ram:delftemp/")
			(choices "Docs.info" "Autodocs.info")
			(dest #delfpath)
			(if (= @user-level 2) (confirm))
		)
	)

	(copyfiles
		(help @copyfiles-help)
		(prompt "Installing developer documentation" )
		(source "ram:delftemp/Docs/")
		(dest (tackon #delfpath "Docs"))
		(choices "DevManual.guide")
		(infos)
		(if (= @user-level 2) (confirm))
	)

	(copyfiles
		(help @copyfiles-help)
		(prompt "Installing autodocs" )
		(source "ram:delftemp/Autodocs/")
		(dest (tackon #delfpath "Autodocs"))
		(all)
		(infos)
		(if (= @user-level 2) (confirm))
	)
))
(complete (/ #complete 10)) (set #complete (+ #complete #completeadd))

;**
;** Install includes
;**
(if (bitand #devparts #devinc)
(
	(copyfiles
		(help @copyfiles-help)
		(prompt "Installing A56 include files" )
		(source "ram:delftemp/include/a56")
		(dest (tackon #incpath "a56"))
		(all)
		(if (= @user-level 2) (confirm))
	)
	(copyfiles
		(help @copyfiles-help)
		(prompt "Installing C and Asm include files" )
		(source "ram:delftemp/include/libraries")
		(dest (tackon #incpath "libraries"))
		(all)
		(if (= @user-level 2) (confirm))
	)
	(copyfiles
		(help @copyfiles-help)
		(prompt "Installing FD file" )
		(source "ram:delftemp/include/fd")
		(dest (tackon #incpath "fd"))
		(all)
		(if (= @user-level 2) (confirm))
	)
	(copyfiles
		(help @copyfiles-help)
		(prompt "Installing pragma file" )
		(source "ram:delftemp/include/pragmas")
		(dest (tackon #incpath "pragmas"))
		(all)
		(if (= @user-level 2) (confirm))
	)
))
(complete (/ #complete 10)) (set #complete (+ #complete #completeadd))

;**
;** Install example sources
;**
(if (bitand #devparts #devsrc)
(
	(if #delold 
	(
		(delete (tackon #delfpath "Examples/") (all) (optional "force"))
	))

	(if (not (exists (tackon #delfpath "Examples.info")))
		(copyfiles 
			(help @copyfiles-help)
			(prompt "Installing icon for Examples directory" )
			(source "ram:delftemp/")
			(choices "Examples.info")
			(dest #delfpath)
			(if (= @user-level 2) (confirm))
		)
	)

	(copyfiles
		(help @copyfiles-help)
		(prompt "Installing example sources")
		(source "ram:Delftemp/Examples/")
		(all)
		(dest (tackon #delfpath "Examples"))
		(if (= @user-level 2) (confirm))
	)
))
(complete (/ #complete 10)) (set #complete (+ #complete #completeadd))

;**
;** Install history files
;**
(if (bitand #devparts #devhist)
(
	(if #delold 
	(
		(delete (tackon #delfpath "Docs/History/") (all) (optional "force"))
	))

	(if (not (exists (tackon #delfpath "Docs/History.info")))
		(copyfiles 
			(help @copyfiles-help)
			(prompt "Installing icon for History directory" )
			(source "ram:delftemp/Docs/")
			(choices "History.info")
			(dest (tackon #delfpath "Docs"))
			(if (= @user-level 2) (confirm))
		)
	)

	(copyfiles
		(help @copyfiles-help)
		(prompt "Installing history files")
		(source "ram:Delftemp/Docs/History/")
		(all)
		(dest (tackon #delfpath "Docs/History"))
		(if (= @user-level 2) (confirm))
	)
))
(complete (/ #complete 10)) (set #complete (+ #complete #completeadd))

;**
;** Delete tempdir
;**
(delete "ram:delftemp" (all))

(complete 100)
(exit)
