; drawSTUDIO Patch Utility
;
; This script is Copyright 1995-1997 Graham Dean and Andy Dean
;

(set version "v1.1.1")

(
	; Welcome

	(message "Welcome to the drawSTUDIO patch. This will patch "
		"v1.1.0 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 1995-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")
		)
	)

	; Floppy or CD

	(set iscd
		(askchoice
			(prompt "Do you have the floppy disk or "
				"CD-ROM version of drawSTUDIO?")
			(help "You may apply this patch to either "
				"the floppy disk or CD-ROM version "
				"of drawSTUDIO")
			(choices "Floppy disk" "CD-ROM")
		)
	)

	; Copy original

	(working "Backing up orginal...")

	; Rename the file from DrawStudio1.1

	(if (= 1 iscd)
		(
			(set srcprog (tackon destdir "DrawStudio1.1"))
			(set bakprog (tackon destdir "DrawStudio"))

			(rename (srcprog) (bakprog))

			(set srcprog (tackon destdir "DrawStudio1.1.info"))
			(set bakprog (tackon destdir "DrawStudio.info"))

			(rename (srcprog) (bakprog))
		)
	)

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

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

	; Set up decompressor to work with

	(working "Setting up files...")

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

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

	(working "Decompressing patch...")

	(complete 10)

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

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

	(working "Decompressing drawSTUDIO program...")

	(complete 30)

	(if (= 0 iscd)
		(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:"))
			)
		)

		; Is CD version

		(
			(if (= 0 fpuversion)
				(
					(set progcd "DrawStudioCD:English/DrawStudio_S/DrawStudio1.1")
				)

				(
					(set progcd "DrawStudioCD:English/DrawStudioFPU/DrawStudio1.1")
				)
			)

			(copyfiles
				(source (progcd))
				(dest ("T:"))
				(newname ("DrawStudio"))
			)
		)
	)

	(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"))
		(optional ("force"))
	)

	; Language files

	(complete 90)

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

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

	; Cleanup

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

	; 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)
)
