;***************************************************************************************************
;***************************************************************************************************
;***
;***	hyperIO installation script
;***	===========================
;***
;***	$VER: 1.2 (11.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			1)					;*** Unarchive (installation with archive).

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

(set #devspat		"hyper#?.device")			;*** Devs hyperCOM/PAR file pattern
(set #libspat		"vmcresource.library")		;*** Libs VMC file pattern
(set #devsisdnpat	"vmcisdn#?.device")			;*** If this is found, some components should not be deleted!

(set #instarc		"hyperio.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 #tempinstdir	"VMC-hyperIO-Install")		;*** Directory which holds installation files after extraction

(set #destdevs		"Devs:")					;*** Default device installation path. Primary needed for update check.
(set #destlibs		"Libs:")					;*** Default libs installation path. Primary needed for update check.
(set #destdocs		"Sys:Utilities")			;*** Default documentation installation path.
(set #destdocsdir	"hyperIO")					;*** Default utils directory.
(set #destutil		"Sys:Utilities")			;*** Default utils installation path.
(set #destutildir	"hyperIO")					;*** Default utils directory.
(set #destback		"SYS:Storage")				;*** Default backup path.
(set #destbackdir	"hyperIO_backup")			;*** Default backup directory.

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

(set #instchoice	0)							;*** Global installation choice (update=0, new=1, back=2, deinstall=3, break=4)
(set #instparts		%00001111)					;*** Bit mask of parts to install (0 = devs, 1 = libs, 2 = docs, 3 = utils)
(set #instcards		%01111111)					;*** Bit mask of cards to install drivers for (0 = hc1, 1 = hc3, 2 = hc3z, 3 = hc4, 4 = hc3ihc4, 5 = hc3ihc3z, 6 = hp)
(set #instutil		%00111111)					;*** Bit mask of utilities to install (0 = ncomm, 1 = ncomm-pk, 2 = hydra, 3 = porth. 4 = prtman, 5 = auxh.)

(set #vmchc1		"hyperCOM1.device")			;***
(set #vmchc3		"hyperCOM3.device")			;***
(set #vmchc4		"hyperCOM4?.device")		;***
(set #vmchc3z		"hyperCOM3?Z.device")		;***
(set #vmchp		"hyperPAR.device")			;***
(set #vmcrsc		"vmcresource.library")		;***

(set #utilncomm		"ncomm306")					;***
(set #utilncommpk	"NComm306PubKey")			;***
(set #utilhydra		"hydra")					;***
(set #utilporth		"porthandler")				;***
(set #utilprtman	"prtman39")					;***
(set #utilauxh		"auxhandler")				;***


;***************************************************************************************************
;***	Debugging stuff
;***************************************************************************************************

(set #dbg 0)

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



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

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

	(set #readmefile				"LiesMichZuerst.guide")

	(set #wronginstaller	(cat    "Achtung! Es ist eine alte Version des Programmes 'Installer' auf "
									"Ihrem Amiga!\n\nDie Installation benötigt mindestens Installer "
									"43.3.\n\nBitte überprüfen Sie Ihre Konfiguration!"))

	(set #msgmakedir				"Folgendes Verzeichnis wird nun erstellt: ")

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

	(set #msgcopy					"\nFolgende Datei wird jetzt kopiert:\n\n")

	(set #msgcopyover1		(cat	"\nEs wurde in der Quelldatei keine Versionsangabe gefunden.\nSoll diese Datei kopiert werden?\n\n"
									"Zu installierende Datei: "))
	(set #msgcopyover2				"\nBisher installierte Datei: ")
	(set #msgcopyovernofile			"Bisher ist keine Datei installiert.")

	(set #msgwelcome1		(cat	"\nWillkommen zur \n\n" #prgname))
	(set #msgwelcome2				" Installation.\n\n")

	(set #msgcopyright		(cat	"Copyright ©1992-1999 by VMC Harald Frank\n"
									"<vmc@vmc.de>\n"
									"http://www.vmc.de\n\n"
									"Installer script ©1998-99 by Carsten 'michelangelo' Scholling\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 werden nun einige alte Dateien aus dem System entfernt.\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 #msgwhichpartsdeinst		"\nWelche Komponenten sollen deinstalliert werden?\n")

	(set #msgwhichdevs				"Devices")
	(set #msgwhichlibs				"Libraries")
	(set #msgwhichdocs				"Dokumentation")
	(set #msgwhichutil				"Goodies")

	(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 #msgaskdevs		(cat	"In welchem Verzeichnis sollen die Device-Treiber installiert werden?\n"
									"Es wird KEIN Verzeichnis erstellt!\n"))
	(set #msgaskdevsdeinst			"In welchem Verzeichnis sind die Device-Treiber installiert?\n")
	(set #msgasklibs		(cat	"In welchem Verzeichnis sollen die Bibliotheken installiert werden?\n"
									"Es wird KEIN Verzeichnis erstellt!\n"))
	(set #msgasklibsdeinst			"In welchem Verzeichnis sind die Bibliotheken installiert?\n")
	(set #msgaskdocs		(cat	"In welchem Verzeichnis soll die Dokumentation installiert werden?\n"
									"Es wird ein Verzeichnis " #destdocsdir " erstellt!\n"))
	(set #msgaskdocsdeinst			"In welchem Verzeichnis ist die Dokumentation installiert?\n")
	(set #msgaskutil		(cat	"In welchem Verzeichnis sollen die Goodies installiert werden?\n"
									"Es wird ein Verzeichnis " #destutildir " erstellt!\n"))
	(set #msgaskutildeinst			"In welchem Verzeichnis sind die Goodies installiert?\n")
	(set #msgaskback		(cat	"In welchem Verzeichnis soll das Backup angelegt werden?\n"
									"Es wird ein Verzeichnis " #destbackdir " erstellt!\n"))

	(set #msgconfirm		(cat	"Die folgenden Daten werden zur Installation herangezogen:\n"))
	(set #msgconfirmdeinst	(cat	"Die folgenden Daten werden zur Deinstallation herangezogen:\n"))
	(set #msgconfirmcpu				"\nProzessor: ")
	(set #msgconfirmfpu				"\nFPU: ")
	(set #msgconfirmos				"\nBetriebssystem: ")
	(set #msgconfirmdevsdest		"\nDevices: ")
	(set #msgconfirmlibsdest		"\nLibraries: ")
	(set #msgconfirmdocsdest		"\nDokumentation: ")
	(set #msgconfirmutildest		"\nGoodies: ")
	(set #msgconfirmbackdest		"\nBackup: ")
	(set #msgconfirmask				"\n\nSoll ich mit diesen Einstellungen fortfahren?")

	(set #msgdelrsclib		(cat	"\nAuf Ihrem System wurde eine VMC-ISDN Installation\n"
									"gefunden welche auch die " #vmcrsc " benötigt.\n"
									"Soll sie trotzdem gelöscht werden?\n"))

	(set #msgcardinst				"Bitte wählen Sie aus, welche Karten in\nIhrem System installiert sind.\n(Hilfe beachten!)")
	(set #msgvmchc1d				"HyperCOM 1 Uhrenport-Karte")
	(set #msgvmchc3d				"HyperCOM 3/3+ Uhrenport-Karte")
	(set #msgvmchc3z				"HyperCOM 3z/3+ Zorro-Karte")
	(set #msgvmchc4d				"HyperCOM 4/4+ Zorro-Karte")
	(set #msgvmchc3ihc4d			"HyperCOM 3i installiert auf HyperCOM 4")
	(set #msgvmchc3ihc3zd			"HyperCOM 3i installiert auf HyperCOM 3z")
	(set #msgvmchpd					"hyperPAR.device für alle Karten")

	(set #msgcardinsthelp	(cat	"!!! NEU !!!\n\n"
									"Eine HyperCOM3i welche auf einer HyperCOM4 montiert ist wird über das "
									"hyperCOM4X.device auf Unit 4 und Unit 5 angesprochen.\n\n"
									"Eine HyperCOM3i welche auf einer HyperCOM3z montiert ist wird über das "
									"hyperCOM3Xz.device auf Unit 2 und Unit 3 angesprochen.\n\n"
									"Alle parallelen Schnittstellen auf den HyperCOM-Karten werden grundsätzlich "
									"über das hyperPAR.device angesteuert.\n\nDie LPT-Schnittstelle einer HyperCOM3 "
									"im A1200 liegt immer auf Unit 0.\n"))

	(set #msgutilinst				"Bitte wählen Sie aus, welche der Goodie-Archive Sie kopieren möchten")
	(set #msgutilncommd				"NComm V3.06 - Terminalprogramm")
	(set #msgutilncommpkd			"Freies Keyfile für NComm")
	(set #msgutilhydrad				"Hydra V1.0r9 - Bidirektionales Transferprotokoll")
	(set #msgutilporthd				"PortHandler V41 - Ersatz für original PortHandler")
	(set #msgutilprtmand			"PrintManager V39 - Drucker Spooler")
	(set #msgutilauxhd				"Aux-Handler V2 - Ermöglicht Remote-Login")

	(set #msgutilinsthelp	(cat	"Achtung!\n\n"
									"Die beigelegten Archive werden NICHT installiert sondern nur in das gewählte "
									"Zielverzeichnis kopiert. Mit anderen Worten: Selbst ist die Frau/der Mann. "))

	(set #msgendinst		(cat	"\n" #prgname " Installation beendet!\nDie installierten Dateien finden Sie in "
									"den folgenden Verzeichnissen:\n"))
	(set #msgenddeinst		(cat	"\n" #prgname " Deinstallation beendet!\n\n"))
	(set #msgend2			(cat	"\n" #prgname " Programm durch Benutzer beendet!\n\n"))

	(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 #readmefile				"ReadMeFirst.guide")

	(set #wronginstaller	(cat    "Attention! I've found an old version of the programm 'Installer' on "
									"your Amiga!\n\nThe installation needs at least Installer version "
									"43.3.\n\nPlease check your configuration!"))

	(set #msgmakedir				"The following directory will be created now: ")

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

	(set #msgcopy					"\nThe following file will be copied now:\n\n")

	(set #msgcopyover1		(cat	"\nI've found no version information in the source file.\nShould i copy this file?\n\n"
									"Sourcefile:     "))
	(set #msgcopyover2				"\nDestination file: ")
	(set #msgcopyovernofile			"No file installed now.")

	(set #msgwelcome1		(cat	"\nWelcome to the\n\n" #prgname))
	(set #msgwelcome2				" installation.\n\n")

	(set #msgcopyright		(cat	"Copyright ©1992-1999 by VMC Harald Frank\n"
									"<vmc@vmc.de>\n"
									"http://www.vmc.de\n\n"
									"Installer script ©1998-99 by Carsten 'michelangelo' Scholling\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\nI am now deleting some old files from your system.\n"
									"You can confirm the action for each file and directory.\n"))

	(set #msgoldfilesave			"\n\n\nI am now 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"
									"automatically deinstalled!\n"))
	(set #msgwhichpartsdeinst		"\nWhich components should be deinstalled?\n")

	(set #msgwhichdevs				"Devices")
	(set #msgwhichlibs				"Libraries")
	(set #msgwhichdocs				"Documentation")
	(set #msgwhichutil				"Goodies")

	(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 #msgaskdevs		(cat	"Where should i install the devices?\n"
									"No directory will be created!\n"))
	(set #msgaskdevsdeinst			"In which directory the devices are installed?\n")
	(set #msgasklibs		(cat	"Where should i install the librarys?\n"
									"No directory will be created!\n"))
	(set #msgasklibsdeinst			"In which directory the librarys are installed?\n")
	(set #msgaskdocs		(cat	"Where should i install the doc files?\n"
									"The " #destdocsdir " directory will be created!\n"))
	(set #msgaskdocsdeinst			"In which directory the doc files are installed?\n")
	(set #msgaskutil		(cat	"Where should i copy the goodies?\n"
									"The " #destutildir " directory will be created!\n"))
	(set #msgaskutildeinst			"In which directory the goodies are installed?\n")
	(set #msgaskback		(cat	"Where should i copy the backup files?\n"
									"The " #destbackdir " directory will be created!\n"))

	(set #msgconfirm		(cat	"The following information will be used for installation:\n"))
	(set #msgconfirmdeinst	(cat	"The following information will be used for deinstallation:\n"))
	(set #msgconfirmcpu				"\nCPU: ")
	(set #msgconfirmfpu				"\nFPU: ")
	(set #msgconfirmos				"\nOS type: ")
	(set #msgconfirmdevsdest		"\nDevices: ")
	(set #msgconfirmlibsdest		"\nLibraries: ")
	(set #msgconfirmdocsdest		"\nDocumentation: ")
	(set #msgconfirmutildest		"\nGoodies: ")
	(set #msgconfirmbackdest		"\nBackup: ")
	(set #msgconfirmask				"\n\nShould i use this settings?")

	(set #msgdelrsclib		(cat	"\nA VMC-ISDN installation which also uses the " #vmcrsc
									"was found on your system.\n"
									"Should i delete it?\n"))

	(set #msgcardinst				"Please choose the cards, that are installed in your Amiga.\n(See Help!)")
	(set #msgvmchc1d				"HyperCOM 1/PortJnr card")
	(set #msgvmchc3d				"HyperCOM 3/3+/PortPlus card")
	(set #msgvmchc3z				"HyperCOM 3z/3+ Zorro card")
	(set #msgvmchc4d				"HyperCOM 4/4+ Zorro card")
	(set #msgvmchc3ihc4d			"HyperCOM3i plugin on HyperCOM4")
	(set #msgvmchc3ihc3zd			"HyperCOM3i plugin on HyperCOM3z")
	(set #msgvmchpd					"hyperPAR.device for all HyperCOM's")

	(set #msgcardinsthelp	(cat	"!!! NEW !!!\n\n"
									"A HyperCOM3i which is installed on a HyperCOM4 card will be used with "
									"hyperCOM4X.device on units 4 and 5.\n\n"
									"A HyperCOM3i which is installed on a HyperCOM3z card will be used with "
									"hyperCOM3Xz.device on units 2 and 3.\n\n"
									"All parallel interfaces on HyperCOM cards will be used through hyperPAR.device.\n\n"
									"The LPT-interface on a HyperCOM3 in A1200 is allways unit 0.\n"))

	(set #msgutilinst				"Please choose which parts of the goodies you want to copy")
	(set #msgutilncommd				"NComm V3.06 - Terminalsoftware")
	(set #msgutilncommpkd			"Free & Public Keyfile for NComm")
	(set #msgutilhydrad				"Hydra V1.0r9 - Bidirectional transfer protokoll")
	(set #msgutilporthd				"PortHandler V41 - Replacement for the old one")
	(set #msgutilprtmand			"PrintManager V39 - Printer spooler")
	(set #msgutilauxhd				"Aux-Handler V2 - Shell over serial remote-login")

	(set #msgutilinsthelp	(cat	"Attention!\n\n"
									"The included goodies will NOT be installed, but only copied "
									"to the selected destination dir. Goodie-installation is -> do it yourself. "))

	(set #msgendinst		(cat	"\n" #prgname " Installation done!\nYou will find the installed files in the "
									"following directories:\n"))
	(set #msgenddeinst		(cat	"\n" #prgname " Deinstallation done!\n\n"))
	(set #msgend2			(cat	"\n" #prgname " Installation aborted by user!\n\n"))

	(set #msgshowreadme		(cat	"\nDo you want to read the " #readmefile " now?\n"))

	(set #msgreboot					"\nYou MUST reboot after this installation to use\nthe new drivers. 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))

	(if (= os 37)	(set osname "2.0"))
	(if (= os 38)	(set osname "2.1"))
	(if (= os 39)	(set osname "3.0"))
	(if (= os 40)	(set osname "3.1"))
	(if (= os 44)	(set osname "3.5"))
	(if (> os 44)	(set osname "3.5+ (not known)"))

	(if (>= os minosver)
		(set ret 1)
		(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.temp " p_path " pat " p_pat " lformat \"%n\""))

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

		(delete "t:csinstcheckpat.temp")
	))

	(set patexists patexists)
)


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

	(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	#msgmakedir p_path "\n\n" @makedir-help)
				(confirm "expert")
				(infos)
			)

			(makedir p_path
				(prompt	#msgmakedir p_path)
				(help	#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
				(optional "force" "askuser")
				(all)
			)
			(delete p_file
				(optional "force" "askuser")
				(infos)
				(all)
			)
		)

		(if (= p_noicons "noicons")

			(delete p_file
				(prompt (cat #msgdelete p_file))
				(help (cat #msgdelete p_file))
				(optional "force" "askuser")
				(all)
				(confirm "expert")
			)
			(delete p_file
				(prompt (cat #msgdelete p_file))
				(help (cat #msgdelete p_file))
				(optional "force" "askuser")
				(infos)
				(all)
				(confirm "expert")
			)
		)
	)
)


;***************************************************************************************************
;***	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 CopyNewer <source dir> <pattern> <dest dir>
;***************************************************************************************************
(procedure P_CopyNewer p_srcdir p_pat p_destdir

	(debug (cat "CopyNewer " p_srcdir p_pat p_destdir))

	;*** Compare the version/size
	;***
	(foreach p_srcdir p_pat (

		(debug @each-name)

		(set res 1)

		;*** Recursively call.
		;***
		(if (= 2 (P_CheckExists (tackon p_srcdir @each-name)))
		(
			(P_MakeDir (tackon p_destdir @each-name) "icons")

			(set savesrc	p_srcdir)
			(set savepat	p_pat)
			(set savedest	p_destdir)

			(P_CopyNewer (tackon p_srcdir @each-name) p_pat (tackon p_destdir @each-name))

			(set p_srcdir	savesrc)
			(set p_pat		savepat)
			(set p_destdir	savedest)
		)
		(
			;*** Get the two version numbers.
			;***
			(if (= 0 (getversion (tackon p_srcdir @each-name)))
			(
				(set srcvers (cat "  (" (/ (getsize (tackon p_srcdir @each-name)) 1024) "kB)"))

				(if ((P_CheckExists (tackon p_destdir @each-name)))
				(
					(set destname @each-name)
					(set msgcopyover2 #msgcopyover2)

					(if (= 0 (getversion (tackon p_destdir @each-name)))
						(set destvers (cat "  (" (/ (getsize (tackon p_destdir @each-name)) 1024) "kB)"))
						(set destvers (cat (P_GetFullVersion (tackon p_destdir @each-name)) "  (" (/ (getsize (tackon p_destdir @each-name)) 1024) "kB)"))
					)
				)
				(
					(set destname #msgcopyovernofile)
					(set destvers "")
					(set msgcopyover2 "\n")
				))

				(set res 1)

				(if (= 2 @user-level)
					(set res (askbool
						(prompt		(cat #msgcopyover1 @each-name " " srcvers msgcopyover2 destname " " destvers))
						(help		(cat #msgcopyover1 @each-name " " srcvers msgcopyover2 destname " " destvers))
						(default	1)
					))
				)

				(if (= 1 res) (
					(copyfiles
						(prompt		#msgcopy)
						(help		#msgcopy @copyfiles-help)
						(source		p_srcdir)
						(dest		p_destdir)
						(pattern	@each-name)
						(infos)
					)
				))
			)
			(
				(copylib
					(prompt (cat #msgcopy @each-name))
					(help (cat #msgcopy @each-name "\n\n" @copylib-help))
					(source	(tackon p_srcdir @each-name))
					(dest 	p_destdir)
					(confirm "expert")
					(infos)
				)
			))
		))
	))
)


;***************************************************************************************************
;***	Procedure CopyNewerExists
;***************************************************************************************************
(procedure P_CopyNewerExists p_srcdir p_pat p_destdir

	(if (P_CheckExistsPat p_destdir p_pat) (P_CopyNewer p_srcdir p_pat p_destdir))
)




;***************************************************************************************************
;***	Procedure CopyNewer <source dir> <pattern> <dest dir>
;***************************************************************************************************
(procedure P_CopyNewer p_srcdir p_pat p_destdir

	;*** Compare the version/size
	;***
	(foreach p_srcdir p_pat (

		(set res 1)

		;*** Recursively call.
		;***
		(if (= 2 (P_CheckExists (tackon p_srcdir @each-name)))
		(
			(P_MakeDir (tackon p_destdir @each-name) "icons")

			(set savesrc	p_srcdir)
			(set savepat	p_pat)
			(set savedest	p_destdir)

			(P_CopyNewer (tackon p_srcdir @each-name) p_pat (tackon p_destdir @each-name))

			(set p_srcdir	savesrc)
			(set p_pat		savepat)
			(set p_destdir	savedest)
		)
		(
			;*** Get the two version numbers.
			;***
			(if (= 0 (getversion (tackon p_srcdir @each-name)))
			(
				(set srcvers (cat "  (" (/ (getsize (tackon p_srcdir @each-name)) 1024) "kB)"))

				(if ((P_CheckExists (tackon p_destdir @each-name)))
				(
					(set destname @each-name)
					(set msgcopyover2 #msgcopyover2)

					(if (= 0 (getversion (tackon p_destdir @each-name)))
						(set destvers (cat "  (" (/ (getsize (tackon p_destdir @each-name)) 1024) "kB)"))
						(set destvers (cat (P_GetFullVersion (tackon p_destdir @each-name)) "  (" (/ (getsize (tackon p_destdir @each-name)) 1024) "kB)"))
					)
				)
				(
					(set destname #msgcopyovernofile)
					(set destvers "")
					(set msgcopyover2 "\n")
				))

				(set res (askbool
					(prompt		(cat #msgcopyover1 @each-name " " srcvers msgcopyover2 destname " " destvers))
					(help		(cat #msgcopyover1 @each-name " " srcvers msgcopyover2 destname " " destvers))
					(default	1)
				))

				(if (= 1 res) (
					(copyfiles
						(prompt #msgcopy)
						(help (cat #msgcopy @copyfiles-help))
						(source	p_srcdir)
						(dest	p_destdir)
						(pattern @each-name)
						(infos)
					)
				))
			)
			(
				(copylib
					(prompt (cat #msgcopy @each-name))
					(help (cat #msgcopy @each-name "\n\n" @copylib-help))
					(source	(tackon p_srcdir @each-name))
					(dest 	p_destdir)
					(confirm "expert")
					(infos)
				)
			))
		))
	))
)


;***************************************************************************************************
;***	Procedure CopyNewerExists
;***************************************************************************************************
(procedure P_CopyNewerExists p_srcdir p_pat p_destdir

	(if (P_CheckExistsPat p_destdir p_pat) (P_CopyNewer p_srcdir p_pat p_destdir))
)




;***************************************************************************************************
;***	Procedure PreInstall
;***************************************************************************************************
(procedure P_PreInstall

	(set @default-dest (tackon #destdocs #destdocsdir))
)


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

;	(set date (getenv (tackon (pathonly @icon) "hyperIOVersion")))
;	(set ver			(/ vers 65536))
;	(set rev			(- vers (* ver 65536)))
;	(set version		(cat ver "." rev))

;	(message (cat #msgwelcome1 " " version #msgwelcome2 #msgcopyright))
	(message (cat #msgwelcome1 #msgwelcome2 #msgcopyright))
)


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

	(set ret 1)

	(working #msgworkingsearchold)

	;*** Check for a version file in devs:
	;***
	(if (= 0 (P_CheckExists (tackon #destdevs "hyperIOVersion")))
	(
		(set patcnt 0)

		;*** Search for devices and libs (resource lib does not bother if isdn installed)
		;***
		(if (P_CheckExistsPat #destdevs #devspat) (set patcnt (+ 1 patcnt)))
		(if (AND (P_CheckExistsPat #destlibs #libspat) (= 0 (P_CheckExistsPat #destdevs #devsisdnpat))) (set patcnt (+ 1 patcnt)))
		(if (P_CheckExistsPat (tackon #destdocs #destdocsdir) "(Documentaion|Dokumentation)") (set patcnt (+ 1 patcnt)))
		(if (P_CheckExistsPat (tackon #destutil #destutildir) "Goodies") (set patcnt (+ 1 patcnt)))

		;*** Found some very 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	#msgoldinstnew #msgoldinstback #msgoldinstdeinst #msgoldinstend)
					(default    0)
				)
			)

			;*** Add 1 to the choice (If very old, no update possible!)
			;***
			(set #instchoice (+ 1 #instchoice))
		)
		(
			;*** No previous installation found! Install new.
			;***
			(set #instchoice 1)
			(set ret 3)
		))
	)
	(
		;*** Else, we look for the version number
		;*** coded as version=high-byte and revision=low-byte.
		;***
		(set oldvers (getenv (tackon #destdevs "hyperIOVersion")))
		(set newvers (getenv (tackon (pathonly @icon) "hyperIOVersion")))

		(if (< oldvers newvers) (

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

			;*** All files up to date. May the user want to deinstall the files...
			(set	choice
				(askchoice
					(prompt		#msguptodate)
					(help		(cat #msguptodate "\n\n" @askchoice-help))
					(choices	#msgoldinstnew #msgoldinstdeinst #msgoldinstend)
					(default    0)
                )
			)

			(if (= 0 choice)
				(set #instchoice 1)

				(if (= 1 choice)
					(set #instchoice 3)

					(if (= 2 choice)
						(set #instchoice 4)
					)
				)
			)
		))
	))

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

	(set ret ret)
)


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

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

		(
			;*** Let the user select which parts of the software should be installed
			;***
			(set #instparts
				(askoptions
					(prompt		#msgwhichparts)
					(help		(cat #msgwhichparts "\n\n" @askchoice-help))
					(choices	#msgwhichdevs #msgwhichlibs #msgwhichdocs #msgwhichutil)
					(default	#instparts)
				)
			)

			;*** Let the user (ALL USERS) select which cards are installed.
			;***
			(set tempuser @user-level)
			(user 2)

			(if (IN #instparts 0)
				(set	#instcards
					(askoptions
						(prompt		#msgcardinst)
						(help		(cat #msgcardinsthelp "\n\n" @askoptions-help))
						(choices	#msgvmchc1d #msgvmchc3d #msgvmchc3z #msgvmchc4d #msgvmchc3ihc4d #msgvmchc3ihc3zd #msgvmchpd)
						(default	#instcards)
					)
				)

				(set #instcards 0)
			)

			(user tempuser)

			;*** Let the user select which utils should be installed (if NO update)
			;***
			(if (<> 0 #instchoice) (
				(if (IN #instparts 3)
					(set	#instutil
						(askoptions
							(prompt		#msgutilinst)
							(help		(cat #msgutilinsthelp "\n\n" @askoptions-help))
							(choices	#msgutilncommd #msgutilncommpkd #msgutilhydrad #msgutilporthd #msgutilprtmand #msgutilauxhd)
							(default	#instutil)
						)
					)
					(set #instutil 0)
			    )
			))

			;*** Ask for the destination dirs depending on selected parts
			;***
			(if (IN #instparts 0) (set #destdevs (P_SelectDir #destdevs #msgaskdevs #msgaskdevs)))
			(if (IN #instparts 1) (set #destlibs (P_SelectDir #destlibs #msgasklibs #msgasklibs)))
			(if (IN #instparts 2) (set #destdocs (P_SelectDir #destdocs #msgaskdocs #msgaskdocs)))
			(if (IN #instparts 3) (set #destutil (P_SelectDir #destutil #msgaskutil #msgaskutil)))

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

		(
			;*** Let the user select which parts of the software should be de-installed
			;***
			(set #instparts
				(askoptions
					(prompt		#msgwhichpartsdeinst)
					(help		(cat #msgwhichpartsdeinst "\n\n" @askchoice-help))
					(choices	#msgwhichdevs #msgwhichlibs #msgwhichdocs #msgwhichutil)
					(default	#instparts)
				)
			)

			(if (= 0 (P_CheckExistsPat #destdevs #devspat)) (

				(if (IN #instparts 0) (set #destdevs (P_SelectDir #destdevs #msgaskdevsdeinst #msgaskdevsdeinst)))
			))

			(if (= 0 (P_CheckExistsPat #destlibs (cat "~(" #vmcrsc "|~(" #libspat "))"))) (

				(if (IN #instparts 1) (set #destlibs (P_SelectDir #destlibs #msgasklibsdeinst #msgasklibsdeinst)))
			))

			(if (= 0 (P_CheckExistsPat (tackon #destdocs #destdocsdir) "(Documentaion|Dokumentation)")) (

				(if (IN #instparts 2) (set #destdocs (P_SelectDir #destdocs #msgaskdocsdeinst #msgaskdocsdeinst)))
			))

			(if (= 0 (P_CheckExistsPat (tackon #destutil #destutildir) "Goodies")) (

				(if (IN #instparts 3) (set #destutil (P_SelectDir #destutil #msgaskutildeinst #msgaskutildeinst)))
			))
		)
	)
)


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

	(set msgconfirm2 "")

	(if (<> 3 #instchoice)
	(
		(set msgconfirm1	(cat	#msgconfirm
									#msgconfirmcpu	cpuname
									#msgconfirmfpu	fpuname
									#msgconfirmos	osname
		))

		(if (IN #instparts 0) (set msgconfirm2 (cat msgconfirm2 #msgconfirmdevsdest #destdevs)))
		(if (IN #instparts 1) (set msgconfirm2 (cat msgconfirm2 #msgconfirmlibsdest #destlibs)))
		(if (IN #instparts 2) (set msgconfirm2 (cat msgconfirm2 #msgconfirmdocsdest (tackon #destdocs #destdocsdir))))
		(if (IN #instparts 3) (set msgconfirm2 (cat msgconfirm2 #msgconfirmutildest (tackon #destutil #destutildir))))
	)
	(

		(set msgconfirm1			#msgconfirmdeinst)

		(set msgconfirm2	(cat	#msgconfirmdevsdest	#destdevs
									#msgconfirmlibsdest	#destlibs
									#msgconfirmdocsdest	(tackon #destdocs #destdocsdir)
									#msgconfirmutildest	(tackon #destutil #destutildir)))

	))


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

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

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

	(set @default-dest (tackon #destdocs #destdocsdir))

	(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_DeInstall)
		(P_NewInstall)
	))

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

	(if (= 3 #instchoice) (
		(P_DeInstall)
	))
)



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

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

	(if (= 1 #unarc) (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 srcdirdevs (tackon srcdir "devs"))
	(set srcdirlibs (tackon srcdir "libs"))
	(set srcdirdocs (tackon srcdir "docs"))
	(set srcdirutil (tackon srcdir "goodies"))


	;*** Now copy the files always needed
	;***

	;*** Copy the selected drivers.
	;***
	(if (IN #instparts 0) (

		(set copycard 0)
		(set copiedcards 0)
		(set instcards #instcards)

		(if (AND (IN instcards 2) (IN instcards 5)) (set instcards (- instcards 32)))
		(if (AND (IN instcards 3) (IN instcards 4)) (set instcards (- instcards 16)))

		(while (< copycard 7) (

			(if (IN instcards copycard) (

				(if (= copycard 0)						(set cardpat #vmchc1))
				(if (= copycard 1)						(set cardpat #vmchc3))
				(if (OR (= copycard 2) (= copycard 5))	(set cardpat #vmchc3z))
				(if (OR (= copycard 3) (= copycard 4))	(set cardpat #vmchc4))
				(if (= copycard 6)						(set cardpat #vmchp))

				(if (NOT (IN copiedcards copycard))	(
					(set copiedcards (BITOR copiedcards (shiftleft 1 copycard)))
					(P_CopyNewerExists srcdirdevs cardpat #destdevs)
				))
			))

			(set copycard (+ 1 copycard))
		))
	))


	;*** resource library
	;***
	(if (IN #instparts 1) (P_CopyNewerExists srcdirlibs #vmcrsc #destlibs))

	;*** documentation
	;***
	(if (IN #instparts 2) (
		(P_MakeDir (tackon #destdocs #destdocsdir) "icons")
		(P_CopyNewerExists srcdirdocs "~(#?.info)" (tackon #destdocs #destdocsdir))
	))

	;*** Goodies
	;***
	(if (IN #instparts 3) (

		(P_MakeDir (tackon #destutil #destutildir) "icons")
		(P_MakeDir (tackon (tackon #destutil #destutildir) "Goodies") "icons")

		(if (IN #instutil 0) (P_CopyNewerExists srcdirutil (cat #utilncomm "#?")	(tackon (tackon #destutil #destutildir) "Goodies")))
		(if (IN #instutil 1) (P_CopyNewerExists srcdirutil (cat #utilncommpk "#?")	(tackon (tackon #destutil #destutildir) "Goodies")))
		(if (IN #instutil 2) (P_CopyNewerExists srcdirutil (cat #utilhydra "#?")	(tackon (tackon #destutil #destutildir) "Goodies")))
		(if (IN #instutil 3) (P_CopyNewerExists srcdirutil (cat #utilporth "#?")	(tackon (tackon #destutil #destutildir) "Goodies")))
		(if (IN #instutil 4) (P_CopyNewerExists srcdirutil (cat #utilprtman "#?")	(tackon (tackon #destutil #destutildir) "Goodies")))
		(if (IN #instutil 5) (P_CopyNewerExists srcdirutil (cat #utilauxh "#?")		(tackon (tackon #destutil #destutildir) "Goodies")))
	))

	;*** Version ID file
	;***
	(copyfiles
		(source (tackon (pathonly @icon) "hyperIOVersion"))
		(dest #destdevs)
		(nogauge)
		(files)
	)
)


;***************************************************************************************************
;***	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) (run (cat "\"" (tackon srcdir #lhexname) "\" " #lhexopts #tempdir " " #lhexcmd " \"" (tackon srcdir #instarc) "\"") (safe)))
)


;***************************************************************************************************
;***	Procedure NewInstall
;***************************************************************************************************
(procedure P_NewInstall

	;*** Define the source dirs
	;***
	(set srcdir (tackon #tempdir #tempinstdir))
	(set srcdirdevs (tackon srcdir "devs"))
	(set srcdirlibs (tackon srcdir "libs"))
	(set srcdirdocs (tackon srcdir "docs"))
	(set srcdirutil (tackon srcdir "goodies"))

	;*** Now copy the files always needed
	;***

	;*** Copy the selected drivers.
	;***
	(if (IN #instparts 0) (

		(set copycard 0)
		(set copiedcards 0)
		(set instcards #instcards)

		(while (< copycard 7) (

			(if (IN instcards copycard) (

				(if (= copycard 0)						(set cardpat #vmchc1))
				(if (= copycard 1)						(set cardpat #vmchc3))
				(if (OR (= copycard 2) (= copycard 5))	(set cardpat #vmchc3z))
				(if (OR (= copycard 3) (= copycard 4))	(set cardpat #vmchc4))
				(if (= copycard 6)						(set cardpat #vmchp))

				(if (NOT (IN copiedcards copycard))	(
					(set copiedcards (BITOR copiedcards (shiftleft 1 copycard)))
					(P_CopyNewer srcdirdevs cardpat #destdevs)
				))
			))

			(set copycard (+ 1 copycard))
		))
	))


	;*** resource library
	;***
	(if (IN #instparts 1) (P_CopyNewer srcdirlibs #vmcrsc #destlibs))

	;*** documentation
	;***
	(if (IN #instparts 2) (
		(P_MakeDir (tackon #destdocs #destdocsdir) "icons")
		(P_CopyNewer srcdirdocs "~(#?.info)" (tackon #destdocs #destdocsdir))
	))

	;*** Goodies
	;***
	(if (IN #instparts 3) (

		(P_MakeDir (tackon #destutil #destutildir) "icons")
		(P_MakeDir (tackon (tackon #destutil #destutildir) "Goodies") "icons")

		(if (IN #instutil 0) (P_CopyNewer srcdirutil (cat #utilncomm "#?")		(tackon (tackon #destutil #destutildir) "Goodies")))
		(if (IN #instutil 1) (P_CopyNewer srcdirutil (cat #utilncommpk "#?")	(tackon (tackon #destutil #destutildir) "Goodies")))
		(if (IN #instutil 2) (P_CopyNewer srcdirutil (cat #utilhydra "#?")		(tackon (tackon #destutil #destutildir) "Goodies")))
		(if (IN #instutil 3) (P_CopyNewer srcdirutil (cat #utilporth "#?")		(tackon (tackon #destutil #destutildir) "Goodies")))
		(if (IN #instutil 4) (P_CopyNewer srcdirutil (cat #utilprtman "#?")		(tackon (tackon #destutil #destutildir) "Goodies")))
		(if (IN #instutil 5) (P_CopyNewer srcdirutil (cat #utilauxh "#?")		(tackon (tackon #destutil #destutildir) "Goodies")))
	))

	;*** Version ID file
	;***
	(copyfiles
		(source (tackon (pathonly @icon) "hyperIOVersion"))
		(dest #destdevs)
		(nogauge)
		(files)
	)
)


;***************************************************************************************************
;***	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 version information file
	;***
	(if (P_CheckExists (tackon #destdevs "hyperIOVersion")) (

		(copyfiles
			(source (tackon #destdevs "hyperIOVersion"))
			(dest (tackon #destback #destbackdir))
			(nogauge)
			(files)
		)

		(P_Delete (tackon #destdevs "hyperIOVersion") "noicons" "noreq")
	))


	;*** Backup Devs drawer
	;***
	(foreach #destdevs #devspat (

		(copyfiles
			(source (tackon #destdevs @each-name))
			(dest (tackon (tackon #destback #destbackdir) "devs"))
			(nogauge)
			(files)
		)

		(P_Delete (tackon #destdevs @each-name) "icons" "req")
	))


	;*** Backup Libs drawer
	;***
	(foreach #destlibs #libspat (

		(copylib
			(source (tackon #destlibs @each-name))
			(dest (tackon (tackon #destback #destbackdir) "libs"))
			(nogauge)
		)

		;*** Don't delete any library if isdn installed!
		;***
		(if (= 0 (P_CheckExistsPat #destdevs #devsisdnpat)) (P_Delete (tackon #destlibs @each-name) "icons" "req"))
	))

	;*** Backup documentation
	;***
	(if (P_CheckExistsPat (tackon #destdocs #destdocsdir) "Documentation") (

		(copyfiles
			(source (tackon #destdocs #destdocsdir))
			(dest (tackon #destback #destbackdir))
			(pattern "Documentation")
			(nogauge)
			(infos)
		)

		(P_Delete (tackon (tackon #destdocs #destdocsdir) "Documentation") "icons" "req")
	))

	(if (P_CheckExistsPat (tackon #destdocs #destdocsdir) "Dokumentation") (

		(copyfiles
			(source (tackon #destdocs #destdocsdir))
			(dest (tackon #destback #destbackdir))
			(pattern "Dokumentation")
			(nogauge)
			(infos)
		)

		(P_Delete (tackon (tackon #destdocs #destdocsdir) "Dokumentation") "icons" "req")
	))


	;*** Backup goodies
	;***
	(if (P_CheckExistsPat (tackon #destutil #destutildir) "Goodies") (

		(copyfiles
			(source (tackon #destutil #destutildir))
			(dest (tackon #destback #destbackdir))
			(pattern "Goodies")
			(nogauge)
			(infos)
		)

		(P_Delete (tackon (tackon #destutil #destutildir) "Goodies") "icons" "req")
	))

)


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

	;*** Create a scriptfile header
	;***
	(run (cat "echo >t:csinstdelete.temp \";csinstdelete.temp - Temporary file - Do not edit or delete*n\""))

	(set match 0)

	;*** Check for files to delete
	;***
	(if (IN #instparts 0)   (if (P_CheckExistsPat #destdevs #devspat)												(set match (BITOR match 1))))
	(if (IN #instparts 1)   (if (P_CheckExistsPat #destlibs (cat "~(" #vmcrsc "|~(" #libspat "))"))					(set match (BITOR match 2))))
	(if (IN #instparts 2)   (if (P_CheckExistsPat (tackon #destdocs #destdocsdir) "(Documentaion|Dokumentation)")	(set match (BITOR match 4))))
	(if (IN #instparts 3)   (if (P_CheckExistsPat (tackon #destutil #destutildir) "Goodies")						(set match (BITOR match 8))))


	;*** Delete libs files if available AND no isdn installed (ask expert user)!
	;***
	(if (= 3 #instchoice) (

		(if (IN match 1) (

			(set isdninst (P_CheckExistsPat #destdevs #devsisdnpat))

			(if (<> 0 isdninst) (
				(if (IN match 4) (
					(if (> (getversion (tackon #destlibs #vmcrsc)) (getversion (tackon (tackon (pathonly @icon) "libs") #vmcrsc))) (

						(set delrsclib 0)

						(if (= 2 @user-level) (

							(set	delrsclib
								(askbool
									(prompt		#msgdelrsclib)
									(help		(cat #msgdelrsclib @askbool-help))
									(default	0)
								)
							)
						))

						(if (= 1 delrsclib) (P_DeleteConfirmFiles #destlibs #vmcrsc 0))
					))
				))
			))
		))
	))

	;*** Reset vmcresource flag
	;***
	(set match (BITAND match 15))

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

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

		;*** Delete devs files.
		;***
		(if (IN match 0) (P_DeleteConfirmFiles #destdevs #devspat 0))

		;*** Delete libs files.
		;***
		(if (IN match 1) (P_DeleteConfirmFiles #destlibs #libspat 0))

		;*** Delete dokumentation files.
		;***
		(if (IN match 2) (P_DeleteConfirmFiles (tackon #destdocs #destdocsdir) "(Documentation|Dokumentation)" 1))

		;*** Delete goodie files.
		;***
		(if (IN match 3) (P_DeleteConfirmFiles (tackon #destutil #destutildir) "Goodies" 1))

		;*** Delete docs/goodies directory.
		;***
		(P_DeleteConfirmFiles #destdocs #destdocsdir 1)

		(if (OR (<> #destdocs #destutil) (<> #destdocsdir #destutildir)) (
			(P_DeleteConfirmFiles #destutil #destutildir 1)

		))
	))
)


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

	;*** Reset all used vars.
	;***
	(set cnt 0)
	(set defopt 0)

	(if (P_CheckExistsPat p_dir p_pat) (

		(foreach p_dir p_pat (

			(symbolset (cat "f" cnt) (tackon p_dir @each-name))

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

			(if (= 14 cnt) (
				(set usedopt (P_DeleteConfirmFiles2 defopt p_isdir f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11 f12 f13))

				(set cnt 0)
				(set defopt 0)
			))
		))

		(while (< cnt 14) (
			(symbolset (cat "f" cnt) "")
			(set cnt (+ 1 cnt))
		))

		(set usedopt (P_DeleteConfirmFiles2 defopt p_isdir f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11 f12 f13))
	))

	(set usedopt usedopt)
)


;***************************************************************************************************
;***	Procedure DeleteConfirmFiles2
;***************************************************************************************************
(procedure P_DeleteConfirmFiles2 p_defopt p_isdir p_f0 p_f1 p_f2 p_f3 p_f4 p_f5 p_f6 p_f7 p_f8 p_f9 p_f10 p_f11 p_f12 p_f13

	(if (= 2 @user-level) (

		(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 p_f12 p_f13)
				(default	p_defopt)
			)
		))
	)
	(set choice p_defopt))

	(set cnt 0)

	(while (< cnt 14) (

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

			;*** Append a delete command for each file/dir.
			;***
			(if (<> 0 p_isdir )
				(run (cat "echo >>t:csinstdelete.temp \"delete " delfile " all\""))
				(run (cat "echo >>t:csinstdelete.temp \"delete " delfile "\""))
			)
		))

		(set cnt (+ 1 cnt))
	))

	(set choice choice)
)


;***************************************************************************************************
;***	Procedure DeInstall
;***************************************************************************************************
(procedure P_DeInstall

	;*** Now REALLY delete the old files (script made by SetupInstall/PreDeInstall).
	;***
	(if (<> 1 @pretend) (
		(execute "t:csinstdelete.temp")
	))

	(P_Delete (tackon #destdevs "hyperIOVersion") "noicons" "noreq")
)


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

	(if (<> 3 #instchoice) (

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

			(if (<> 0 (P_CheckExists "sys:system/multiview"))
				(set mvpath "sys:system/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 ")
						(set mvpath "echo >con: ")
					)
				)
			)
		)

		(if (= 1 (askbool
			(prompt #msgshowreadme)
			(default 1)
			(help (cat #msgshowreadme "\n\n" @askbool-help))))

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

		(set tempuser @user-level)
		(user 2)
		(if (= 1 (askbool
			(prompt #msgreboot)
			(help (cat #msgreboot "\n\n" @askbool-help))
			(default 1)
			(choices #msgrebootyes #msgrebootno))) (

				(run (tackon (tackon #tempdir #tempinstdir) "reboot"))
			)
		)

		(user tempuser)
		(working #msgworkingcleanup)

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

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

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

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


;***************************************************************************************************
;***	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:csinstcheckpat#?.temp")
	(delete "t:csinstdelete.temp")
)


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

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

(complete 0)

(if (<> 1 #unarc )		(set #tempdir ""))

(P_PreInstall)

(complete 2)
(welcome)

(complete 4)
(P_About)

(if (P_CheckOldInst) (

	(complete 6)

	(P_CheckOS)
	(P_CheckCPU)

	(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 (<> 3 #instchoice) (

		(set msgend #msgendinst)
		(if (IN #instparts 0) (set msgend (cat msgend #msgconfirmdevsdest #destdevs)))
		(if (IN #instparts 1) (set msgend (cat msgend #msgconfirmlibsdest #destlibs)))
		(if (IN #instparts 2) (set msgend (cat msgend #msgconfirmdocsdest (tackon #destdocs #destdocsdir))))
		(if (IN #instparts 3) (set msgend (cat msgend #msgconfirmutildest (tackon #destutil #destdocsdir))))
		(if (= 2 #instchoice) (set msgend (cat msgend #msgconfirmbackdest (tackon #destback #destbackdir))))
	)
	(
		(set msgend #msgenddeinst)
	))

	(exit msgend)
))

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


