;
; $VER: jfif_dtc_install 1.1 (10.12.94)
;
; Copyright (c) 1994 Christoph Feck, TowerSystems.
;
; Boy, do I hate brackets...
;

;****************************************************************************
;
; English texts
;

(set #bad-kick (cat "You must have AmigaOS Release 3 or newer to be able to "
	"use the JFIF DataType.")
)

(set #old-jpeg (cat "    The Installer has found out, that your system has "
	"an obsolete JPEG DataTypes Class installed.  The new JFIF DataType will "
	"not work, if the old DataType remains installed.\n    You should select "
	"\"Delete\" to delete it, or \"Move to Storage\" to move it into the "
	"systems \"Storage/DataTypes\" drawer for later use.")
)

(set #prefs-type (cat "    The JFIF DataType Preferences Editor allows you "
	"to edit various options of the JFIF DataType, such as number of colors "
	"or dithering mode, separately for every application.\n    There are two "
	"versions of the editor available: a GadTools version (which uses the "
	"ROM gadtools library), and a MUI(MagicUserInterface) version.  The "
	"latter requires that you have MUI installed on your harddisk; MUI is "
	"not included.\n\n" @askchoice-help)
)

(set #jfif-descr (cat "    The JFIF DataTypes Descriptor is required to "
	"identify JFIF files.  This file is usually placed into the "
	"\"DEVS:DataTypes\" drawer, it will then automatically be added to the "
	"list of available DataTypes on every reboot.\n    You may also place it "
	"into the systems \"Storage/DataTypes\" drawer and only activate the "
	"DataType, when you need it (simply double-click the \"JFIF\" icon).\n\n"
	@copyfiles-help)
)

(set #has-assign (cat "You already have the \"JPEGTMP:\" assignment, "
	"probably left over from the old JPEG DataType.\n\nPlease do not remove "
	"this assignment,\nthe JFIF DataType may also require it.")
)

(set #temp-file (cat "    To obtain best quality images, the DataType needs "
	"a large amount of memory.\n    If the required storage is not available "
	"in main memory, the DataType will create a temporary file on your "
	"harddisk.  The volume on which this file is created should have enough "
	"free space (about 4 meg).\n    A temporary file is usually only "
	"required, if you have selected the \"Compute Large Histogram\" option "
	"in the JFIF DataTypes Preferences Editor.\n\n" @askdir-help)
)

(set #make-assign (cat "    The logical assignment \"JPEGTMP:\" is used to "
	"refer to the temporary directory.\n    In order to make this assignment "
	"available on every reboot, an \"Assign\" command has to be added to "
	"your \"user-startup\" file.\n\n" @startup-help)
)

(set #why-reboot (cat "    You had an old JPEG DataType installed, which "
	"may still be in memory.  The new JFIF DataType cannot work if you do "
	"not reboot.  Select \"Reboot\" to reboot now, or select \"Cancel\", if "
	"you want to reboot later.")
)

(set #support-me (cat "This is Giftware.\n\nIf you use this DataType "
	"regulary, please consider the amount of work I put into it.  Thank "
	"you.\n\n")
)

;****************************************************************************
;
; Setup
;

(set @default-dest "")

(set libs-dest "LIBS:")
(set class-dest "SYS:Classes")
(set dt-dest "DEVS:DataTypes")
(set storage "SYS:Storage")
(set dt-storage "SYS:Storage/DataTypes")
(set prefs-dest "SYS:Prefs")
(set locale-dest "LOCALE:Catalogs")

(makedir storage)
(makedir dt-storage)
(makedir dt-dest)

(if (not (exists class-dest))
	(set class-dest "LIBS:")
)

(complete 0)

