;
;$VER: Uridium-II HD Installer script v1.02 (c) 1997 John Girvin
;

;---------------------------------------------------------------------------
;
; Make a disk image
;

(procedure S_MakeDisk #UDISKNUM
(
	(set #UDATFILE (tackon #UDESTDIR (cat "Disk." #UDISKNUM)))

	(message
		(cat
			"\n\n\nPlease insert Uridium-II Disk "
			#UDISKNUM 
			" in drive DF0:\n\n"
			"*** WARNING ***\n"
			"Multitasking will be disabled while the disk image"
			" is being created. After inserting the disk, please"
			" ensure that all disk and network activity has finished"
			" before clicking 'Proceed'.\n\n"
			"Click 'Proceed' when ready."
		)
	)

	(working
		(cat "Creating image of disk " #UDISKNUM " in '" #UDATFILE "'\n\n"
    	     "*** Multitasking is disabled. DON`T PANIC! ***"
		)
	)


	(set #URCODE (run (cat "U2MakeDat " #UDATFILE)))

	(if (<> #URCODE 0)
		(abort
			(cat
				"Could not create image of disk "
				#UDISKNUM
				" !\n\nError: " #URCODE
			)
		)
	)
))

;---------------------------------------------------------------------------
;
; Fresh install, not upgrading
;
; - get dir to install in
; - create drawer
; - copy the drawer icon
; - create the disk images
;

(procedure S_Install
(
	;
	; Get directory to install U2 in
	;
	(set #UROOTDIR
		(askdir
			(prompt "Where would you like Uridium-II installed?\n"
					"(a new drawer called 'Uridium-II' will be created here)"
			)
			(help @askdir-help)
			(default #UROOTDIR)
		)
	)

	(set #UDESTDIR (tackon #UROOTDIR "Uridium-II/"))
	(set @default-dest #UDESTDIR)

	;
	; Create the directory
	;
	(makedir #UDESTDIR
		(prompt "I will now create the directory '" #UDESTDIR "'")
		(help @makedir-help)
		(infos)
		(confirm)
	)

	;
	; Copy disk drawer icon
	;
	(copyfiles
		(prompt "Copying HD drawer icon")
		(help @copyfiles-help)
		(source "Uridium-II.inf")
		(newname "Uridium-II.info")
		(dest #UROOTDIR)
		(nogauge)
		(optional fail force)
	)

	;
	; Create the disk images
	;
	(S_MakeDisk 1)
	(S_MakeDisk 2)
))

;---------------------------------------------------------------------------
;
; Upgrading an existing install
;
; - find out where game is installed
;

(procedure S_Upgrade
(
	;
	; Get directory containing installed U2
	;
	(until
		(= 1 (exists (tackon #UDESTDIR "Disk.1")))
		(set #UDESTDIR
			(askdir
				(prompt "Where do you have Uridium-II installed?\n"
						"(select the directory containing the Uridium-II disk images)"
				)
				(help @askdir-help)
				(default #UDESTDIR)
			)
		)
	)
	(set @default-dest #UDESTDIR)
))

;---------------------------------------------------------------------------

(welcome "Welcome to the Uridium-II Hard Drive Installer")
(set @app-name (cat "Uridium-II_HD"))
(set #UROOTDIR "DH0:")
(set #UDESTDIR "")

(if	(<> @user-level 2)
	(abort "You must select 'Expert' user level")
)

(message "\n\nWelcome to the Uridium-II Hard Drive Installer\n"
		 "(c) 1997 John Girvin\n\n"
		 "Please read the documentation thoroughly before"
		 " attempting to use this installer!\n\n"
		 "This is version 1.02\n\n"
		 "Click 'Proceed' to begin."
)

;
; See if we are upgrading or not
;
(if (= 0 (askbool
			(prompt "\n\n\nAre you upgrading from a previous version of U2Install?")
			(help @askoptions-help)
		 )
	)
	(S_Install)
	(S_Upgrade)
)

;
; Generate config file
; Always done, update or fresh
;
(set #UDATFILE (tackon #UDESTDIR "u2config.bin"))
(set #URCODE (run (cat "U2Config " #UDATFILE)))

(if (<> #URCODE 0)
	(abort
		(cat
			"Could not create configuation file "
			#DUATFILE
			" !\n\nError: " #URCODE
		)
	)
)

;
; Copy WHDload, slave and icon
; Always copied for both upgrades and fresh installs
;
(copyfiles
	(prompt "Copying WHDLoad program")
	(help @copyfiles-help)
	(source "WHDLoad")
	(dest #UDESTDIR)
	(nogauge)
	(noposition)
	(optional fail force)
)

(copyfiles
	(prompt "Copying slave program")
	(help @copyfiles-help)
	(source "Uridium-II_HD")
	(dest #UDESTDIR)
	(nogauge)
	(noposition)
	(optional fail force)
)

(copyfiles
	(prompt "Copying slave program icon")
	(help @copyfiles-help)
	(source "Uridium-II_HD.inf")
	(newname "Uridium-II_HD.info")
	(dest #UDESTDIR)
	(nogauge)
	(optional fail force)
)
