;***************************************************************************************************
;***************************************************************************************************
;***
;***	X-Phone installation script
;***	===========================
;***
;***	$VER: 1.4 (16.08.99)
;***
;***	©1998-99 by Carsten 'michelangelo' Scholling
;***
;***
;***
;***	No changes outside of strings- and main-part!
;***
;***
;***************************************************************************************************
;***************************************************************************************************


;***************************************************************************************************
;***	Error handling stuff
;***************************************************************************************************
(onerror (P_Cleanup))


;***************************************************************************************************
;***	Configuration defaults
;***************************************************************************************************
(set #unarc			0)							;*** Unarchive (installation with archive).

(set #prgname		"X-Phone")					;*** Simply the program name.
(set #dirname		"XPhone")					;*** Directory name to be created at first install.

(set #dest			"Sys:Utilities")			;*** Default installation path. Primary needed for update check.
(set #oldinstdirvar	"XPhone.oid")				;*** Name of the environment var to save the installation dir to.
(set #destback		"SYS:Storage")				;*** Default backup path.
(set #destbackdir	"XPhone_Backup")			;*** Default backup directory.

(set #instarc		"xpinst.lha")				;*** Installation archive name.
(set #lhexname		"lhex")						;*** Unarchiver name
(set #lhexopts		"-q -f -w=")				;*** lhex options
(set #lhexcmd		"x")						;*** lhex parameters
(set #tempdir		"ram:")						;*** Temporary directory for unarchiving
(set #tempexdir		"ram:")						;*** Temporary directory for unarchiving included archives
(set #tempinstdir	"XPhone")					;*** Directory which holds installation files after extraction

(set #instchoice	0)							;*** Global installation choice (0 = update, 1 = new, 2 = back, 3 = deinstall, 4= break)
(set #instparts		%01111111)					;*** Bit mask of parts to install (0 = main, 1 = configs, 2 = docs, 3 = htmldocs, 4 = Rexx 5 = tools, 6 = MUI-classes)

(set #defcat		%00000011)					;*** Default bit mask for available catalogs (0 = english, 1 = deutsch, 2 = fraçais, ...)
(set #defdoc		%00000010)					;*** Default bit mask for available documentation (0 = english, 1 = deutsch, 2 = fraçais, ...)
(set #defhtml		%00000010)					;*** Default bit mask for available HTML documentation (0 = english, 1 = deutsch, 2 = fraçais, ...)

(set #minosver		36)							;*** Minimum OS version
(set #mincpu		0)							;*** Minimum CPU.


;***************************************************************************************************
;***	Debugging stuff
;***************************************************************************************************
(set #dbg 0)

(if (= 1 #dbg) (
	(set #unarc 0)
))



;***************************************************************************************************
;***	Strings
;***************************************************************************************************

;***
;*** German strings
;***
(if (= @language "deutsch") (

	(set #wronginstaller	(cat    "Achtung! Sie benutzen eine alte Version des Programmes\n"
									"'Installer' oder den 'SavageInstaller'.\n\n"
									"Dieses Installationsscript benötigt mindestens Installer 43.3\n"
									"und läuft NICHT mit dem SavageInstaller.\n\n"
									"Bitte überprüfen Sie Ihre Konfiguration!"))

	(set #msgunknown				"Unbekannt")

	(set #msgmakedir				"\nFolgendes Verzeichnis wird nun erstellt:\n\n%s")

	(set #msgdelete					"\nFolgende Datei wird jetzt gelöscht:\n\n%s")

	(set #msgcopy					"Folgende Datei wird jetzt kopiert: %s")
	(set #msgcopymany				"Folgende Dateien werden jetzt kopiert:")
	(set #msgcopycat				"Soll diese Katalogdatei jetzt kopiert werden: %s?")

	(set #msgwelcome		(cat	("\nWillkommen zur \n\n%s Installation.\n\n" #prgname)))

	(set #msgcopyright		(cat	"Copyright ©1998-99 by Apocalypse Hard- und Software\n"
									"Carsten Scholling\n\n"
									"<cscholling@vmc.de>\n"
									"http://www.vmc.de/cscholling\n\n"))

	(set #msgoldinst		(cat	"Ich habe eine alte " #prgname " Installation auf Ihrem System gefunden.\n"
									"Bitte wählen Sie, wie die Installation fortgesetzt werden soll.\n"))

	(set #msgoldfilesexp	(cat	"\n\n\nEs müssen einige alte Dateien aus dem System entfernt werden.\n"
									"Sie können im folgenden das Löschen jeder Datei einzeln bestätigen.\n"))

	(set #msgoldfilesave			"\n\n\nEs werden nun einige alte Dateien aus dem System entfernt.\n")

	(set #msgoldfiles2				"Bitte deselektieren Sie die Dateien/Verzeichnisse\ndie nicht gelöscht werden sollen:\n")

	(set #msgoldinstupdate			"Update der alten Version")
	(set #msgoldinstnew				"Komplette Neuinstallation")
	(set #msgoldinstback			"Backup anlegen, anschließend neu installieren")
	(set #msgoldinstdeinst			"Alte Version deinstallieren")
	(set #msgoldinstend				"Programm beenden")

	(set #msgwhichparts		(cat	"\nWelche Komponenten sollen installiert werden?\nAlle nicht selektierten Komponenten werden,\n"
									"sofern vorhanden, automatisch deinstalliert!\n"))
	(set #msgwhichpartmain			"Hauptprogramm")
	(set #msgwhichpartconfigs		"Beispiel-Konfigurationen")
	(set #msgwhichpartdocs			"Dokumentation")
	(set #msgwhichparthtml			"HTML Dokumentation")
	(set #msgwhichpartrexx			"ARexx Beispiel-Scripte")
	(set #msgwhichparttools			"Utilities")
	(set #msgwhichpartmuic			"Externe MUI-Klassen")

	(set #msgwhichcatalogs			"Welche Katalogdateien sollen installiert werden?")
	(set #msgwhichdocs				"Welche Dokumentation soll installiert werden?")
	(set #msgwhichhtml				"Welche HTML Dokumentation soll installiert werden?")

	(set #msgworkingbackup			"\nErstelle ein Backup der alten Installation...\n")
	(set #msgworkingsearchold		"\nSuche nach bereits installierten Komponenten... ;-)\n")
	(set #msgworkingprepareinst		"\nBereite die Installation vor...\n")
	(set #msgworkingpreparedeinst	"\nBereite die Deinstallation vor...\n")
	(set #msgworkinginst			"\nArbeite an der Installation...\n")
	(set #msgworkingdeinst			"\nArbeite an der Deinstallation...\n")
	(set #msgworkingcleanup			"\nTemporäre Dateien werden entfernt...\n")

	(set #msguptodate		(cat	"Die zu installierende " #prgname " Version ist auf dem neusten Stand.\n"
									"Bitte wählen Sie, ob Sie eine Neu- oder Deinstallation wünschen, oder\n"
									"ob der Installer beendet werden soll.\n"))

	(set #msgaskdest		(cat	"In welchem Verzeichnis soll " #prgname " installiert werden?\n"
									"Es wird ein Verzeichnis `" #dirname "' erstellt!\n"))
	(set #msgaskback		(cat	"In welchem Verzeichnis soll das Backup von\n" #prgname " erstellt werden?\n"
									"Es wird ein Verzeichnis `" #destbackdir "' erstellt!\n"))

	(set #msgconfirm				"Die folgenden Daten werden zur Installation herangezogen:\n")
	(set #msgconfirmdeinst			"Die folgenden Daten werden zur Deinstallation herangezogen:\n")
	(set #msgconfirm2				"\nProzessor: %s\nFPU: %s\nBetriebssystem: %s")
	(set #msgconfirminstmuic		"\nExterne MUI-Klassen werden installiert.")
	(set #msgconfirmdest			"\n\nZielverzeichnis: %s")
	(set #msgconfirmbackdest		"\nBackup: %s")
	(set #msgconfirmask				"\n\nSoll ich mit diesen Einstellungen fortfahren?")

	(set #msgmuicinfo		(cat	"\nFür " #prgname " werden folgende externe MUI-Klassen benötigt:\n\n"
									"MCC_Toolbar, MCC_NList, MCC_Listtree, MCC_Lamp,\n"
									"MCC_InfoText, MCC_Busy.\n\n"
									"Im folgenden werden diese Klassen installiert."))
	(set #msglaunchinstaller		"\nDer Installer wird nun gestartet um\n\n%s\n\n zu installieren.")
	(set #msginstallmuic			"\nFür\n\n%s\n\n werden jetzt nur die Klassen selbst\ndurch dieses Script installiert.")
;	(set #msginstallmuic	(cat	"\nFür\n\n%s\n\nwird kein Installer-Script mitgeliefert. Es werden\n"
;									"jetzt nur die Klassen selbst durch dieses Script installiert."))
	(set #msgunarc					"\nEntpacke Archiv %s\n")
	(set #msginstallmuiclass		"\nFolgende MUI Klasse wird jetzt installiert: %s\n")

	(set #msgaskconvertwt	(cat	"\nSoll die Konfiguration von WilhelmTEL automatisch in die von\n"
									#prgname " konvertiert werden?"))
	(set #msgselectwtdir	(cat	"In welchem Verzeichnis ist WilhelmTEL installiert? Wählen Sie\n"
									"bitte das Verzeichnis in dem sich die DATEI TEL befindet!"))
	(set #msgconvwtsuccess			"\nDie WilhelmTEL Konfiguration wurde erfolgreich konvertiert!")
	(set #msgconvwtnosuccess		"\nDie WilhelmTEL Konfiguration wurde NICHT konvertiert!")

	(set #msgendinst		(cat	"\n" #prgname " Installation beendet!\n\n"))
	(set #msgenddeinst		(cat	"\n" #prgname " Deinstallation beendet!\n\n"))
	(set #msgend2			(cat	"\n" #prgname " Programm durch Benutzer beendet!\n\n"))

	(set #readmefile				"LiesMichZuerst.guide")
	(set #msgshowreadme		(cat	"\nSoll jetzt die Datei " #readmefile " angezeigt werden?\n"))

	(set #msgreboot					"\nDer Rechner MUß nach dieser Installation neu gestartet\nwerden. Soll das jetzt geschehen?\n")
	(set #msgrebootyes				"Reboot")
	(set #msgrebootno				"KEIN Reboot")
)

;***
;*** English strings
;***
(
	(set #wronginstaller	(cat    "Attention! You are unsing an old version of the programm\n"
									"'Installer' or the 'SavageInstaller'.\n\n"
									"This installation-script needs at least Installer 43.3\n"
									"and does NOT work with the SavageInstaller.\n\n"
									"Please check your configuration!"))

	(set #msgunknown				"Unknown")

	(set #msgmakedir				"\nThe following directory will be created now:\n\n%s")

	(set #msgdelete					"\nThe following file will be deleted now:\n\n%s")

	(set #msgcopy					"The following file will be copied now: %s")
	(set #msgcopymany				"The following files will be copied now:")
	(set #msgcopycat				"Should i copy this catalog now: %s")

	(set #msgwelcome		(cat	("\nWelcome to the\n\n%s installation.\n\n" #prgname)))

	(set #msgcopyright		(cat	"Copyright ©1998-99 by Apocalypse Hard- and Software\n"
									"Carsten Scholling\n\n"
									"<cscholling@vmc.de>\n"
									"http://www.vmc.de/cscholling\n\n"))

	(set #msgoldinst		(cat	"I have found an old " #prgname " installation on your system.\n"
									"Please choose, how to continue the installation.\n"))

	(set #msgoldfilesexp	(cat	"\n\n\nThere are some old files which must be deleted before installing.\n"
									"You can confirm each file and directory.\n"))

	(set #msgoldfilesave			"\n\n\nI am deleting some old files from your system.\n")

	(set #msgoldfiles2				"Please deselect all files/dirs,\nthat should not to be deleted:\n")

	(set #msgoldinstupdate			"Update old version")
	(set #msgoldinstnew				"Complete new installation")
	(set #msgoldinstback			"Backup and install new")
	(set #msgoldinstdeinst			"Remove installation")
	(set #msgoldinstend				"Abort installation")

	(set #msgwhichparts		(cat	"\nWhich components should be installed?\nAll unselected components will be \n"
									"deinstalled automatically!\n"))
	(set #msgwhichpartmain			"Main program files")
	(set #msgwhichpartconfigs		"Example configurations")
	(set #msgwhichpartdocs			"Documentation")
	(set #msgwhichparthtml			"HTML Documentation")
	(set #msgwhichpartrexx			"ARexx sample scripts")
	(set #msgwhichparttools			"Utilities")
	(set #msgwhichpartmuic			"External MUI-classes")

	(set #msgwhichcatalogs			"Which catalog files do you want me to install?")
	(set #msgwhichdocs				"Which documentation do you want me to copy?")
	(set #msgwhichhtml				"Which HTML documentation do you want me to copy?")

	(set #msgworkingbackup			"\nCreate backup of the old installation...\n")
	(set #msgworkingsearchold		"\nSearching for installed components... ;-)\n")
	(set #msgworkingprepareinst		"\nPreparing installation...\n")
	(set #msgworkingpreparedeinst	"\nPreparing deinstallation...\n")
	(set #msgworkinginst			"\nWorking on installation...\n")
	(set #msgworkingdeinst			"\nWorking on deinstallation...\n")

	(set #msguptodate		(cat	"The installed version of " #prgname " is up to date.\n"
									"Please choose if you want a complete new installation, \n"
									"deinstallation or quitting.\n"))

	(set #msgaskdest		(cat	"Where should i install " #prgname "?\n"
									"A directory " #dirname " will be created there!\n"))
	(set #msgaskback		(cat	"Where should i copy the backup files?\n"
									"A directory " #destbackdir " will be created there!\n"))

	(set #msgconfirm				"The following information will be used for installation:\n")
	(set #msgconfirmdeinst			"The following information will be used for deinstallation:\n")
	(set #msgconfirm2				"\nCPU: %s\nFPU: %s\nOS type: %s")
	(set #msgconfirminstmuic		"\nExternal MUI-classes will be installed.")
	(set #msgconfirmdest			"\n\nDestination dir: %s")
	(set #msgconfirmbackdest		"\nBackup: %s")
	(set #msgconfirmask				"\n\nShould i use this settings?")

	(set #msgmuicinfo		(cat	"\nYou need some external MUI-classes for " #prgname " to run:\n\n"
									"MCC_Toolbar, MCC_NList, MCC_Listtree, MCC_Lamp,\n"
									"MCC_InfoText, MCC_Busy.\n\n"
									"These classes will be installed now."))
	(set #msglaunchinstaller		"\nThe Installer will be launched now to install\n\n%s")
	(set #msginstallmuic			"\nFor\n\n%s\n\nnow only the classes itself\nwill be installed.")
;	(set #msginstallmuic	(cat	"\nFor\n\n%s\n\nno Installer-script is supplied. Now only the\n"
;									"classes itself will be installed."))
	(set #msgaskconvertwt	(cat	"\nShould i convert the WilhelmTEL configuration automatically into\n"
									#prgname " configuration?"))
	(set #msgselectwtdir	(cat	"In which directory is WilhelmTEL installed? Please choose the dir\n"
									"with the executable FILE TEL!"))
	(set #msgconvwtsuccess			"\nThe WilhelmTEL configuration was successfully converted!")
	(set #msgconvwtnosuccess		"\nThe WilhelmTEL configuration was NOT converted!")

	(set #msgunarc					"\nUnpacking archive %s\n")
	(set #msginstallmuiclass		"\nFollowing MUI class will be installed now: %s\n")

	(set #msgendinst		(cat	"\n" #prgname " Installation done!\n\n"))
	(set #msgenddeinst		(cat	"\n" #prgname " Deinstallation done!\n\n"))
	(set #msgend2			(cat	"\n" #prgname " Installation aborted by user!\n\n"))

	(set #readmefile				"ReadMeFirst.guide")
	(set #msgshowreadme				"\nDo you want me to show " #readmefile " now?\n")

	(set #msgreboot					"\nYou MUST reboot after this installation to use\nthe new software. Should i reboot now?\n")
	(set #msgrebootyes				"Reboot")
	(set #msgrebootno				"NO reboot")
))



;***************************************************************************************************
;***************************************************************************************************
;***
;***	!!! NO CHANGES BEHIND THIS LINE !!!
;***
;***************************************************************************************************
;***************************************************************************************************






;***************************************************************************************************
;***************************************************************************************************
;***
;***	Standard procedures
;***
;***************************************************************************************************
;***************************************************************************************************

;***************************************************************************************************
;***	Procedure CheckOS
;***************************************************************************************************
(procedure P_CheckOS

	(set #os (/ (getversion "libs:version.library") 65536))

	(set v 0)

	(while (<> #os
		(select v 36 37 38 39 40 41 os))
		(set v (+ v 1))
	)

	(set #osname
		(select v "2.0pre" "2.0" "2.1" "3.0" "3.1" "3.5" #msgunknown)
	)

	(if (>= #os #minosver)
		(set ret #os)
		(set ret 0)
	)
)


;***************************************************************************************************
;***	Procedure CheckCPU
;***************************************************************************************************
(procedure P_CheckCPU

	(set #cpuname	(database "cpu"))
	(set #fpuname	(database "fpu"))

	(if (= #cpuname "68000")	(set #cpu 0))
	(if (= #cpuname "68010")	(set #cpu 1))
	(if (= #cpuname "68020")	(set #cpu 2))
	(if (= #cpuname "68030")	(set #cpu 3))
	(if (= #cpuname "68040")	((set #cpu 4) (set #fpuname "FPU040")))
	(if (> (exists ("sys:libs/68060.library")) 0) (
		(set #cpuname "68060")
		(set #cpu 6)
	))

	(if (= #fpuname "NOFPU")	(set #fpu 0))
	(if (= #fpuname "68881")	(set #fpu 1))
	(if (= #fpuname "68882")	(set #fpu 2))
	(if (= #fpuname "FPU40")	(set #fpu 4))
	(if (= #fpuname "FPU040")	(set #fpu 4))
	(if (> (exists ("sys:libs/68060.library")) 0) (
		(set #fpuname "FPU060")
	))

	(if (>= #cpu #mincpu)
		(set ret 1)
		(set ret 0)
	)
)


;***************************************************************************************************
;***	Procedure GetVersion <file>
;***************************************************************************************************
(procedure P_GetVersion p_file

	(set ver	(shiftright (BITAND (getversion p_file) $ffff0000) 16))
)


;***************************************************************************************************
;***	Procedure GetRevision <file>
;***************************************************************************************************
(procedure P_GetRevision p_file

	(set rev	(BITAND (getversion p_file) $ffff))
)


;***************************************************************************************************
;***	Procedure GetFullVersion <file>
;***************************************************************************************************
(procedure P_GetFullVersion p_file

	(set vers	(cat (P_GetVersion p_file ) "." (P_GetRevision p_file )))
)


;***************************************************************************************************
;***	Procedure CheckExists <file>
;***************************************************************************************************
(procedure P_CheckExists p_file

	(set ret (exists p_file (noreq)))
)


;***************************************************************************************************
;***	Procedure CheckExistsPat <path> <pattern>
;***************************************************************************************************
(procedure P_CheckExistsPat p_path p_pat

	(set patexists 0)

	(if (P_CheckExists p_path) (

		(run (cat "list >t:$csinstcheckpat.tmp " p_path " pat " p_pat " lformat \"%n\"") (safe))

		(if (> (getsize "t:$csinstcheckpat.tmp") 0) (set patexists 1))

		(delete "t:$csinstcheckpat.tmp" (safe))
	))

	(set patexists patexists)
)


;***************************************************************************************************
;***	Procedure Rename <file> <newname>
;***************************************************************************************************
(procedure P_Rename p_file p_new p_confforce

	(rename p_file p_new
		(prompt (cat #msgrename1 p_file #msgrename2 p_new))
		(help (cat #msgrename1 p_file #msgrename2 p_new))
		(confirm "expert")
	)
)


;***************************************************************************************************
;***	Procedure MakeDir <path> <name> <NOICONS>
;***************************************************************************************************
(procedure P_MakeDir p_path p_noicons

	(if (<> 2 (P_CheckExists p_path)) (

		(if (<> p_noicons "noicons")
			(makedir p_path
				(prompt (#msgmakedir p_path))
				(help (cat (#msgmakedir p_path) "\n\n" @makedir-help))
				(infos)
				(confirm "expert")
			)
			(makedir p_path
				(prompt (#msgmakedir p_path))
				(help (cat (#msgmakedir p_path) "\n\n" @makedir-help))
				(confirm "expert")
			)
		)
	))
)


;***************************************************************************************************
;***	Procedure Delete <file> <NOICONS> <NOREQ>
;***************************************************************************************************
(procedure P_Delete p_file p_noicons p_noreq

	(if (= p_noreq "noreq") (

		(if (<> p_noicons "noicons")
			(delete p_file
				(prompt		(#msgdelete p_file))
				(help		(#msgdelete p_file))
				(optional	"force" "askuser")
				(infos)
				(all)
			)
			(delete p_file
				(prompt		(#msgdelete p_file))
				(help		(#msgdelete p_file))
				(optional	"force" "askuser")
				(all)
			)
		)
	)
	(
		(if (<> p_noicons "noicons")
			(delete p_file
				(prompt		(#msgdelete p_file))
				(help		(#msgdelete p_file))
				(optional	"force" "askuser")
				(confirm	"expert")
				(infos)
				(all)
			)
			(delete p_file
				(prompt		(#msgdelete p_file))
				(help		(#msgdelete p_file))
				(optional	"force" "askuser")
				(confirm	"expert")	
				(all)
			)
		)
	))
)


;***************************************************************************************************
;***	Procedure SelectDir <default dest> <text> <helptext>
;***************************************************************************************************
(procedure P_SelectDir p_dest p_text p_help

	;*** Ask the user for any directory.
	;***
	(set p_dest
		(askdir
			(prompt		p_text)
			(help		(cat p_help "\n\n" @askdir-help))
			(default	p_dest)
		)
	)

	(set p_dest p_dest)
)


;***************************************************************************************************
;***	Procedure MakeFileList	<base filename> <directory> <pattern> <options>
;***							<initial counter> <initial recurs. counter>
;***
;***	Option-bits: 0 = Include subdirectories, 1 = Only files
;***************************************************************************************************
(procedure P_MakeFileList p_bfname p_dir p_pat p_opts p_cnt p_xcnt

	(if (P_CheckExistsPat p_dir p_pat) (

		(foreach p_dir p_pat (

			;*** Recursively call.
			;***
			(set savefile (tackon p_dir @each-name))

			(if (<> savefile "" ) (

				(if (OR (NOT (IN p_opts 1)) (< @each-type 0)) (

					(textfile (dest (cat p_bfname "." p_cnt)) (append savefile) (safe))
					(set p_cnt (+ 1 p_cnt))
				))
			))

			(if (IN p_opts 0) (

				(if (> @each-type 0) (

					(set p_xcnt (+ p_xcnt 1))

					(P_MakeFileList p_bfname savefile "#?" p_opts p_cnt p_xcnt)

					(set p_xcnt (- p_xcnt 1))
					(set p_dir (pathonly p_dir))
					(set p_pat "#?")
				))
			))
		))
	))

	(set p_cnt p_cnt)
)


;***************************************************************************************************
;***	Procedure CopyLib <source> <destination>
;***************************************************************************************************
(procedure P_CopyLib p_src p_dest

	(copylib
		(prompt		(#msgcopy p_src))
		(help		(cat (#msgcopy p_src) "\n\n" @copylib-help))
		(source		p_src)
		(dest		p_dest)
		(confirm	"expert")
		(infos)
	)
)

;***************************************************************************************************
;***	Procedure CopyLibPat <source> <pattern> <destination>
;***************************************************************************************************
(procedure P_CopyLibPat p_src p_pat p_dest

	(foreach p_src p_pat
		(P_CopyLib (tackon p_src @each-name) p_dest)
	)
)

;***************************************************************************************************
;***	Procedure Copy <source> <destination>
;***************************************************************************************************
(procedure P_Copy p_src p_dest

	(copyfiles
		(prompt		(#msgcopy p_src))
		(help		(cat (#msgcopy p_src) "\n\n" @copylib-help))
		(source		p_src)
		(dest 		p_dest)
		(confirm	"expert")
		(infos)
	)
)

;***************************************************************************************************
;***	Procedure CopyPat <source> <pattern> <destination>
;***************************************************************************************************
(procedure P_CopyPat p_src p_pat p_dest

	(copyfiles
		(prompt		(#msgcopymany p_src))
		(help		(cat (#msgcopymany p_src) "\n\n" @copylib-help))
		(source		p_src)
		(dest 		p_dest)
		(pattern	p_pat)
		(confirm	"expert")
		(infos)
	)
)


;***************************************************************************************************
;***	Procedure SelectLanguage <text> <directory> <default options>
;***************************************************************************************************
(procedure P_SelectLanguage p_text p_dir p_defopt

	(set lang0 "")
	(set lang1 "")
	(set lang2 "")
	(set lang3 "")
	(set lang4 "")
	(set lang5 "")
	(set lang6 "")
	(set opt %00000000)

	;*** English always there (built in)
	;***
	(if (IN p_defopt 0) (
		(set lang0 "English (built-in)")
		(set opt %00000001)
	))
	(if (OR (P_CheckExists (tackon p_dir "Deutsch")) (P_CheckExists (tackon p_dir "ger"))) (
		(set lang1 "Deutsch")
		(set opt (+ opt %00000010))
	))
	(if (OR (P_CheckExists (tackon p_dir "Français")) (P_CheckExists (tackon p_dir "fra"))) (
		(set lang2 "Français")
		(set opt (+ opt %00000100))
	))
	(if (OR (P_CheckExists (tackon p_dir "Dansk")) (P_CheckExists (tackon p_dir "dan"))) (
		(set lang3 "Dansk")
		(set opt (+ opt %00001000))
	))
	(if (OR (P_CheckExists (tackon p_dir "Español")) (P_CheckExists (tackon p_dir "esp"))) (
		(set lang4 "Español")
		(set opt (+ opt %00010000))
	))
	(if (OR (P_CheckExists (tackon p_dir "Italiano")) (P_CheckExists (tackon p_dir "ita"))) (
		(set lang5 "Italiano")
		(set opt (+ opt %00100000))
	))
	(if (OR (P_CheckExists (tackon p_dir "Svenska")) (P_CheckExists (tackon p_dir "sve"))) (
		(set lang6 "Svenska")
		(set opt (+ opt %01000000))
	))

	(set opt (BITAND opt p_defopt))

	(set opt
		(askoptions
			(prompt		p_text)
			(help		(cat p_text "\n\n" @askoptions-help))
			(choices	lang0 lang1 lang2 lang3 lang4 lang5 lang6)
			(default	opt)
		)
	)

	(set opt opt)
)



;***************************************************************************************************
;***	Procedure CopyLanguage <source> <destination> <base name> <default options>
;***************************************************************************************************
(procedure P_CopyLanguage p_src p_dest p_bname p_opt p_short

	(set n 0)
	(set lang "")

	(while
		(if (= 0 p_short)
			(set lang
				(select n
					"English"
					"Deutsch"
					"Français"
					"Dansk"
					"Español"
					"Italiano"
					"Svenska"
					""
				)
			)

			(set lang
				(select n
					"eng"
					"ger"
					"fra"
					"dan"
					"esp"
					"ita"
					"sve"
					""
				)
			)
		)
		(
			(if (IN p_opt n)
				(if (<> 0 n) (

					(set src	(tackon p_src lang))
					(set desti	(tackon p_dest lang))

					(if (P_CheckExists (tackon src p_bname)) (

						(P_MakeDir	desti "icons")

						(copylib
							(prompt		(#msgcopycat p_bname))
							(source		(tackon src p_bname))
							(dest		desti)
							(help		(cat (#msgcopycat p_bname) "\n\n" @copylib-help))
							(confirm	"expert")
							(infos)
						)
					)
					(if (= p_bname "#?")
						(P_CopyPat src "#?" desti)
					))
				))
			)

			(set n (+ n 1))
		)
	)
)



;***************************************************************************************************
;***	Procedure CopyNewerExists
;***************************************************************************************************
(procedure P_CopyNewerExists p_src p_dest

	(if (P_CheckExists p_dest) (P_CopyNewer p_src p_dest))
)




;***************************************************************************************************
;***	Procedure DeleteConfirmFiles
;***************************************************************************************************
(procedure P_DeleteConfirmFiles p_dir p_pat

	(set fcnt 0)
	(set defopt 0)
	(set usedopt 0)

	(if (= 2 @user-level) (

		;*** Make a file list of installed files. Include subdirs and save directories.
		;***
		(set cnt (P_MakeFileList "t:$csinst.tmp" p_dir p_pat 1 0 0))
		(set cnt (- cnt 1))

		;*** Create a scriptfile header
		;***
		(textfile (dest "t:$csinstdel.tmp") (append ";csinstdel.tmp - Temporary file - Do not edit or delete\n") (safe))

		(while (<> -1 cnt) (

			(symbolset (cat "f" fcnt) (getenv (cat "t:$csinst.tmp." cnt)))
			(delete (cat "t:$csinst.tmp." cnt) (safe))

			(set defopt (BITOR defopt (shiftleft 1 fcnt)))
			(set fcnt (+ fcnt 1))

			(if (= 12 fcnt) (
				(set usedopt (p_DeleteConfirmFilesDelete defopt f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11))
				(set fcnt 0)
				(set defopt 0)
			))

			(set cnt (- cnt 1))
		))

		(while (< fcnt 12) (
			(symbolset (cat "f" fcnt) "")
			(set fcnt (+ 1 fcnt))
		))

		(set usedopt (p_DeleteConfirmFilesDelete defopt f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11))
		(P_Delete (cat (tackon p_dir p_pat) ".info") "icons" "noreq")
	)
	(
		(P_Delete (tackon p_dir p_pat) "icons" "req")
	))

	(set usedopt usedopt)
)


;***************************************************************************************************
;***	Procedure DeleteConfirmFilesDelete
;***************************************************************************************************
(procedure p_DeleteConfirmFilesDelete p_opt p_f0 p_f1 p_f2 p_f3 p_f4 p_f5 p_f6 p_f7 p_f8 p_f9 p_f10 p_f11

	(set dcnt 0)
	(set delfile "")

	(set	choice (
		(askoptions
			(prompt		#msgoldfiles2)
			(help		#msgoldfiles2 @askoptions-help)
			(choices	p_f0 p_f1 p_f2 p_f3 p_f4 p_f5 p_f6 p_f7 p_f8 p_f9 p_f10 p_f11)
			(default	p_opt)
		)
	))

	(set choice p_opt)

	(while (< dcnt 12) (

		(if (IN choice dcnt) (
			(set delfile (select dcnt p_f0 p_f1 p_f2 p_f3 p_f4 p_f5 p_f6 p_f7 p_f8 p_f9 p_f10 p_f11))

			;*** Append a delete command for each file.
			;***
			(run (cat "echo >>t:$csinstdel.tmp \"delete >nil: *\"" delfile "*\"\"") (safe))
		))

		(set dcnt (+ dcnt 1))
	))
)



;***************************************************************************************************
;***	Procedure InstallMUIClass <path to base directory (without MUI/Libs)>
;***************************************************************************************************
(procedure P_InstallMUIClass p_basesrc

	(set src (tackon p_basesrc "Libs/MUI"))

	(set dst
		(if (= 2 (P_CheckExists "MUI:Libs/MUI"))
			("MUI:Libs/MUI")
			(if (= 2 (P_CheckExists "Libs:MUI"))
				("Libs:MUI")
			)
		)
	)

	(foreach src "(#?.mcc|#?.mcp)" (

		(copylib
			(prompt		(#msginstallmuiclass @each-name))
			(source		(tackon src @each-name))
			(dest		dst)
			(help		(cat (#msginstallmuiclass @each-name) "\n\n" @copylib-help))
			(confirm	"expert")
		)
	))
)


;***************************************************************************************************
;***	Procedure HandleMUIClasses <path to MUIC directory>
;***************************************************************************************************
(procedure P_HandleMUIClasses p_path

	(set srcdir (tackon #tempdir #tempinstdir))
	(set cnt 0)

	;*** Make a file list of all MUI classes archives.
	;***
	(set cnt (P_MakeFileList "t:$csinstmuic.tmp" p_path "MCC_#?.lha" 2 0 0))
	(set cnt (- cnt 1))

	;*** Attemting to install the external classes...
	;***
	(while (<> -1 cnt) (

		(set actfile (getenv (cat "t:$csinstmuic.tmp." cnt)))
		(delete (cat "t:$csinstmuic.tmp." cnt) (safe))

		(set instscripti	"")
		(set instscript		"")
		(set classpath		"")

		(if (= 1 (P_CheckExists actfile)) (

			(if (patmatch "#?MCC_Busy#?" actfile) (

				(set classpath		(tackon #tempexdir "MCC_Busy"))
				(set instscript		"MCC_Busy-Install")
			))

			(if (patmatch "#?MCC_InfoText#?" actfile) (

				(set classpath (tackon #tempexdir "MCC_InfoText"))
			))

			(if (patmatch "#?MCC_Lamp#?" actfile) (

				(set classpath		(tackon #tempexdir "MCC_Lamp"))
				(set instscript		"MCC-Install")
				(set instscripti	(cat "Install/" @language))
			))

			(if (patmatch "#?MCC_Listtree#?" actfile) (

				(set classpath (tackon #tempexdir "MCC_Listtree"))
			))

			(if (patmatch "#?MCC_NList#?" actfile) (

				(set classpath		(tackon #tempexdir "MCC_NList"))
				(set instscript		"Install")
			))

			(if (patmatch "#?MCC_Toolbar#?" actfile) (

				(set classpath (tackon #tempexdir "MCC_Toolbar"))
			))

			(working (#msgunarc (fileonly actfile)))
			(run (cat "\"" (tackon srcdir #lhexname) "\" " #lhexopts #tempexdir " " #lhexcmd " \"" actfile "\"") (safe))

;			(set aname "")
;			(set muser "")
;			(set duser "")
;			(set lfile "")

			;*** Installer script available?
			;***
;			(if (<> instscript "") (
;
;				(message (#msglaunchinstaller (fileonly classpath)) (all))
;
;				(if (<> instscripti "") (set sicon instscripti) (set sicon instscript))
;
;				(iconinfo (dest (tackon classpath sicon))
;					(gettooltype	"APPNAME"	"aname")
;					(gettooltype	"MINUSER"	"muser")
;					(gettooltype	"DEFUSER"	"duser")
;					(gettooltype	"LOGFILE"	"lfile")
;				)
;
;				(iconinfo (dest @icon)
;					(getdefaulttool	"instname")
;				)
;
;				(set lng @language)
;
;				(if (= aname "")
;					(set aname instscript)
;				)
;
;				(if (= muser "")
;					(set muser "AVERAGE")
;				)
;
;				(if (= duser "")
;					(set duser "AVERAGE")
;				)
;
;				(if (= lfile "")
;					(set lfile (cat (tackon "RAM:" instscript) ".log"))
;				)
;
;				(if (<> lfile "")
;					(textfile (dest "t:$csinstlaunch.tmp") (append (cat "cd \"" classpath "\"\n" ("\"%s\" \"%s\" APPNAME \"%s\" MINUSER %s DEFUSER %s LANGUAGE %s LOGFILE \"%s\"" instname (tackon classpath instscript) aname muser duser lng lfile))) (safe))
;					(textfile (dest "t:$csinstlaunch.tmp") (append (cat "cd \"" classpath "\"\n" ("\"%s\" \"%s\" APPNAME \"%s\" MINUSER %s DEFUSER %s LANGUAGE %s NOLOG\"" instname (tackon classpath instscript) aname muser duser lng))) (safe))
;				)
;
;				(execute	"t:$csinstlaunch.tmp")
;				(delete		"t:$csinstlaunch.tmp" (safe))
;			)
;			(
				(if (= 2 (P_CheckExists classpath)) (

					(message (#msginstallmuic (fileonly classpath)))
					(P_InstallMUIClass classpath)
				))
;			))

			(run (cat "delete >nil: \"" classpath "#?\" all quiet noreq") (safe))
		))

		(set cnt (- cnt 1))
	))
)



;***************************************************************************************************
;***	Procedure ConvertWTConfig <WilhelmTEL directory>
;***************************************************************************************************
(procedure P_ConvertWTConfig p_wtdir

	(set srcdir (tackon #tempdir #tempinstdir))
	(set wtfile "")
	(set retval 0)

	(if (P_CheckExists (tackon p_wtdir "TEL"))
		(set wtfile (tackon p_wtdir "Tel"))

		(if (P_CheckExists (tackon p_wtdir "WilhelmTEL"))
			(set wtfile (tackon p_wtdir "WilhelmTel"))
		)
	)

	(if (<> wtfile "") (

		(run ("\"%s\" \"%s\" \"%s\"" (tackon srcdir "Tools/WTConvert") wtfile (tackon #dest #dirname)))
		(set retval 1)
	))

	(set retval retval)
)



;***************************************************************************************************
;***	Procedure PreWork
;***************************************************************************************************
(procedure P_PreWork

	(set oldinstdir "")

	(if (P_CheckExists (tackon "ENV:" #oldinstdirvar))
		(set oldinstdir (getenv (tackon "ENV:" #oldinstdirvar)))
		(set oldinstdir #dest)
	)

	(set @default-dest oldinstdir)
	(set #dest oldinstdir)
)


;***************************************************************************************************
;***	Procedure Welcome
;***************************************************************************************************
(procedure P_About p_update

	(message (cat #msgwelcome #msgcopyright))
)


;***************************************************************************************************
;***	Procedure PrepareInstall
;***************************************************************************************************
(procedure P_PrepareInstall

	;*** Only ask, if not deinstallation.
	;***
	(if (<> 3 #instchoice) (

		;*** When making update, sample configs are not and MUI-classes should not be copied.
		;***
		(if (= 0 #instchoice) (set #instparts (- #instparts %01000010)))

		;*** Let the user select which parts of the software should be installed
		;***
		(if (<> 0 #instchoice)
			(set #instparts
				(askoptions
					(prompt		#msgwhichparts)
					(help		(cat #msgwhichparts "\n\n" @askchoice-help))
					(choices	#msgwhichpartmain #msgwhichpartconfigs #msgwhichpartdocs #msgwhichparthtml #msgwhichpartrexx #msgwhichparttools #msgwhichpartmuic)
					(default	#instparts)
				)
			)
			(set #instparts
				(askoptions
					(prompt		#msgwhichparts)
					(help		(cat #msgwhichparts "\n\n" @askchoice-help))
					(choices	#msgwhichpartmain "" #msgwhichpartdocs #msgwhichparthtml #msgwhichpartrexx #msgwhichparttools #msgwhichpartmuic)
					(default	#instparts)
				)
			)
		)

		;*** Ask for the destination dir when not only MUI-classes should be installed.
		;***
		(if (<> 64 #instparts)
			(set #dest (P_SelectDir #dest #msgaskdest #msgaskdest))
		)

		;*** Let the user select a backup dir if backup selected
		;***
		(if (= 2 #instchoice) (set #destback (P_SelectDir #destback #msgaskback #msgaskback)))
	))
)


;***************************************************************************************************
;***	Procedure CheckOldInst
;***************************************************************************************************
(procedure P_CheckOldInst

	(set ret 1)

	(working #msgworkingsearchold)

	;*** Check for a XPhone directory in Sys:Utilities
	;***
	(if (= 2 (P_CheckExists (tackon #dest #dirname))) (

		(set patcnt 0)

		;*** Search for Installed parts.
		;***
		(if (P_CheckExistsPat (tackon #dest #dirname) #dirname) (set patcnt (+ 1 patcnt)))

		;*** Found some old files
		;***
		(if (> patcnt 0)
		(
			(set ret 2)

			;*** Let the user select what to do (update, install new).
			;***
			(set	#instchoice
				(askchoice
					(prompt		#msgoldinst)
					(help		(cat #msgoldinst "\n\n" @askchoice-help))
					(choices	#msgoldinstupdate #msgoldinstnew #msgoldinstback #msgoldinstdeinst #msgoldinstend)
					(default	#instchoice)
				)
			)
		)
		(
			;*** No previous installation found! Install new.
			;***
			(set #instchoice 1)
			(set ret 3)
		))
	)
	(
		;*** No previous installation found! Install new.
		;***
		(set #instchoice 1)
		(set ret 3)
	))


	;*** We have to cancel (end) the installation script
	;***
	(if (= 4 #instchoice) (set ret 0))

	(set ret ret)
)


;***************************************************************************************************
;***	Procedure AskConfirmation
;***************************************************************************************************
(procedure P_AskConfirmation

	(set msgconfirm2 "")
	(set msgconfirm3 "")
	(set msgconfirm4 "")

	(if (<> 3 #instchoice) (

		(set msgconfirm1		(cat	#msgconfirm (#msgconfirm2 #cpuname #fpuname #osname)))

		;*** Not only MUI-classes.
		;***
		(if (<> %01000000 #instparts)
			(set msgconfirm2	(#msgconfirmdest (tackon #dest #dirname)))
		)
	)
	(
		(set msgconfirm1		#msgconfirmdeinst)
		(set msgconfirm2		(#msgconfirmdest (tackon #dest #dirname)))
	))


	(if (IN #instparts 6)
		(set msgconfirm3		#msgconfirminstmuic)
	)

	(if (= 2 #instchoice)
		(set msgconfirm4		(#msgconfirmbackdest (tackon #destback #destbackdir)))
	)

	(set msgconfirm				(cat	msgconfirm1 msgconfirm2 msgconfirm3 msgconfirm4 #msgconfirmask))

	;*** All right?
	;***
	(set	choice
		(askbool
			(prompt		msgconfirm)
			(help		msgconfirm)
			(default	1)
		)
	)

	(set @default-dest (tackon #dest #dirname))

	(set choice choice)
)



;***************************************************************************************************
;***	Procedure SetupInstall
;***************************************************************************************************
(procedure P_SetupInstall

	(if (<> 3 #instchoice) (working #msgworkingprepareinst) (working #msgworkingpreparedeinst))

	(if (= 0 #instchoice) (
		(P_PreUpdate)
	))

	(if (= 1 #instchoice) (
		(P_PreDeInstall)
		(P_PreNewInstall)
	))

	(if (= 2 #instchoice) (
		(P_PreNewInstall)
	))

	(if (= 3 #instchoice) (
		(P_PreDeInstall)
	))
)


;***************************************************************************************************
;***	Procedure DoInstall
;***************************************************************************************************
(procedure P_DoInstall

	(if (<> 3 #instchoice) (working #msgworkinginst) (working #msgworkingdeinst))

	(if (= 0 #instchoice) (
		(P_DoUpdate)
	))

	(if (= 1 #instchoice) (
		(P_DoDeInstall)
		(P_DoNewInstall)
	))

	(if (= 2 #instchoice) (
		(P_Backup)
		(P_DoNewInstall)
	))

	(if (= 3 #instchoice) (
		(P_DoDeInstall)
	))
)



;***************************************************************************************************
;***	Procedure AfterInstall
;***************************************************************************************************
(procedure P_AfterInstall

	(if (<> 3 #instchoice) (

		(if (<> 0 (P_CheckExists "sys:utilities/powerguide"))
			(set mvpath "sys:utilities/powerguide ")

			(if (<> 0 (P_CheckExists "sys:system/powerguide"))
				(set mvpath "sys:system/powerguide ")

				(if (<> 0 (P_CheckExists "c:powerguide"))
					(set mvpath "c:powerguide ")

					(if (<> 0 (P_CheckExists "sys:utilities/multiview"))
						(set mvpath "sys:utilities/multiview ")

						(if (<> 0 (P_CheckExists "sys:system/multiview"))
							(set mvpath "sys:utilities/multiview ")

							(if (<> 0 (P_CheckExists "c:multiview"))
								(set mvpath "c:multiview ")

								(if (<> 0 (P_CheckExists "sys:utilities/more"))
									(set mvpath "sys:utilities/more ")

									(if (<> 0 (P_CheckExists "sys:system/more"))
										(set mvpath "sys:system/more ")

										(if (<> 0 (P_CheckExists "c:more"))
											(set mvpath "c:more ")
											(set mvpath "echo >con: ")
										)
									)
								)
							)
						)
					)
				)
			)
		)

		(if (<> 0 (P_CheckExists #readmefile))
			(if (= 1 (askbool
				(prompt #msgshowreadme)
				(default 1)
				(help (cat #msgshowreadme "\n\n" @askbool-help))))

				(run (cat mvpath (tackon (tackon #tempdir #tempinstdir) #readmefile)) (safe))
			)
		)

		(working #msgworkingcleanup)

		(if (= 0 #instchoice) (
			(P_PostUpdate)
		))

		(if (= 1 #instchoice) (
			(P_PostNewInstall)
		))

		(if (= 2 #instchoice) (
			(P_PostNewInstall)
		))

		(if (= 3 #instchoice) (
			(P_PostNewInstall)
		))

		;*** Save the installation directory to ENV:
		;***
		(if (<> 3 #instchoice) (
			(textfile (dest (tackon "ENVARC:" #oldinstdirvar)) (append #dest))
			(textfile (dest (tackon "ENV:" #oldinstdirvar)) (append #dest))
		)
		(
			(P_Delete (tackon  "ENVARC:" #oldinstdirvar) "noicons" "noreq")
			(P_Delete (tackon  "ENV:" #oldinstdirvar) "noicons" "noreq")
		))
	))
)


;***************************************************************************************************
;***	Procedure PreUpdate
;***************************************************************************************************
(procedure P_PreUpdate

	;*** Define the source dir
	;***
	(set srcdir (pathonly @icon))

	(if (= 1 #unarc) (

		(working (#msgunarc #instarc))
		(run (cat "\"" (tackon srcdir #lhexname) "\" " #lhexopts #tempdir " " #lhexcmd " \"" (tackon srcdir #instarc) "\"") (safe))
	))
)


;***************************************************************************************************
;***	Procedure DoUpdate
;***************************************************************************************************
(procedure P_DoUpdate

	;*** Define the source dirs
	;***
	(set srcdir (tackon #tempdir #tempinstdir))
	(set destdir (tackon #dest #dirname))

	;*** Copy the main program and assiocated files.
	;***
	(if (IN #instparts 0) (

		(P_MakeDir		destdir "icons")
		(P_CopyLib		(tackon srcdir #dirname) destdir)

		(set wlang		(P_SelectLanguage #msgwhichcatalogs (tackon srcdir "Catalogs") #defcat))
		(if (> wlang 1)	(P_MakeDir (tackon destdir "Catalogs") "noicons"))
		(P_CopyLanguage	(tackon srcdir "Catalogs") (tackon destdir "Catalogs") "xphone.catalog" wlang 0)

		(P_MakeDir		(tackon destdir "IMG") "noicons")
		(P_CopyPat		(tackon srcdir "IMG") "#?" (tackon destdir "IMG"))

		(P_MakeDir		(tackon destdir "OGM") "noicons")
		(P_CopyPat		(tackon srcdir "OGM") "#?.alaw" (tackon destdir "OGM"))
	))

	;*** Configs.
	;***
	(if (IN #instparts 1) (

		(P_MakeDir	(tackon destdir "Config") "noicons")
		(P_CopyPat	(tackon srcdir "Config") "#?" (tackon destdir "Config"))
	))

	;*** Documentation.
	;***
	(if (IN #instparts 2) (

		(set wlang		(P_SelectLanguage #msgwhichdocs (tackon srcdir "Help") #defdoc))
		(if (> wlang 0)	(P_MakeDir (tackon destdir "Help") "icons"))
		(P_CopyLanguage	(tackon srcdir "Help") (tackon destdir "Help") "XPhone.guide" wlang 0)
	))

	;*** HTML Documentation.
	;***
	(if (IN #instparts 3) (

		(set wlang		(P_SelectLanguage #msgwhichhtml (tackon srcdir "HTML") #defhtml))
		(if (> wlang 0)	(P_MakeDir (tackon destdir "HTML") "icons"))
		(P_CopyLanguage	(tackon srcdir "HTML") (tackon destdir "HTML") "#?" wlang 1)
	))

	;*** Rexx.
	;***
	(if (IN #instparts 4) (

		(P_MakeDir		(tackon destdir "Rexx") "icons")
		(P_CopyPat		(tackon srcdir "Rexx") "#?" (tackon destdir "Rexx"))
	))

	;*** Tools.
	;***
	(if (IN #instparts 5) (

		(P_MakeDir		(tackon destdir "Tools") "icons")
		(P_CopyPat		(tackon srcdir "Tools") "#?" (tackon destdir "Tools"))
	))

	;*** External MUI-classes.
	;***
	(if (IN #instparts 6) (

		(message #msgmuicinfo)
		(set muicdir "MUI")

		(if (= 2 (P_CheckExists muicdir)) (

			(P_HandleMUIClasses muicdir)
		))
	))
)


;***************************************************************************************************
;***	Procedure PostUpdate
;***************************************************************************************************
(procedure P_PostUpdate

	(if (= 1 #unarc) (
		(delete (tackon #tempdir #tempinstdir) (all) (safe))
		(delete (cat (tackon #tempdir #tempinstdir) ".info") (safe))
	))
)


;***************************************************************************************************
;***	Procedure PreNewInstall
;***************************************************************************************************
(procedure P_PreNewInstall

	;*** Define the source/dest dirs
	;***
	(set srcdir (pathonly @icon))

	(if (= 1 #unarc) (

		(working (#msgunarc #instarc))
		(run (cat "\"" (tackon srcdir #lhexname) "\" " #lhexopts #tempdir " " #lhexcmd " \"" (tackon srcdir #instarc) "\"") (safe))
	))
)


;***************************************************************************************************
;***	Procedure NewInstall
;***************************************************************************************************
(procedure P_DoNewInstall

	;*** Define the source dirs
	;***
	(set srcdir (tackon #tempdir #tempinstdir))
	(set destdir (tackon #dest #dirname))

	;*** Copy the main program and assiocated files.
	;***
	(if (IN #instparts 0) (

		(P_MakeDir		destdir "icons")
		(P_CopyLib		(tackon srcdir #dirname) destdir)

		(set wlang		(P_SelectLanguage #msgwhichcatalogs (tackon srcdir "Catalogs") #defcat))
		(if (> wlang 1)	(P_MakeDir (tackon destdir "Catalogs") "noicons"))
		(P_CopyLanguage	(tackon srcdir "Catalogs") (tackon destdir "Catalogs") "xphone.catalog" wlang 0)

		(P_MakeDir		(tackon destdir "IMG") "noicons")
		(P_CopyPat		(tackon srcdir "IMG") "#?" (tackon destdir "IMG"))

		(P_MakeDir		(tackon destdir "OGM") "noicons")
		(P_CopyPat		(tackon srcdir "OGM") "#?.alaw" (tackon destdir "OGM"))
	))

	;*** Configs.
	;***
	(if (IN #instparts 1) (

		(P_MakeDir	(tackon destdir "Config") "noicons")
		(P_CopyPat	(tackon srcdir "Config") "#?" (tackon destdir "Config"))
	))

	;*** Documentation.
	;***
	(if (IN #instparts 2) (

		(set wlang		(P_SelectLanguage #msgwhichdocs (tackon srcdir "Help") #defdoc))
		(if (> wlang 0)	(P_MakeDir (tackon destdir "Help") "icons"))
		(P_CopyLanguage	(tackon srcdir "Help") (tackon destdir "Help") "XPhone.guide" wlang 0)
	))

	;*** HTML Documentation.
	;***
	(if (IN #instparts 3) (

		(set wlang		(P_SelectLanguage #msgwhichhtml (tackon srcdir "HTML") #defhtml))
		(if (> wlang 0)	(P_MakeDir (tackon destdir "HTML") "icons"))
		(P_CopyLanguage	(tackon srcdir "HTML") (tackon destdir "HTML") "#?" wlang 1)
	))

	;*** Rexx.
	;***
	(if (IN #instparts 4) (
		(P_MakeDir		(tackon destdir "Rexx") "icons")
		(P_CopyPat		(tackon srcdir "Rexx") "#?" (tackon destdir "Rexx"))
	))

	;*** Tools.
	;***
	(if (IN #instparts 5) (
		(P_MakeDir		(tackon destdir "Tools") "icons")
		(P_CopyPat		(tackon srcdir "Tools") "#?" (tackon destdir "Tools"))
	))

	;*** External MUI-classes.
	;***
	(if (IN #instparts 6) (

		(message #msgmuicinfo)
		(set muicdir "MUI")

		(if (= 2 (P_CheckExists muicdir)) (

			(P_HandleMUIClasses muicdir)
		))
	))

	;*** WilhelmTEL config converter
	;***
	(if (= 1 #instchoice) (

		(set tempuser (user 2))

		(if (= 1 (askbool
			(prompt		#msgaskconvertwt)
			(help		#msgaskconvertwt)
			(default	1))) (

			(set wtdir (P_SelectDir #dest #msgselectwtdir #msgselectwtdir))

			(if (= 1 (P_ConvertWTConfig wtdir))
				(message #msgconvwtsuccess)
				(message #msgconvwtnosuccess (all))
			)
		))

		(user tempuser)
	))
)


;***************************************************************************************************
;***	Procedure PostNewInstall
;***************************************************************************************************
(procedure P_PostNewInstall

	(if (= 1 #unarc) (
		(delete (tackon #tempdir #tempinstdir) (all) (safe))
		(delete (cat (tackon #tempdir #tempinstdir) ".info") (safe))
	))
)


;***************************************************************************************************
;***	Procedure Backup
;***************************************************************************************************
(procedure P_Backup

	(working #msgworkingbackup)

	;*** Create all needed dirs
	;***
	(P_MakeDir #destback "icons")
	(P_MakeDir (tackon #destback #destbackdir) "icons")


	;*** Backup all files.
	;***
	(copyfiles
		(source ( tackon #dest #dirname))
		(dest (tackon #destback #destbackdir))
		(nogauge)
		(all)
	)

	(P_Delete (tackon #dest #dirname) "icons" "req")
)


;***************************************************************************************************
;***	Procedure PreDeInstall
;***************************************************************************************************
(procedure P_PreDeInstall

	(set match 0)

	;*** Check for files do delete
	;***
	(if (P_CheckExistsPat #dest #dirname) (set match (BITOR match 1)))

	;*** Found some?
	;***
	(if (<> match 0 ) (

		(if (= 2 @user-level) (message #msgoldfilesexp) (message #msgoldfilesave))

		;*** Delete files.
		;***
		(if (IN match 0) (P_DeleteConfirmFiles #dest #dirname))
	))
)


;***************************************************************************************************
;***	Procedure DeInstall
;***************************************************************************************************
(procedure P_DoDeInstall

	;*** Now REALLY delete the old files (script made by SetupInstall/PreDeInstall).
	;***
	(if (<> 0 (P_CheckExists "t:$csinstdel.tmp"))
		(execute "t:$csinstdel.tmp")
	)
)


;***************************************************************************************************
;***	Procedure Cleanup
;***************************************************************************************************
(procedure P_Cleanup

	(if (= 0 #instchoice) (
		(P_PostUpdate)
	))

	(if (= 1 #instchoice) (
		(P_PostNewInstall)
	))

	(if (= 2 #instchoice) (
		(P_PostNewInstall)
	))

	(if (= 3 #instchoice) (
		(P_PostNewInstall)
	))

	(delete "t:$csinst#?" (safe))
)


;***************************************************************************************************
;***	Entry point
;***************************************************************************************************
;*** No user should have a Installer version below 43.3!

(if @savage-installer (
	(message #wronginstaller (all))
	(exit (quiet))
))

(if (< @installer-version 2818051) (
	(message #wronginstaller (all))
	(exit (quiet))
))

(if (<> 1 #unarc ) (

	(set #tempdir "")
	(set #tempinstdir (pathonly @icon))
))

(complete 0)
(P_PreWork)

(if (= 0 #dbg) (

	(complete 2)
	(welcome)

	(complete 4)
	(P_About)
))

(complete 6)
(P_CheckOS)
(P_CheckCPU)

(if (P_CheckOldInst) (

	(complete 8)
	(set ret 0)

	(while (= 0 ret) (

		(P_PrepareInstall)

		(complete 10)

		;*** Ask for confirmation
		;***
		(set ret (P_AskConfirmation))
	))

	(complete 20)
	(P_SetupInstall)

	(complete 40)
	(P_DoInstall)

	(complete 90)
	(P_AfterInstall)

	(complete 100)
	(P_Cleanup)

	(if (= 0 #dbg)
		(if (<> 3 #instchoice) (exit #msgendinst) (exit #msgenddeinst (quiet)))
	)
))

(if (<> 0 #dbg ) (exit (quiet)))

(complete 100)
(P_Cleanup)
(exit #msgend2)