(if (< (/ (getversion) 65536) 39)
	(abort #bad-kick)
)

;****************************************************************************
;
; Welcome
;

(welcome)

(message "\nTower JFIF DataTypes and JPEG Codec Class\n\nCopyright  1994 "
	"Christoph Feck, TowerSystems\nAll Rights Reserved.\n_\n\nJFIF DataType "
	"Preferences (MUI Application)\n\nCopyright  1994 Matthias Scheler\n"
	"All Rights Reserved.\n\n\nPlease refer to the documentation for details."
)

;****************************************************************************
;
; Is the old JPEG datatype installed?
;

(set reboot 0)

(if (exists (tackon dt-dest "JPEG"))
	(
		(set reboot 1)
		(if (askbool (help #old-jpeg) (prompt "You have an obsolete JPEG DataType installed.\nDo you want to delete it?") (choices "Delete" "Move to Storage"))
			(
				(if (exists (tackon class-dest "DataTypes/jpeg.datatype"))
					(delete (tackon class-dest "DataTypes/jpeg.datatype"))
				)
				(if (exists (tackon dt-dest "JPEG"))
					(delete (tackon dt-dest "JPEG"))
				)
				(if (exists (tackon dt-dest "JPEG.info"))
					(delete (tackon dt-dest "JPEG.info"))
				)
			)
			;else
			(
				(if (exists (tackon dt-dest "JPEG"))
					(rename (tackon dt-dest "JPEG") (tackon dt-storage "JPEG"))
				)
				(if (exists (tackon dt-dest "JPEG.info"))
					(rename (tackon dt-dest "JPEG.info") (tackon dt-storage "JPEG.info"))
				)
			)
		)
	)
)

(complete 5)

;****************************************************************************
;
; Install prefs editor
;

(if (or (exists "MUI:mui.key" (noreq)) (exists "S:mui.key" (noreq)))
	(set prefseditor 1)
	(set prefseditor 0)
)

(if (set prefseditor (askchoice (help #prefs-type) (prompt "Which version of the JFIF DataType Preferences Editor would you like to use?") (choices "GadTools version" "MUI version") (default prefseditor)))
	(copyfiles
		(help @copyfiles-help)
		(prompt "Copying JFIF DataType Preferences Editor...")
		(source "Prefs/JFIFDataType")
		(dest prefs-dest)
		(infos)
		(confirm)
	)
	;else
	(copyfiles
		(help @copyfiles-help)
		(prompt "Copying JFIF DataType Preferences Editor...")
		(source "Prefs/JFIF DataType")
		(dest prefs-dest)
		(infos)
		(confirm)
	)
)

(complete 10)

;****************************************************************************
;
; Install catalogs
;

(if (exists (tackon locale-dest "deutsch"))
	(if (IN (askoptions (help @askoptions-help) (prompt "Please indicate which languages to install.") (choices "English" "Deutsch")) 1)
		(
			(makedir (tackon locale-dest "deutsch/Classes"))
			(copyfiles
				(help @copyfiles-help)
				(prompt "Copying JPEG codec catalog...")
				(source "Locale/Catalogs/deutsch/Classes/Codecs/jpeg.catalog")
				(dest (tackon locale-dest "deutsch/Classes/Codecs"))
				(optional nofail)
			)
			(if (= prefseditor 1)
				(copyfiles
					(help @copyfiles-help)
					(prompt "Copying JFIFDataType catalog...")
					(source "Locale/Catalogs/deutsch/JFIFDataType.catalog")
					(dest (tackon locale-dest "deutsch"))
					(optional nofail)
				)
			)
		)
	)
)

(complete 15)

;****************************************************************************
;
; JPEGTMP: assignment
;

(set has-temp 0)

(if (exists "JPEGTMP:" (noreq))
	(
		(set has-temp 1)
		(if (= "RAM" (getdevice "JPEGTMP:"))
			(set has-temp 0)
		)
	)
)

(if (= has-temp 1)
	(message #has-assign)
	;else
	(
		(set jpeg-tmp (askdir (help #temp-file) (prompt "Select a directory for temporary files, not in RAM:") (default "SYS:")))
		(startup "JFIF DataType"
			(help #make-assign)
			(prompt "An assignment has to be added to your user-startup.")
			(command "Assign JPEGTMP: \"" jpeg-tmp "\"")
		)
		(makeassign "JPEGTMP" jpeg-tmp)
	)
)

(complete 20)

;****************************************************************************
;
; Install DataTypes descriptor
;

(if (exists (tackon dt-dest "ILBM.info"))
	(
		(copyfiles
			(help @copyfiles-help)
			(prompt "Cloning icon...")
			(source (tackon dt-dest "ILBM.info"))
			(newname "JFIF.info")
			(dest "Devs/DataTypes")
			(optional nofail)
		)
		(tooltype
			(help @tooltype-help)
			(prompt "Unsnapshooting icon...")
			(dest "Devs/DataTypes/JFIF")
			(noposition)
		)
	)
)

(copyfiles
	(help #jfif-descr)
	(prompt "Copying JFIF DataTypes Descriptor...")
	(source "Devs/DataTypes/JFIF")
	(dest dt-dest)
	(infos)
	(confirm)
)

(complete 25)

;****************************************************************************
;
; Copy Documentation
;

(set doc-dir (askdir (help @askdir-help) (prompt "Select a directory for the documentation.") (default "HELP:english/")))
(copyfiles
	(help @copyfiles-help)
	(prompt "Copying JFIF.guide...")
	(source "JFIF.guide")
	(dest doc-dir)
	(infos)
	(optional nofail)
	(confirm)
)

(complete 30)

;****************************************************************************
;
; Copy Default settings
;

(if (or (not (exists "ENVARC:Classes/DataTypes/jfif.prefs")) (not (exists "ENV:Classes/DataTypes/jfif.prefs")))
	(
		(makedir "ENVARC:Classes")
		(copyfiles
			(help @copyfiles-help)
			(prompt "Copying default settings...")
			(source "Prefs/Env-Archive/Classes/DataTypes/jfif.prefs")
			(dest "ENVARC:Classes/DataTypes")
		)
		(makedir "ENV:Classes")
		(copyfiles
			(help @copyfiles-help)
			(prompt "Copying default settings...")
			(source "Prefs/Env-Archive/Classes/DataTypes/jfif.prefs")
			(dest "ENV:Classes/DataTypes")
		)
	)
)

(complete 35)

;****************************************************************************
;
; Install libraries and classes
;

(copylib
	(help @copylib-help)
	(prompt "Copying tower.library...")
	(source "Libs/tower.library")
	(dest libs-dest)
	(confirm)
)

(complete 45)

(copylib
	(help @copylib-help)
	(prompt "Copying codec.class...")
	(source "Classes/codec.class")
	(dest class-dest)
	(confirm)
)

(complete 55)

(copylib
	(help @copylib-help)
	(prompt "Copying picture.codec...")
	(source "Classes/Codecs/picture.codec")
	(dest (tackon class-dest "Codecs"))
	(confirm)
)

(complete 65)

(copylib
	(help @copylib-help)
	(prompt "Copying jpeg.codec...")
	(source "Classes/Codecs/jpeg.codec")
	(dest (tackon class-dest "Codecs"))
	(confirm)
)

(complete 90)

(copylib
	(help @copylib-help)
	(prompt "Copying jfif.datatype...")
	(source "Classes/DataTypes/jfif.datatype")
	(dest (tackon class-dest "DataTypes"))
	(confirm)
)

;****************************************************************************
;
; Exit
;

(if (= reboot 0)
	(
		(run "Avail >NIL: FLUSH")
		(run "AddDataTypes >NIL: Devs/DataTypes/JFIF")
		(complete 100)
		(exit #support-me "The JFIF DataType is now ready to be used.  Enjoy!")
	)
	; else
	(
		(complete 100)
		; every beta tester forgot to reboot...
		(user 1)
		(if (askbool (help #why-reboot) (prompt "Installation of JFIF DataType has been completed.\n\n" #support-me "A reboot is required before you can use the JFIFDataType.  Do you want to reboot now?") (choices "Reboot" "Cancel"))
			(run "Reboot")
		)
		(exit "\n*** YOU MUST REBOOT BEFORE USING THE DATATYPE ***")
	)
)

