; drawSTUDIO Patch Utility
;
; This script is Copyright ©1995,1996 Graham Dean and Andy Dean
;

(set version "v1.1.0")

(
	; Welcome

	(message "Welcome to the drawSTUDIO patch. This will patch "
		"v1.0.2 of drawSTUDIO to " version " Your "
		"original copy of drawSTUDIO will be renamed, in case "
		"the patch fails for any reason. Both English and "
		"German language versions can be installed from "
		"this patch.\n\n"
		"You will need your orginal drawSTUDIO disks and "
		"your registration number before you proceed.\n\n"
		"This patch is Copyright 1996-1997 Graham Dean and "
		"Andy Dean."

	)

	; Ask where to install it...

	(set destdir
		(askdir
			(prompt "Select the directory where your current "
				"version of drawSTUDIO is installed.")
			(help "This is where the new version of "
				"drawSTUDIO will be placed.")
			(default @default-dest)
			(disk)
		)
	)

	(set @default-dest destdir)
	
	; Shall we patch the FPU version ?

	(set fpuversion
		(askchoice
			(prompt "Select whether you are patching the "
				"Standard or the FPU version of drawSTUDIO:")
			(help "You may update either of the versions using "
				"this patch, but you cannot change the "
				"Standard version to the FPU version, or "
				"the FPU version to the Standard.")
			(choices "Standard" "FPU optimised")
		)
	)

	; Language

	(set language
		(askchoice
			(prompt "Choose the language you wish drawSTUDIO "
				"to use:")
			(help "Both English and German languages are "
				"supported in this patch. Choose "
				"the version you want drawSTUDIO to "
				"throughout the program.")
			(choices "English" "German")
		)
	)

	; Copy original

	(working "Backing up orginal...")

	(set srcprog (tackon destdir "DrawStudio"))
	(set bakprog (tackon destdir "DrawStudioOLD"))

	(copyfiles
		(source (srcprog))
		(dest (bakprog))
		(newname ("DrawStudio"))
		(infos)
	)

	;(run "copy " srcprog bakprog)

	;(set srcprog (tackon destdir "DrawStudio.info"))
	;(set bakprog (tackon destdir "DrawStudioOLD.info"))

	;(run "copy " srcprog bakprog)

	; Set up decompressor to work with

	(working "Setting up files...")

	(copyfiles
		(source ("spatch"))
		(dest ("T:"))
	)

	(copyfiles
		(source ("DrawStudio_1:"))
		(dest ("T:"))
		(choices "lx" "pcefis")
	)

	(working "Decompressing patch...")

	(complete 10)

	(if (= 0 fpuversion)
		(run ("t:pcefis dsNON102110.lha T:"))

		(run ("t:pcefis dsFPU102110.lha T:"))
	)

	(working "Decompressing drawSTUDIO program...")

	(complete 30)

	(if (= 0 fpuversion)
		(
			(run ("t:pcefis drawSTUDIO_1:drawSTUDIONON.lha T:"))
		)

		(
			(askdisk (dest "drawSTUDIO_2") (assigns)
			(prompt "Please insert disk drawSTUDIO_2")
			(help "Insert Disk 2 in any drive. You may "
				"remove Disk 1, it will not be needed again."))

			(working "Decompressing drawSTUDIO program...")

			(run ("t:pcefis drawSTUDIO_2:drawSTUDIO881.lha T:"))
		)
	)
	
	(complete 60)

	(working "Patching program. This may take some time...")

	(run "t:spatch -pT:patch.pch -oT:DrawStudio.new T:DrawStudio")

	; Copy the patched file back to the disk

	(complete 80)

	(working "Copying new program...")

	(copyfiles
		(source ("T:DrawStudio.new"))
		(dest (destdir))
		(newname ("DrawStudio"))
	)

	; Language files

	(complete 90)

	(if (= 0 fpuversion)
		(copyfiles
			(source ("LanguageEng.msg"))
			(dest (destdir))
			(newname ("Language.msg"))
		)

		(copyfiles
			(source ("LanguageDeu.msg"))
			(dest (destdir))
			(newname ("Language.msg"))
		)
	)

	; Cleanup

	(delete ("t:LX"))
	(delete ("t:pcefis"))
	(delete ("t:DrawStudio"))
	(delete ("t:DrawStudio.new"))
	(delete ("t:spatch"))
	(delete ("t:patch.pch"))

	; Say goodbye

	(set endmessage (cat "Your copy of drawSTUDIO has now been "
		"patched to " version " and your old version has "
		"been placed in the DrawStudioOLD directory. You will "
		"need to enter your registration number again when "
		"you run the program for the first time."))

	(complete 100)

	(message endmessage)
)
