;
;$VER: Jimmy White's Whirlwind Snooker HD Installer script v1.02 (c) 1998 John Girvin
;
;------------------------------------------------------------------------------------
; Make game data

(procedure S_InstallGame
(
	;
	; Get game disk inserted
	;
	(message
		(cat
			"\n\n\nPlease insert your game disk in drive DF0:\n\n"
			"Click 'Proceed' when ready."
		)
	)

	;
	; Copy extractor slave to destination
	;
	(copyfiles
		(prompt "Copying data extractor slave")
		(help @copyfiles-help)
		(source "JWWSMakeDat")
		(dest #TDESTDIR)
		(nogauge)
		(noposition)
		(optional fail force)
	)

	;
	; Call the data extractor
	;
	(message	"\n\n*** WARNING ***\n\n"
				"The next stage of the installation process requires that"
				" multitasking be disabled temporarily while a data file"
				" is being read and decrunched. This may take up to two"
				" minutes depending on the speed of your Amiga.\n\n"
				" Please ensure that all critical activity (eg: disk or"
				" network access) has finished before clicking 'Proceed'.\n\n"
				"Click 'Proceed' when ready."
	)

	(working
		(cat "Creating game data file in '" #TDATDIR "'\n\n"
	   	     "*** Multitasking is disabled - DON`T PANIC! ***"
		)
	)

	(set #TOLDEXEDIR @execute-dir)
	(set @execute-dir #TDESTDIR)
	(run
		(cat
			(tackon #TDESTDIR
					"WHDLoad SLAVE=JWWSMakeDat NOVBRMOVE NOCACHE NOAUTOVEC NOTRAPHANDLER"
			)
		)
	)
	(set @execute-dir #TOLDEXEDIR)

	;
	; Delete the data extractor
	;
	(delete
		(tackon #TDESTDIR "JWWSMakeDat")
		(prompt "Deleting data extractor slave")
		(optional fail force)
	)

	;
	; Did the data extractor work?
	; Check that the file was created and is the correct size
	;

	(set #TMAINSIZE (getsize (tackon #TDATDIR "Main")))

	(if (<>	#TMAINSIZE 330160)
		(if (<>	#TMAINSIZE 330192)
			(if (<>	#TMAINSIZE 330888)
				(abort "Could not create data file !")
				(set #TSLAVENAME "v3")
			)
			(set #TSLAVENAME "v2")
		)
		(set #TSLAVENAME "v1")
	)
	(set #TSLAVENAME (cat #TSLAVENAME ".gpch"))

	(message "\n\nData file successfuly created!"
			 "\n\nMultitasking is re-enabled."
	)
))

;------------------------------------------------------------------------------------
; Make HD loader slave

(procedure S_InstallSlave
(
	;
	; Create slave from base file and patch
	;
	(working "Creating slave program")
	(set #TRCODE
		(run
			(cat "GPatch JWWSHD_base "
				 	#TSLAVENAME " "
					(tackon #TDESTDIR "JW_Snooker")
			)
		)
	)

	(if (<> #TRCODE 0)
		(abort
			(cat "Slave generation failed error " #TRCODE)
		)
	)


	;	
	; Copy slave icon and set tooltypes
	;
	(copyfiles
		(prompt "Copying slave program icon")
		(help @copyfiles-help)
		(source "Slave.inf")
		(newname "JW_Snooker.info")
		(dest #TDESTDIR)
		(nogauge)
		(optional fail force)
	)

	(tooltype
		(prompt "Setting HD loader slave icon tooltypes")
		(dest (tackon #TDESTDIR "JW_Snooker"))
		(setdefaulttool "WHDLoad")
		(settooltype "SLAVE" "JW_Snooker")
		(settooltype "NOVBRMOVE" "")
		(settooltype "NOCACHE" "")
		(settooltype "PRELOAD" "")
	)
))

;------------------------------------------------------------------------------------
; Make save data

(procedure S_InstallSave
(
	;
	; Copy save extractor to destination
	; Do it even if user is installing default saves
	; since it will be required later if they want to
	; install a save disk with the other script
	;
	(copyfiles
		(prompt "Copying save data extractor program")
		(help @copyfiles-help)
		(source "JWWSMakeSave")
		(dest #TDATDIR)
		(nogauge)
		(noposition)
		(optional fail force)
	)

	;
	; Install actual saves or defaults?
	;
	(if (= 1
			(askbool
				(prompt "Do you want to install any existing saved games and scores?")
				(help @askchoice-help)
				(choices "Yes" "No")
				(default 0)
			)
		)
		(	; Install from save disk

			;
			; Get save disk inserted
			;
			(message
				(cat "\n\n\nPlease insert your save disk in drive DF0:\n\n"
					 "Click 'Proceed' when ready."
				)
			)

			;
			; Call the save extractor
			;
			(set #TOLDEXEDIR @execute-dir)
			(set @execute-dir #TDATDIR)
			(run (cat(tackon #TDATDIR "JWWSMakeSave 0")))
			(set @execute-dir #TOLDEXEDIR)

			;
			; Did the save install work?
			; Check that the files were created
			;
			(if (<>	(getsize (tackon #TDATDIR "SaveDat.6B4")) 5632)
				(abort "Could not create save data file 1 !")
			)

			(if (<>	(getsize (tackon #TDATDIR "SaveDat.6CA")) 5632)
				(abort "Could not create save data file 2 !")
			)

			(message "\n\n\n\nSaved games and scores successfuly installed!")
		)
		(	;Install empty save data files

			(copyfiles
				(prompt "Copying empty saved game buffer")
				(help @copyfiles-help)
				(source "SaveDat.6B4")
				(dest #TDATDIR)
				(nogauge)
				(optional fail force)
			)

			(copyfiles
				(prompt "Copying empty saved game buffer")
				(help @copyfiles-help)
				(source "SaveDat.6CA")
				(dest #TDATDIR)
				(nogauge)
				(optional fail force)
			)
		)
	)
))

;------------------------------------------------------------------------------------
(welcome "Welcome to the Jimmy White's Whirlwind Snooker HD Installer")
(set @app-name (cat "Jimmy White's Whirlwind Snooker"))
(set #TROOTDIR "RAM:")
(set #TDESTDIR "")
(set #TDATDIR "")
(set #TMAINSIZE 0)
(set #TSLAVENAME "")

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

(if	(< @installer-version 2818051)
	(abort "This package requires at least version 43.3 of the Installer program")
)

(message "\n\nWelcome to the Jimmy White's Whirlwind Snooker HD Installer\n"
		 "(c) 1998 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."
)

;
; Get directory to install JWWS in
;
(set #TROOTDIR
	(askdir
		(prompt "Where would you like Jimmy White's Whirlwind Snooker installed?\n"
				"(a new drawer called 'JW_Snooker' will be created here)"
		)
		(help @askdir-help)
		(default #TROOTDIR)
	)
)
(set #TDESTDIR (tackon #TROOTDIR "JW_Snooker/"))
(set #TDATDIR  (tackon #TDESTDIR "data/"))
(set @default-dest #TDESTDIR)

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

;
; Create the installation directories
;
(makedir #TDESTDIR
	(prompt "The directory '" #TDESTDIR "' will now be created")
	(help @makedir-help)
	(infos)
	(confirm)
)

(makedir #TDATDIR
	(prompt "The directory '" #TDATDIR "' will now be created")
	(help @makedir-help)
)

;
; Copy WHDload
; Copy now because its required by the data extractor slave
;
(copyfiles
	(prompt "Copying WHDLoad program")
	(help @copyfiles-help)
	(source "WHDLoad")
	(dest #TDESTDIR)
	(nogauge)
	(noposition)
	(optional fail force)
)

;
; Install the game data, slave and save data
;
(S_InstallGame)
(S_InstallSlave)
(S_InstallSave)

;
; Copy savegame installer script and icon
;
(copyfiles
	(prompt "Copying savegame installer script")
	(help @copyfiles-help)
	(source "Install_JWWS_Save")
	(dest #TDESTDIR)
	(nogauge)
	(optional fail force)
)

(copyfiles
	(prompt "Copying savegame installer script icon")
	(help @copyfiles-help)
	(source "InstallSave.inf")
	(newname "Install_JWWS_Save.info")
	(dest #TDESTDIR)
	(nogauge)
	(optional fail force)
)
