; TextureStudio Installer Utility
;
; This script is Copyright ©1995 Andy Dean and Graham Dean
;

(
	; Ask where to install it...

	(set destdir
		(askdir
			(prompt "Select where you would like to install "
				"TextureStudio. A drawer called 'TextureStudio' will "
				"be created here.")
			(help "TextureStudio and all necessary files will be "
				"installed in the directory of your choice. You "
				"may wish to create a new directory for "
				"TextureStudio by using the 'Make New Drawer' "
				"gadget.\n\n"
				"You may install this version over your existing "
				"version of TextureStudio, but you will loose your "
				"current preference settings and some of your "
				"files may be overwritten with more recent "
				"versions. This may be undesirable if you have "
				"customised your 'Blank_tsrx' file for example.")
			(default @default-dest)
			(disk)
		)
	)

	(set destdir
		(tackon destdir "TextureStudio")
	)

	(set @default-dest destdir)

	; See whether this directory exists, if so warn the user

	(if (exists @default-dest) 
		(
			(if (= 0 (askbool
					(prompt "The 'TextureStudio' directory "
						"already exists, overwrite?")
					(help "You may stop the install to "
						"avoid overwriting your current "
						"version of TextureStudio.\n\n"
						"Continuing the install will "
						"overwrite your current files "
						"and you will loose your current "
						"preferences.")
					(choices "Yes" "Quit")
				))

				(

				; User wishes to quit

				(exit (quiet))
				)

			)
		)
	)

	(message "TextureStudio will be installed in " @default-dest)

	; Set up decompressor to work with

	(complete 0)

	(working "Setting up files...")

	; Copy LX to ram disk if it is not already present

	(if (= 0 (exists "ram:LX"))
		(
			(copyfiles
				(source (""))
				(dest ("ram:"))
				(choices "LX")
			)

			(set dellx 1)
		)

		(
			(set dellx 0)
		)
	)

	; Copy pcefis to ram disk if it is not already present

	(if (= 0 (exists "ram:pcefis"))
		(
			(copyfiles
				(source (""))
				(dest ("ram:"))
				(choices "pcefis")
			)

			(set delpcefis 1)
		)

		(
			(set delpcefis 0)
		)
	)

	(working "Installing TextureStudio Program...")

	; Create the directory if it doesn't exist

	(if (= 0 (exists @default-dest))
		(
			(makedir @default-dest
				(prompt "Creating 'TextureStudio' directory")
				(infos)
			)
		)
	)
	(working "Decompressing TextureStudio executable...")

	; Install the executable and prefs file

	(
		(run ("ram:pcefis TextureStudio.lha \"%s\""
				@default-dest)
		)
	)

	(complete 10)

	; Create Parameters and Renders directories

	(set parametersdir (tackon @default-dest "Parameters"))
	(set rendersdir (tackon @default-dest "Renders"))

	(if (= 0 (exists parametersdir))
		(
			(makedir parametersdir
				(prompt "Creating 'Parameters' directory")
				(infos)
			)
		)
	)

	(if (= 0 (exists rendersdir))
		(
			(makedir rendersdir
				(prompt "Creating 'Renders' directory")
				(infos)
			)
		)
	)

	; Install axis settings

	(complete 20)

	(set axisdir (tackon @default-dest "Axis"))
	(set doaxis 1)

	(if (= 0 (exists axisdir))
		(
			(makedir axisdir
				(prompt "Creating 'Axis' directory")
				(infos)
			)
		)

		; Warn user about overwriting existing Axis

		(
			(if (askbool
				(prompt "Existing 'Axis' directory found. "
					"Overwrite existing axis settings?")
				(help "If you don't wish to overwrite your "
					"current axis settings, skip this "
					"part of the installation process.")
				(choices "Yes" "Skip this part")
				)

				; If chosen overwrite

				(
					(set doaxis 1)
				)

				; If chosen skippy

				(
					(set doaxis 0)
				)
			)
		)
	)

	(if doaxis
		(
			(working "Decompressing axis settings...")

			(run ("ram:pcefis Axis.lha \"%s\""
				axisdir))
		)
	)

	; Install Settings

	(complete 30)

	(set settingsdir (tackon @default-dest "Settings"))
	(set dosettings 1)

	(if (= 0 (exists settingsdir))
		(
			(makedir settingsdir
				(prompt "Creating 'Settings' directory")
				(infos)
			)
		)

		; Warn user about overwriting existing Settings

		(
			(if (askbool
				(prompt "Existing 'Settings' directory found. "
					"Overwrite existing settings?")
				(help "If you don't wish to overwrite your "
					"current settings, skip this "
					"part of the installation process.")
				(choices "Yes" "Skip this part")
				)

				; If chosen overwrite

				(
					(set dosettings 1)
				)

				; If chosen skippy

				(
					(set dosettings 0)
				)
			)
		)
	)

	(if dosettings
		(
			(working "Decompressing settings...")

			(run ("ram:pcefis Settings.lha \"%s\""
				settingsdir))
		)
	)

	; Install ARexx scripts

	(complete 50)

	(set rexxdir (tackon @default-dest "Rexx"))
	(set dorexx 1)

	(if (= 0 (exists rexxdir))
		(
			(makedir rexxdir
				(prompt "Creating 'Rexx' directory")
				(infos)
			)
		)

		; Warn user about overwriting existing Rexx scripts

		(
			(if (askbool
				(prompt "Existing 'Rexx' directory found. "
					"Overwrite existing ARexx scripts?")
				(help "If you don't wish to overwrite your "
					"current ARexx scripts, skip this "
					"part of the installation process.")
				(choices "Yes" "Skip this part")
				)

				; If chosen overwrite

				(
					(set dorexx 1)
				)

				; If chosen skippy

				(
					(set dorexx 0)
				)
			)
		)
	)

	(if dorexx
		(
			(working "Decompressing ARexx scripts...")

			(run ("ram:pcefis Rexx.lha \"%s\""
				rexxdir))
		)
	)

	; Install textures

	(complete 60)

	(set texturesdir (tackon @default-dest "Textures"))
	(set dotextures 1)

	(if (= 0 (exists texturesdir))
		(
			(makedir texturesdir
				(prompt "Creating 'Textures' directory")
				(infos)
			)
		)

		; Warn user about overwriting existing Rexx scripts

		(
			(if (askbool
				(prompt "Existing 'Textures' directory found. "
					"Overwrite existing textures?")
				(help "If you don't wish to overwrite your "
					"current textures, skip this "
					"part of the installation process.")
				(choices "Yes" "Skip this part")
				)

				; If chosen overwrite

				(
					(set dotextures 1)
				)

				; If chosen skippy

				(
					(set dotextures 0)
				)
			)
		)
	)

	(if dotextures
		(
			(working "Decompressing textures...")

			(run ("ram:pcefis Textures.lha \"%s\""
				texturesdir))
		)
	)

	; Ask whether should install render screens

	(complete 70)

	(set renderscreens
		(askbool
			(prompt "Do you want the demo render screens installed?")
			(help "The demo render screens give some examples of the "
			      "images that can be created with TextureStudio. "
			      "They are not necessary for the operation of "
			      "program.")
			(choices "Yes" "Skip this part")
		)
	)

	; Create directory if needed

	(set renderscreensdir (tackon @default-dest "RenderScreens"))

	(if (= 0 (exists renderscreensdir))
		(
			(makedir renderscreensdir
				(prompt "Creating 'RenderScreens' directory")
				(infos)
			)
		)
	)

	(if renderscreens
		(
			; Decompress the pics files

			(working "Decompressing render screens...")

			(run ("ram:pcefis RenderScreens.lha \"%s\""
				renderscreensdir))
		)
	)

	; Copy keyfile if it exists

	(if (exists "TextureStudio.keyfile")
		(
			(copyfiles
				(source "TextureStudio.keyfile")
				(dest @default-dest)
			)

			(set foundkeyfile (""))
		)

		; Else, note we didn't find one

		(
			(set foundkeyfile (cat "No keyfile was found during "
				"installation. For details of how to register "
				"and receive the full version, refer to the "
				"documentation."))
		)
	)

	; Ask user what documentation the user wishes

	(set docchoice
		(askoptions
			(prompt "Which formats of documentation would you like "
				"installing in your 'Docs' directory?")
			(help	"TextureStudio.txt is the ASCII (plain text) "
				"documentation file.\n\n"
				"TextureStudio.guide documentation is the "
				"AmigaGuide format.\n\n"
				"TextureStudio.ps is the documentation in PostScript "
				"format.\n\n"
				"TextureStudio.dvi is for use with the Amiga TeX "
				"package.")
			(choices "TextureStudio.txt" "TextureStudio.guide"
				 "TextureStudio.ps" "TextureStudio.dvi")
			(default 3)
		)
	)

	; Create directory if needed

	(set docsdir (tackon @default-dest "Docs"))

	(if (= 0 (exists docsdir))
		(
			(makedir docsdir
				(prompt "Creating 'Docs' directory")
				(infos)
			)
		)
	)

	; Copy the history file into the docs directory

	(complete 80)

	(copyfiles
		(source "")
		(dest docsdir)
		(choices "History.txt" "ImageStudio.ilbm" )
		(infos)
	)

	; See if we want to install the TextureStudio.txt doc

	(if (= 1 (IN docchoice 0))
		(
			(working "Decompressing ASCII documentation...")

			(run ("ram:pcefis DocTXT.lha \"%s\""
				docsdir))
		)
	)

	; See if we want to install the TextureStudio.guide doc

	(if (= 2 (IN docchoice 1))
		(
			(working "Decompressing AmigaGuide documentation...")

			(run ("ram:pcefis DocGUIDE.lha \"%s\""
				docsdir))
		)
	)

	; See if we want to install the TextureStudio.ps doc

	(if (= 4 (IN docchoice 2))
		(
			(working "Decompressing PostScript documentation...")

			(run ("ram:pcefis DocPS.lha \"%s\""
				docsdir))
		)
	)

	; See if we want to install the TextureStudio.dvi doc

	(if (= 8 (IN docchoice 3))
		(
			(working "Decompressing DVI documentation...")

			(run ("ram:pcefis DocDVI.lha \"%s\""
				docsdir))
		)
	)

	(complete 100)

	; Say goodbye

	(if (<> foundkeyfile "")
		(
			(message foundkeyfile)
		)
	)

	; Cleanup

	(if (= 1 dellx)
		(
			(delete ("ram:LX"))
		)
	)
	(if (= 1 delpcefis)
		(
			(delete ("ram:pcefis"))
		)
	)
)
