; ImageStudio 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 "
				"ImageStudio. A drawer called 'ImageStudio' will "
				"be created here.")
			(help "ImageStudio and all necessary files will be "
				"installed in the directory of your choice. You "
				"may wish to create a new directory for "
				"ImageStudio by using the 'Make New Drawer' "
				"gadget.\n\n"
				"You may install this version over your existing "
				"version of ImageStudio, 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_isrx' file for example.")
			(default @default-dest)
			(disk)
		)
	)

	(set destdir
		(tackon destdir "ImageStudio")
	)

	(set @default-dest destdir)

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

	(if (exists @default-dest) 
		(
			(if (= 0 (askbool
					(prompt "The 'ImageStudio' directory "
						"already exists, overwrite?")
					(help "You may stop the install to "
						"avoid overwriting your current "
						"version of ImageStudio.\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 "ImageStudio will be installed in " @default-dest)

	; Set up decompressor to work with

	(complete 0)

	(working "Setting up files...")

	(copyfiles
		(source ("ImageStudio_1:"))
		(dest ("ram:"))
		(choices "LX" "pcefis")
	)

	(working "Installing ImageStudio Program...")

	; Create the directory if it doesn't exist

	(if (= 0 (exists @default-dest))
		(
			(makedir @default-dest
				(prompt "Creating 'ImageStudio' directory")
				(infos)
			)
		)
	)

	; Shall we install the 68020 version ?

	(set cpuversion
		(askchoice
			(prompt "Choose which version of ImageStudio to install "
				"based on your processor.")
			(help "If you are running an Amiga A500, A600 or "
				"unexpanded A1500 or A2000 you should run the "
				"68000 version of ImageStudio.\n\n"
				"Users of Amiga A1200, A3000, A4000s or any of the "
				"above machines which have an accelerator card "
				"should use the 68020+ version of ImageStudio "
				"for increased performance.")
			(choices "68000" "68020+")
		)
	)

	; Set up the versions to install based on the CPU chosen

	(if (= 0 cpuversion)
		(
			(set cpu "000")
		)

		(
			(set cpu "020")
		)
	)

	(working "Decompressing ImageStudio executable...")

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

	; Install UnCrash

	(copyfiles
		(source "ImageStudio_1:UnCrash")
		(dest @default-dest)
	)

	; Install convolution filters

	(complete 30)

	(set convolvedir (tackon @default-dest "Convolves"))
	(set doconvolve 1)

	(if (= 0 (exists convolvedir))
		(
			(makedir convolvedir
				(prompt "Creating 'Convolves' directory")
				(infos)
			)
		)

		; Warn user about overwriting existing Convolves

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

				; If chosen overwrite

				(
					(set doconvolve 1)
				)

				; If chosen skippy

				(
					(set doconvolve 0)
				)
			)
		)
	)

	(if doconvolve
		(
			(working "Decompressing convolution filters...")

			(run ("ram:pcefis ImageStudio_1:Convolves.lha \"%s\""
				convolvedir))
		)
	)

	; Install palettes

	(complete 40)

	(set palettesdir (tackon @default-dest "Palettes"))
	(set dopalettes 1)

	(if (= 0 (exists palettesdir))
		(
			(makedir palettesdir
				(prompt "Creating 'Palettes' directory")
				(infos)
			)
		)

		; Warn user about overwriting existing Palettes

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

				; If chosen overwrite

				(
					(set dopalettes 1)
				)

				; If chosen skippy

				(
					(set dopalettes 0)
				)
			)
		)
	)

	(if dopalettes
		(
			(working "Decompressing palettes...")

			(run ("ram:pcefis ImageStudio_1:Palettes.lha \"%s\""
				palettesdir))
		)
	)

	; Install ARexx scripts

	(complete 45)

	(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 convolution filters?")
				(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 ImageStudio_1:Rexx.lha \"%s\""
				rexxdir))
		)
	)

	; Install IO modules

	(complete 50)

	(set modulesdir (tackon @default-dest "Modules"))
	(set domodules 1)

	(set iodir (tackon modulesdir "IO"))
	(set doio 1)

	(if (= 0 (exists modulesdir))
		(
			(makedir modulesdir
				(prompt "Creating 'Modules' directory")
				(infos)
			)
		)

		; Warn user about overwriting existing modules

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

				; If chosen overwrite

				(
					(set domodules 1)
				)

				; If chosen skippy

				(
					(set domodules 0)
				)
			)
		)
	)

	(if (= 0 (exists iodir))
		(
			(makedir iodir
				(prompt "Creating 'IO' directory")
				(infos)
			)
		)

		; Warn user about overwriting existing IO modules

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

				; If chosen overwrite

				(
					(set doio 1)
				)

				; If chosen skippy

				(
					(set doio 0)
				)
			)
		)
	)

	(if doio
		(
			(working "Decompressing IO modules...")

			(run ("ram:pcefis ImageStudio_1:IO%s.lha \"%s\"" cpu
				iodir))
		)
	)

	; Install View modules

	(complete 55)

	(set viewdir (tackon modulesdir "View"))
	(set doview 1)

	(if (= 0 (exists viewdir))
		(
			(makedir iodir
				(prompt "Creating 'View' directory")
				(infos)
			)
		)

		; Warn user about overwriting existing View modules

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

				; If chosen overwrite

				(
					(set doview 1)
				)

				; If chosen skippy

				(
					(set doview 0)
				)
			)
		)
	)

	(if doview
		(
			(working "Decompressing View modules...")

			(run ("ram:pcefis ImageStudio_1:View%s.lha \"%s\"" cpu
				viewdir))
		)
	)

	; Copy the AmigaGuide.library if needed

	(complete 60)

	(working "Checking amigaguide.library version...")

	(copylib
		(prompt "Copying amigaguide library to LIBS: directory...")
		(help "The amigaguide.library is needed for online help. "
			"Users of Workbench3.0 and above will have a more recent "
			"version of this library and so can skip this part "
			"of the installation.")
		(source "ImageStudio_1:libs/amigaguide.library")
		(dest "LIBS:")
		(confirm)
	)

	; Copy keyfile if it exists

	(if (exists "ImageStudio_1:ImageStudio.keyfile")
		(
			(copyfiles
				(source "ImageStudio_1:ImageStudio.keyfile")
				(dest @default-dest)
			)

			(set foundkeyfile (""))
		)

		; Else, note we didn't find one

		(
			(set foundkeyfile (cat "No keyfile was found during "
				"installation. If you are a registered user make "
				"sure that you create a keyfile by selecting the "
				"'Create keyfile' option in the 'Project' menu "
				"of this version of ImageStudio. For more details "
				"see the 'Upgrading from v1.x.x' section in the "
				"'Introduction' of the manual."))
		)
	)

	; Ask user what documentation the user wishes

	(set docchoice
		(askoptions
			(prompt "Which formats of documentation would you like "
				"installing in your 'Docs' directory?")
			(help   "ImageStudio.txt is the ASCII (plain text) "
				"documentation file.\n\n"
				"ImageStudio.guide documentation is required for "
				"online help.\n\n"
				"ImageStudio.ps is the documentation in PostScript "
				"format.\n\n"
				"ImageStudio.dvi is for use with the Amiga TeX "
				"package.")
			(choices "ImageStudio.txt" "ImageStudio.guide"
				 "ImageStudio.ps" "ImageStudio.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 readme, history and news files into the docs directory

	(complete 70)

	(copyfiles
		(source "ImageStudio_1:")
		(dest docsdir)
		(choices "NEWS.txt" "HISTORY.txt" "README.txt" "Award.ilbm")
		(infos)
	)

	; The (assigns) parameters in the askdisk commands is deliberate
	; as the user may want to decompress the .lha distribution archives
	; into directories instead of onto disks. This just make life easier.

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

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

			(working "Decompressing ASCII documentation...")

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

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

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

			(working "Decompressing AmigaGuide documentation...")

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

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

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

			(working "Decompressing PostScript documentation...")

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

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

	(if (= 8 (IN docchoice 3))
		(
			(askdisk (dest "ImageStudio_2") (assigns)
			(prompt "Please insert disk ImageStudio_2")
			(help "Insert Disk 2 in any drive. You may "
			"remove Disk 1, it will not be needed again.") )

			(working "Decompressing DVI documentation...")

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

	; Ask whether should install demo pictures

	(complete 90)

	(set demopics
		(askbool
			(prompt "Do you want the demo pictures installed?")
			(help "Installing the demo pics will allow you to perform "
				"some of the tutorials given in the documentation. "
				"All the demo pictures are small enough to load "
				"into the unregistered version of ImageStudio.")
			(choices "Yes" "Skip this part")
		)
	)

	(if demopics
		(
			; Create directory if needed

			(set picsdir (tackon @default-dest "Pics"))

			(if (= 0 (exists picsdir))
				(
					(makedir picsdir
						(prompt "Creating 'Pics' directory")
						(infos)
					)
				)
			)

			; Decompress the pics files

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

			(working "Decompressing demo pics...")

			(run ("ram:pcefis ImageStudio_2:Pics.lha \"%s\""
				picsdir))
		)
	)
	; Say goodbye

	(set endmessage (cat "Do not forget to set the value of the TEMPDIR "
		"preference so that the virtual memory swap files can be created "
		"on your hard disk instead of taking lots of RAM."
		"The INTERNALVIEWER can also be changed to take advantage of "
		"an AGA Amiga, or Amiga with a graphics card.\n\n"))

	(if (<> foundkeyfile "")
		(
			(set endmessage (cat endmessage foundkeyfile))
		)
	)

	(complete 100)

	(message endmessage)

	; Cleanup

	(delete ("ram:LX"))
	(delete ("ram:pcefis"))
)
