; $VER: InstallPPaintCD 3.2
; Cloanto Personal Paint 7 Installation Script
; Copyright © 1996 Cloanto Italia srl
; Cloanto is a registered trademark of Cloanto Italia srl
; "Installer and Installer project icon Copyright © 1991-1993 Commodore-Amiga, Inc. All Rights Reserved
;  Reproduced and distributed under license from Commodore"
; New installer icon design Copyright © 1994 Cloanto Italia srl

(set id_lang_eng 0)
(set id_lang_deu 1)
(set id_lang_fra 3)
(set id_lang_ita 2)

(set id_item_ppaintcd 0)
(set id_item_ppaint 1)

(set kb_ppaintcd 665600)
(set kb_ppaint 1180)

(set installer_lang -1)

(if (= @language "Deutsch") (set installer_lang id_lang_deu))

(if (= installer_lang id_lang_deu) (
	(set #wrong-kick
		"Personal Paint erfordert mindestens Kickstart 1.2.")

	(set #wrong-wb
		"Personal Paint erfordert mindestens Workbench 1.3.")

	(set #which-items
		"Welche Teile sollen installiert werden?")
	(set #which-items-help
		(cat "\nEinzelne Bestandteile lassen sich auch individuell nachinstallieren. "
		"\"Gesamte CD-ROM\" enthält alle Elemente."
		"\n\nBitte entnehmen Sie weitere Informationen der Datei \"PPaintCD.guide\".\n\n"
		@askoptions-help))

	(set #item-ppaintcd "Gesamte CD-ROM (58 MByte)")
	(set #item-ppaint "Nur Personal Paint Software (1,6 MByte)")

	(set #which-dir-ppaintcd
		(cat "Bitte geben Sie an, wo das Verzeichnis \"PPaint\" "
		"angelegt werden soll."))
	(set #which-dir-ppaintcd-help
		(cat "\nBitte geben Sie ein Verzeichnis auf der Festplatte an, in dem "
		"das Verzeichnis \"PPaint\" angelegt werden soll (\"PPaint\" wird dem "
		"angegebenen Pfad automatisch angehängt)."
		"\n\nWenn das Verzeichnis \"PPaint\" unter dem angegebenen Pfad "
		"bereits existiert, werden die ursprünglichen Konfigurationsdateien "
		"durch die der neu installierten Programme evtl. überschrieben.\n\n"
		@askdir-help))

	(set #ask-startup-ppaintcd
		"\nPPaint-Assigns zur \"S:user-startup\"hinzufügen?")
	(set #ask-startup-ppaintcd-help
		(cat "\nDiese Funktion fügt einer Ihrer Startdateien einige "
		"Assign-Befehle hinzu, damit die installierten Elemente auch "
		"von der Festplatte geladen werden. Bei der Auswahl bestimmter "
		"Grafik- und Dokumentationsdateien werden die dazugehörigen "
		"Teile der Software automatisch gefunden.\n\n"
		@startup-help))

	(set #ask-diskfull
		(cat "\nEs scheint, als wäre nicht mehr genügend Speicherplatz "
		"zur Installation der gewünschten Elemente vorhanden. Möchten Sie "
		"dennoch fortfahren?"))
	(set #ask-diskfull-help
		(cat "\nWenn Sie sich dazu entscheiden, fortzufahren, wird die "
		"Installation möglicherweise vor ihrem Abschluß durch einen Fehler "
		"abgebrochen."))

	(set #busy-environment
		"Umgebung wird analysiert")
	(set #busy-defdirs
		"Standardverzeichnisse werden erstellt")
	(set #busy-ppaintcd
		"Gesamte CD-ROM wird installiert")
	(set #busy-ppaint
		"Personal Paint wird installiert")
	(set #busy-icons-reorg
		"Piktogramme werden angeordnet")
	(set #busy-startup
		"System-Startdateien werden aktualisiert")

	(set #prompt-cdrom
		"\nBitte die Personal Paint CD-ROM in ein beliebiges Laufwerk einlegen.")

	(set #warning-upgrade
		(cat "\nVorsicht: Die bereits existierende Version von "
		"Personal Paint ist aktueller als das Update. Möchten Sie "
		"die neuere Version wirklich mit einer älteren von der "
		"CD-ROM überschreiben?"))

	(set #warning-upgrade-help
		(cat "\nWenn Sie hier fortfahren, wird die aktuelle Version "
		"von Personal Paint mit großer Wahrscheinlichkeit durch eine "
		"ältere ersetzt."))

	(set #error-misc
		(cat "\nDer Installationsvorgang wurde durch einen Fehler unterbrochen."
		"\n\nMögliche Ursachen sind zu wenig Speicher (im RAM oder auf Disk), "
		"der Versuch, ein neues Verzeichnis über eine schon bestehende Datei mit dem "
		"gleichen Namen zu installieren oder ein Softwareproblem. "
		"\n\nWenn sich der Fehler nicht lösen läßt, entnehmen Sie bitte der "
		"Datei \"PPaintCD.guide\" Anweisungen zur manuellen Installation sowie zur  "
		"Fehlerbehebung und zum technischen Kundendienst, oder wenden Sie sich per "
		"E-Mail an <support@cloanto.com>."))

	(set #msg-complete
		"\nInstallation abgeschlossen.")

	(set @abort-button "Installation abbrechen")
))


(if (= @language "English") (set installer_lang id_lang_eng))

(if (= installer_lang -1) (set installer_lang id_lang_eng))

(if (= installer_lang id_lang_eng) (
	(set #wrong-kick
		"Personal Paint requires at least Kickstart 1.2.")

	(set #wrong-wb
		"Personal Paint requires at least Workbench 1.3.")

	(set #which-items
		"Please select the items to be installed:")
	(set #which-items-help
		(cat "\nIt is possible to install individual items at separate times. "
		"\"Entire CD-ROM\" includes the software, artwork and documentation."
		"\n\nPlease refer to \"PPaintCD.guide\" for additional instructions.\n\n"
		@askoptions-help))

	(set #item-ppaintcd "Entire CD-ROM (58 Mbytes)")
	(set #item-ppaint "Only Personal Paint Software (1.6 Mbytes)")

	(set #which-dir-ppaintcd
		(cat "Please specify where the \"PPaint\" drawer should "
		"be installed."))
	(set #which-dir-ppaintcd-help
		(cat "\nPlease specify a location on the hard-disk where the drawer "
		"named \"PPaint\" should be installed (\"PPaint\" is automatically "
		"appended to the path)."
		"\n\nPlease note that if \"PPaint\" already exists and "
		"contains some software, the configuration files of the "
		"newly installed programs may replace the existing files.\n\n"
		@askdir-help))

	(set #ask-startup-ppaintcd
		"\nAdd PPaint Assigns to \"S:user-startup\"?")
	(set #ask-startup-ppaintcd-help
		(cat "\nThis part adds some Assign commands to use the "
		"installed items from hard disk. In this way, when certain "
		"artwork and documentation files are selected, the Amiga "
		"will know where to find the necessary software.\n\n"
		@startup-help))

	(set #ask-diskfull
		(cat "\nIt is likely that there is not enough storage capacity "
		"to install the selected items. Do you wish to proceed "
		"anyway?"))
	(set #ask-diskfull-help
		(cat "\nIf you choose to proceed, the installation may "
		"be interrupted by an error before it is complete. If the current "
		"installation mainly replaces existing items, it may be safe to continue."))

	(set #busy-environment
		"Analyzing environment")
	(set #busy-defdirs
		"Creating default directories")
	(set #busy-ppaintcd
		"Installing entire CD-ROM")
	(set #busy-ppaint
		"Installing Personal Paint")
	(set #busy-icons-reorg
		"Arranging icons")
	(set #busy-startup
		"Updating system startup files")

	(set #prompt-cdrom
		"\nPlease insert the Personal Paint CD-ROM in any drive.")

	(set #warning-upgrade
		(cat "\nWarning: the existing version of Personal Paint "
		"appears to be newer than the update. Do you wish to replace "
		"the newer version with the older version from the CD-ROM?"))

	(set #warning-upgrade-help
		(cat "\nIf you choose to proceed, it is very likely that "
		"the currently installed version of Personal Paint will be replaced "
		"by an older version."))

	(set #error-misc
		(cat "\nAn error interrupted the installation procedure."
		"\n\nThis could be caused by a low memory condition (RAM or disk), "
		"by the selection of \"Make New Drawer\" where a file having the "
		"same name exists, or by a software error. "
		"\n\nIf the error cannot be resolved, please refer to "
		"\"PPaintCD.guide\" for instructions on manual installation, "
		"troubleshooting and technical support, or send E-mail to "
		"<support@cloanto.com>."))

	(set #msg-complete
		"\nInstallation complete.")

	(set @abort-button "Abort Install")
))

(onerror (
	(user 1)
	(message #error-misc)
	(exit (quiet))
	))

(procedure checkfree (
	(if (= (getdevice checkfree_dest)(getdevice "RAM:")) (
		(set bool_ramdest 1)
		(set kb_destfree (/ (+ (database "total-mem")) 1024))
		) (
		(set bool_ramdest 0)
		(set kb_destfree (/ (getdiskspace checkfree_dest) 1024))
		))
	))

(procedure destfull (
	(if (= source1 "") (set source1 #ask-diskfull) (set source1 (cat "\n" source1 "\n" #ask-diskfull)))
	(if (NOT (askbool
		(prompt source1)
		(help #ask-diskfull-help)
		(default 0)
		)) (
		(set install_items 0)
		))
	))

(procedure filecomp (
	(set compresult 2)

	(if (<> (exists source1) 1) (set compresult -1))
	(if (<> (exists target1) 1) (set compresult 1))

	(if (= compresult 2) (
		(if (= (getsize source1) (getsize target1)) (
			(if (NOT (OR (earlier source1 target1) (earlier target1 source1))) (set compresult 0) (
				(if (= (getsum source1) (getsum target1)) (
					(set compresult 0)
					))
				))
			))
		))

	(if (<> compresult 0) (
		(if (= compresult 2) (
			(if (< (getversion source1) (getversion target1)) (set compresult -1))
			(if (> (getversion source1) (getversion target1)) (set compresult 1))
			))

		(if (= compresult 2) (
			(if (earlier source1 target1) (set compresult -1))
			(if (earlier target1 source1) (set compresult 1))
			))

		(if (= compresult 2) (set compresult 1) )
		))
	))

(procedure makesubdir (
	(set target2 (tackon ppaintcd_dest cdrawername))

	(if (<> (exists target2) 2) (
		(if (= (exists target2) 1) (delete target2 (optional "force")))
		(makedir target2)
		))

	(copyfiles
		(source (tackon ppaintcd_source (cat cdrawername ".info")))
		(dest ppaintcd_dest)
		(optional "nofail" "force")
		(nogauge)
		)
	))

(procedure fixiconpos (
	(set target2 (tackon ppaintcd_dest cdrawername))

	(if (AND (= (exists target2) 2) (= (exists (cat target2 ".info")) 1)) (
		(run (cat (tackon ppaintcd_source "H/2/CopyIcon -p ") "\"" (tackon ppaintcd_source (cat "H/0/5/0/" cdrawernum)) "\" \"" (tackon ppaintcd_dest cdrawername) "\""))
		(if (AND (= cdrawernum 0)(= (exists (tackon ppaintcd_dest "PPaintCD.guide")) 1)) (run (cat (tackon ppaintcd_source "H/2/CopyIcon -p ") "\"" (tackon ppaintcd_source "H/0/5/0/PPaintCD.guide") "\" \"" (tackon ppaintcd_dest "PPaintCD.guide") "\"")))
		(run (cat (tackon ppaintcd_source "H/2/CopyIcon -f ") "\"" (tackon ppaintcd_source (cat "H/0/5/0/Parent" cdrawernum)) "\" \"" ppaintcd_dest "\""))
		(set cdrawernum (+ cdrawernum 1))
		))
	))

(procedure moveall (
	(if (= (exists target1) 2) (
		(copyfiles
			(source target1)
			(dest target2)
			(all)
			(infos)
			(optional "nofail" "force")
			(nogauge)
			)
		(run (cat "Delete >NIL: <NIL: \"" target1 "\" ALL QUIET"))
		(if (= (exists (cat target1 ".info")) 1) (delete (cat target1 ".info") (optional "force")) )
		))

	(if (= (exists target1) 1) (
		(filecomp)
		(if (<> compresult 0) (
			(copyfiles
				(source target1)
				(dest (pathonly target2))
				(optional "nofail" "force")
				(nogauge)
				)
			(delete target1 (optional "force"))
			))
		))
	))

(procedure itemoff (
	(if (IN install_items id_itemoff)(set install_items (- install_items (shiftleft 1 id_itemoff))))
	))

(procedure itemvaroff (
	(if (= (if (= (exists (cat "ENV:" requiredvar)) 1)(getenv requiredvar)("")) "FALSE") (itemoff))
	))

(procedure devonly (
	(if (<> (substr source1 (- (strlen source1) 1) 1) ":") (set source1 (expandpath (cat (getdevice source1) ":"))))
	(set source1 (substr source1 0 (- (strlen source1) 1)))
	))

(procedure intellassign (
	(set target1 "")
	(if (< verkick 37) (set target1 (getassign source1 "a")) (
		(if (= (run (cat "Assign >NIL: <NIL: \"" source1 ":\" EXISTS") (safe)) 0) (
			(run (cat "Assign >NIL: <NIL: TKCPIAT: \"" source1 ":\"") (safe))
			(set target1 (getassign "TKCPIAT" "a"))
			(run "Assign >NIL: <NIL: TKCPIAT:" (safe))
			))
		))
	))

(set trapreturn (trap 1 (

 (set verkick (/ (getversion "exec.library" (resident)) 65536))
 (set verwb (/ (getversion "icon.library" (resident)) 65536))

 (if (< verkick 33) (message #wrong-kick))
 (if (< verwb 34) (message #wrong-wb))

 (working #busy-environment)

 (set ppaintcd_source (expandpath (cat (getdevice (pathonly @icon)) ":")))
 (if (<> (exists (tackon ppaintcd_source "H/6/0/2/InstallPPaintCD")) 1) (set ppaintcd_source "PPaintCD:"))

 (set ppaintcd_dest (getassign "PCDPPAINT" "a"))
 (if (= (getdevice ppaintcd_source)(getdevice ppaintcd_dest)) (set ppaintcd_dest "") )
 (if (OR (< (getdiskspace ppaintcd_dest) 1048576)(= (getdevice ppaintcd_dest)(getdevice "RAM:"))) (set ppaintcd_dest ""))
 (if (<> ppaintcd_dest "") (set ppaintcd_dest (pathonly (expandpath ppaintcd_dest))))

 (if (= ppaintcd_dest "") (
	(set ppaintcd_dest (getassign "PPAINT" "a"))
	(if (= (getdevice ppaintcd_source)(getdevice ppaintcd_dest)) (set ppaintcd_dest "") )
	(if (OR (< (getdiskspace ppaintcd_dest) 1048576)(= (getdevice ppaintcd_dest)(getdevice "RAM:"))) (set ppaintcd_dest ""))
	(if (<> ppaintcd_dest "") (set ppaintcd_dest (pathonly (expandpath ppaintcd_dest))))
	))

 (if (= ppaintcd_dest "") (
	(set n 0)
	(while (set source1 (select n
		"BTITLER"
		"DPaint"
		"DeluxePaintIII"
		"DPaintIV"
		"DPaintV"
		"DPaintVI"
		"ADPRO"
		"PHOTOGENICS"
		"@2"
		"PWrite"
		"PFM2"
		"C1-Text"
		"PPage"
		"Fonts"
		""
		)) (
			(set n (+ n 1))
			(if (= source1 "@2") (
				(if (<> (getassign "PSUITEROOT" "a") "") (set n (+ n 2)))
				) (
				(if (= ppaintcd_dest "") ((intellassign) (set ppaintcd_dest target1)))
				))
		))

	(if (OR (< (getdiskspace ppaintcd_dest) 1048576)(= (getdevice ppaintcd_dest)(getdevice "RAM:"))) (set ppaintcd_dest ""))
	(if (<> ppaintcd_dest "") (set ppaintcd_dest (pathonly ppaintcd_dest)))

	(if (= ppaintcd_dest "") (set ppaintcd_dest (getassign "Work" "vda")))
	(if (= ppaintcd_dest "") (set ppaintcd_dest (getassign "Graphics" "vda")))
	(if (= ppaintcd_dest "") (set ppaintcd_dest (getassign "Video" "vda")))
	(if (= ppaintcd_dest "") (set ppaintcd_dest (getassign "Tools" "vd")))
	(if (= ppaintcd_dest "") (set ppaintcd_dest (getassign "DH1" "vd")))
	(if (= ppaintcd_dest "") (set ppaintcd_dest (getassign "HD1" "vd")))
	(if (= ppaintcd_dest "") (set ppaintcd_dest (getassign "QDH1" "vd")))
	(if (= ppaintcd_dest "") (set ppaintcd_dest (getassign "DH0" "vd")))
	(if (= ppaintcd_dest "") (set ppaintcd_dest (getassign "HD0" "vd")))
	(if (= ppaintcd_dest "") (set ppaintcd_dest (getassign "QDH0" "vd")))

	(if (= ppaintcd_dest "") (
		(set ppaintcd_dest @default-dest)
		(if (= @user-level 0) (user 1))
		))
	))

 (set checkfree_dest ppaintcd_dest) (checkfree)

 (set bool_drytargetmin (< kb_destfree kb_ppaint))
 (set bool_drytargetmax (< kb_destfree kb_ppaintcd))

 (set install_items -1)

 (set bool_checksyspf 0)

 (set id_itemoff id_item_ppaintcd)
 (if bool_drytargetmax (itemoff))

 (if bool_drytargetmin (set install_items 0))

 (set install_items (askoptions
	(prompt #which-items)
	(help #which-items-help)
	(choices #item-ppaintcd #item-ppaint)
	(default install_items)
	))

 (if (IN install_items id_item_ppaintcd) ((set id_itemoff id_item_ppaint)(itemoff)))

 (if (<> install_items 0) (
	(set ppaintcd_dest (askdir
		(prompt #which-dir-ppaintcd)
		(help #which-dir-ppaintcd-help)
		(default ppaintcd_dest)
		(newpath)
		))

	(set ppaintcd_dest (tackon ppaintcd_dest "PPaint"))
	(if (= (exists ppaintcd_dest) 1)(delete ppaintcd_dest (optional "force")))
	(if (= (exists ppaintcd_dest) 0)(makedir ppaintcd_dest (infos)))
	(run (cat (tackon ppaintcd_source "H/2/CopyIcon -f ") "\"" (tackon ppaintcd_source "H/0/5/0/PPaint") "\" \"" ppaintcd_dest "\""))

	(set @default-dest ppaintcd_dest)
	) (set @default-dest ""))

 (if (IN install_items id_item_ppaint) (set ppaintcd_source (tackon ppaintcd_source "H/0/6/4")))

 (if (<> install_items 0) (
	(set target1 (tackon ppaintcd_dest "Old"))
	(if (<> (exists target1) 2) (
		(if (= (exists target1) 1) (delete target1 (optional "force")))
		(makedir target1)
		))

	(set target1 (tackon target1 "PPaint_Prefs"))
	(if (<> (exists target1) 2) (
		(if (= (exists target1) 1) (delete target1 (optional "force")))
		(makedir target1)
		))

	(set n 0)
	(while (set currentfile (select n
		"PPaint.man"
		"ReadMe"
		"Readme.txt"
		"Bitte_Lesen"
		"Leggere"
		"Informazioni"
		"E-reg.txt"
		"InstallPPaint"
		"English"
		"Deutsch"
		"Français"
		"Italiano"
		"PPaint_Tools"
		"PPaint_Icons"
		"PPaint_Icons_1"
		"PPaint_Icons_2"
		"JPEG"
		"HP_DeskJet"
		"CloantoAudio.info"
		"Fonts.info"
		"PPaint_PS.info"
		"Shell.info"
		"Preferences"
		"PPaint_Prefs/Startup_1.set"
		"PPaint_Prefs/Startup_2.set"
		"PPaint_Prefs/Startup_A.set"
		"PPaint_Prefs/Startup.pic"
		"PPaint_Prefs/UIGraphics.pic"
		"PPaint_Prefs/UIColors.6"
		"PPaint_Prefs/UIColors.12"
		""
		)) (
		(set n (+ n 1))

		(set source1 (tackon ppaintcd_source (cat "H/0/6/4/" currentfile)))
		(set target1 (tackon ppaintcd_dest currentfile))
		(set target2 (tackon ppaintcd_dest (cat "Old/" currentfile)))
		(if (<> (exists target1) 0) (moveall))

		(set source1 (cat source1 ".info"))
		(set target1 (cat target1 ".info"))
		(set target2 (cat target2 ".info"))
		(if (<> (exists target1) 0) (moveall))
	))

	(set target1 (tackon target1 "PPaint_4.0"))
	(if (= (exists target1) 1) (delete target1 (optional "force")))

	(set target1 (tackon ppaintcd_dest "Stereograms"))
	(set target2 (tackon ppaintcd_dest "Pictures"))
	(if (= (exists target1) 2) (
		(if (<> (exists target2) 2) (
			(if (= (exists target2) 1) (delete target2 (optional "force")))
			(makedir target2)
			))

		(set target2 (cat target2 "/Stereograms"))
		(moveall)
		))

	(set target1 (tackon ppaintcd_dest "Patterns"))
	(set target2 (tackon ppaintcd_dest "Brushes"))
	(if (= (exists target1) 2) (
		(if (<> (exists target2) 2) (
			(if (= (exists target2) 1) (delete target2 (optional "force")))
			(makedir target2)
			))

		(set target2 (cat target2 "/Patterns"))
		(moveall)
		))

	(copyfiles
		(source ppaintcd_source)
		(dest ppaintcd_dest)
		(all)
		(optional "nofail" "force")
		)

	(copyfiles
		(source (tackon ppaintcd_dest "PPView"))
		(dest "C:")
		(optional "nofail" "force")
		(nogauge)
		)

	(if (<> (getassign "ENVARC" "a") "") (
		(if (= (exists "ENVARC:Sys/def_Drawer.info") 1) (
			(copyfiles
				(source "ENVARC:sys/def_Drawer.info")
				(dest (tackon ppaintcd_dest "PPaint_Icons"))
				(optional "nofail" "force")
				(nogauge)
				)
			))
		))

	(if (AND (> (getdiskspace "FONTS:") 5120) (= (exists "FONTS:Personal/8") 1)) (
		(copyfiles
			(source (tackon ppaintcd_dest "fonts/Personal"))
			(dest "FONTS:Personal")
			(all)
			(optional "nofail" "force")
			(nogauge)
			)
		(copyfiles
			(source (tackon ppaintcd_dest "fonts/Personal.font"))
			(dest "FONTS:")
			(optional "nofail" "force")
			(nogauge)
			)
		))

	(set source1 (tackon ppaintcd_source "fonts/Personal/8"))
	(set target1 "SYS:fonts/Personal/8")

	(if (= (exists target1) 1) (
		(filecomp)
		(if (= compresult 1) (

			(copyfiles
				(source (tackon ppaintcd_source "fonts/Personal"))
				(dest "SYS:fonts/Personal")
				(all)
				(optional "nofail" "force")
				(nogauge)
				)
			(copyfiles
				(source (tackon ppaintcd_source "fonts/Personal.font"))
				(dest "SYS:fonts")
				(optional "nofail" "force")
				(nogauge)
				)
			))
		))

	(set target1 "FONTS:Personal/8")

	(if (= (exists target1) 1) (
		(filecomp)
		(if (= compresult 1) (

			(copyfiles
				(source (tackon ppaintcd_source "fonts/Personal"))
				(dest "FONTS:Personal")
				(all)
				(optional "nofail" "force")
				(nogauge)
				)
			(copyfiles
				(source (tackon ppaintcd_source "fonts/Personal.font"))
				(dest "FONTS:")
				(optional "nofail" "force")
				(nogauge)
				)
			))
		))

	(if (<> (getdevice ppaintcd_dest)(getdevice "RAM:")) (
		(working #busy-startup)
		(set startup_command (cat "Assign PPAINT: \"" ppaintcd_dest "\"\n"))
		(startup "Personal Paint"
			(prompt (cat #ask-startup-ppaintcd "\n\n" startup_command))
			(help #ask-startup-ppaintcd-help)
			(command startup_command)
			)

		(if (IN install_items id_item_ppaintcd) (
			(set startup_command (cat "Assign PPAINTCD: \"" ppaintcd_dest "\"\n"))
			(startup "Personal Paint CD-ROM"
				(prompt (cat #ask-startup-ppaintcd "\n\n" startup_command))
				(help #ask-startup-ppaintcd-help)
				(command startup_command)
				)
			))
		))
	))

 (message #msg-complete)

 (exit (quiet))

)))

(if (> trapreturn 1) (abort))

(exit (quiet))
