;  $VER: InstallYGM 1.18 (30.4.2002) Copyright © 1999-2002 by Stefan Falke
;  $Revision: 1.18 $ $Date: 2002/04/30 14:34:32 $

(set #prg_name "YGM")
(set #assign "YGM")

(set #destdev "DH0:")
(set #destdir "YGM")
(set #install_dest #destdev)

(set #verstr "2.7")

(set @default-dest "")

(set #vernum (getversion))
(set #os_ver (/ #vernum 65536))
(set #os_rev (- #vernum (* #os_ver 65536)))

(set #invernum @installer-version)
(set #in_ver (/ #invernum 65536))
(set #in_rev (- #invernum (* #in_ver 65536)))


(procedure setLanguage
	(set #lang_dk 0)
	(set #lang_de 1)
	(set #lang_en 2)
	(set #lang_es 3)
	(set #lang_it 4)
	(set #lang_no 5)
	(set #lang_builtin #lang_en)

	(set #language #lang_builtin)

	(set #lch_dku "Dansk")
	(set #lch_deu "Deutsch")
	(set #lch_enu "English")
	(set #lch_esu "Español")
	(set #lch_itu "Italiano")
	(set #lch_nou "Norsk")

	(set #lch_dkl "dansk")
	(set #lch_del "deutsch")
	(set #lch_enl "english")
	(set #lch_esl "español")
	(set #lch_itl "italiano")
	(set #lch_nol "norsk")

	(if (= #lch_dkl @language) (set #language #lang_dk))
	(if (= #lch_del @language) (set #language #lang_de))
	(if (= #lch_enl @language) (set #language #lang_en))
	(if (= #lch_esl @language) (set #language #lang_es))
	(if (= #lch_itl @language) (set #language #lang_it))
	(if (= #lch_nol @language) (set #language #lang_no))

	(if (= #in_ver 0) (
		(set #langhelp "Please choose your language\nBitte Sprache auswählen")
		(set #language (askchoice
				(choices #lch_dku #lch_deu #lch_enu #lch_esu #lch_itu #lch_nou)
				(prompt #langhelp)
				(help #langhelp)
				(default #language)
			)
		)
	))

	; English strings
	(set #wrongversion "\n\n\nThis installation script needs Installer V42.6 or better.")

	(set #welcome "\n\nPOP3 mailbox checker\n\nCopyright © 1999-2002 by Stefan Falke, All Rights Reserved.\nFreeware software\n\nAuthor: Stefan Falke\n\nWeb: www.sfxsoft.de\nEMail: support@sfxsoft.de")
	(set #welcome2 "\nThis installation script may be used for a\n\n» First time installation «\n\nor to\n\n» Update an existing installation «")

	(set #installnow "\nThe install script has all necessary information to install YGM on your system.\n\nThe YGM files will now be copied.")

	(set #chdir "Please select a destination directory\nfor the installation.\n\nNo drawer will be created by default.")
	(set #chdirhelp "You have to specify now the path of the drawer in which all files shall be copied.\nNon existant drawers can be created from within this install script including their accompanying icons.")

	(set #asklibdir "In which drawer do you want the support libraries to be installed?")

	(set #lchelp "Please select the language catalog to be installed")
	(set #askcatdir "In which drawer do you want the catalog to be installed?")

	(set #iconnew "\nDo you want the existing YGM Icon to be copied over by the new icon from the installation archive?\nChoose 'No' if you have modified any tooltypes of the existing icon.\n(Recommended choice: 'No')")
	(set #owhelp "If you respond to this requester with 'Yes', a possibly existing %sversion will be written over completely!")
	(set #owhelp2 "If you respond to this requester with 'Yes', a possibly existing file will be written over completely!")

	(set #askassign "Do you want an assign for \"%s:\" to \"%s\" to be added to the User-Startup file?")
	(set #assignhelp "If you respond to this requester with 'Proceed', an assign to the logical device '%s:' will be added to the User-Startup file which will ease the installation of newer releases and the access to all %s files.")

	(set #askinstall1 "Do you want to install the main program again?")
	(set #askinstall2 "Do you want to install the main program with version %ld.%ld?")
	(set #installed1 (cat "Version %ld.%ld of the program \"%s\" presumedly has already been installed before.\n" #askinstall1))
	(set #installed2 (cat "ATTENTION! Version %ld.%ld of the program \"%s\" already exists in the destination drawer.\n" #askinstall2))

	(set #pr_copylibs "Copy support library ")
	(set #pr_copycats "Copy language catalog")
	(set #pr_copysdir "Copy script and option files")
	(set #pr_copyguide "Copy user guide")
	(set #pr_copymain "Copy main program")

	(set #newer "newer ")
	(set #older "older ")
	(set #no "No")
	(set #yes "Yes")

	; German strings
	(if (= #language #lang_de) (
	(set #wrongversion "\n\n\nDieses Installations-Skript benötigt den Installer V42.6 oder neuer.")

	(set #welcome "\n\nPOP3-Mailbox Checker\n\nCopyright © 1999-2002 Stefan Falke, Alle Rechte vorbehalten.\nFreeware-Software\n\nAuthor: Stefan Falke\n\nWeb: www.sfxsoft.de\nEMail: support@sfxsoft.de")
	(set #welcome2 "\nDieses Installations-Skript kann für eine\n\n» Erstinstallation «\n\noder zum\n\n» Updaten einer vorhandenen Installation «\n\nverwendet werden.")

	(set #installnow "\nDas Install-Skript hat alle notwendigen Informationen, um YGM auf Ihrem System zu intstallieren.\n\nDie YGM-Dateien werden jetzt kopiert.")

	(set #chdir "Bitte Ziel-Verzeichnis für\nInstallation auswählen.\n\nEin eigenes Verzeichnis wird nicht\nautomatisch erzeugt.")
	(set #chdirhelp "Sie müssen jetzt den Pfad des Verzeichnisses angeben, in das die Dateien kopiert werden sollen.\nNoch nicht vorhandene Verzeichnisse können von diesem Installationprogramm aus angelegt werden und mit einem Schubladen-Icon versehen werden.")

	(set #asklibdir "In welchem Verzeichnis sollen die Support-Libraries installiert werden?")

	(set #lchelp "Wählen Sie den Sprachen-Katalog der installiert werden soll.")
	(set #askcatdir "In welchem Verzeichnis soll der Sprachen-Katalog installiert werden?")

	(set #iconnew "\nWollen Sie das bereits vorhandene YGM-Icon mit dem Icon aus dem Installations-Archiv überschreiben?\nWenn Sie in dem vorhandenen Icon ToolTypes verändert haben, sollten Sie 'Nein' wählen.\n(Empfohlene Wahl: 'Nein')")
	(set #owhelp "Wenn Sie diesen Requester mit 'Ja' beantworten, wird eine eventuell schon vorhandene %sVersion komplett überschrieben!")
	(set #owhelp2 "Wenn Sie diesen Requester mit 'Ja' beantworten, wird eine eventuell schon vorhandene Datei komplett überschrieben!")

	(set #askassign "Soll ein Assign für \"%s:\" auf \"%s\" in die Datei User-Startup eingefügt werden?")
	(set #assignhelp "Wenn Sie diesen Requester mit 'Weiter' beantworten, wird ein Assign auf das logische Device '%s:' in die Datei User-Startup eingefügt, wodurch das Installieren neuerer Versionen und der Zugriff auf %s-Dateien vereinfacht wird.")

	(set #askinstall1 "Wollen sie das Hauptprogramm erneut installieren?")
	(set #askinstall2 "Wollen sie das Hauptprogramm mit der Version %ld.%ld installieren?")
	(set #installed1 (cat "Die Version %ld.%ld des Programmes \"%s\" wurde vermutlich schon zuvor in dem angegebenen Zielverzeichnis installiert.\n" #askinstall1))
	(set #installed2 (cat "ACHTUNG! In dem angegebenen Zielverzeichnis befindet sich bereits die Version %ld.%ld des Programmes \"%s\".\n" #askinstall2))

	(set #pr_copylibs "Kopieren der Support-Library ")
	(set #pr_copycats "Kopieren des Sprachen-Katalogs")
	(set #pr_copysdir "Kopieren der Script- und Einstellungs-Dateien")
	(set #pr_copyguide "Kopieren der Bedienungsanleitung")
	(set #pr_copymain "Kopieren des Hauptprogrammes")

	(set #newer "neuere ")
	(set #older "ältere ")
	(set #no "Nein")
	(set #yes "Ja")
	))

	; Spanish strings 1.2.0 (19.2.00) by Dámaso D. Estévez <amidde@arrakis.es>
	(if (= #language #lang_es) (
	(set #chdir "Por favor, elija un directorio de destino\npara la instalación.\n\nNo se creará ningún cajón adicional por defecto.")
	(set #chdirhelp "Debe especificar el camino de acceso al cajón en el que todos los ficheros serán copiados.\nLos cajones que no existan (y sus correspondientes iconos) serán creados desde este guión instalador.")

	(set #asklibdir "¿En qué cajón desea que sea instalada la biblioteca de soporte?")

	(set #lchelp "Por favor, elija el catálogo del idioma que desea instalar")
	(set #askcatdir "En qué cajón desea instalar el catálogo?")

	(set #iconnew "\n¿Desea que el icono de YGM sea sobreescrito por el nuevo icono incluido en el paquete de instalación?\nResponda negativamente si ha modificado algún tipo de herramienta del icono preexistente en su equipo.\n(Opción recomendada: `No')")
	(set #owhelp "Si responde positivamente a esta petición, una posible versión preexistente %s será sobreescrita completamente.")
	(set #owhelp2 "Si responde positivamente a esta petición, un posible fichero preexistente será sobreescrito completamente.")

	(set #askinstall1 "¿Desea instalar el programa principal de nuevo?")
	(set #askinstall2 "¿Desea instalar el programa principal con la versión %ld.%ld?")
	(set #installed1 (cat "La versión %ld.%ld del programa \"%s\" presumiblemente ya ha sido instalada de forma completa.\n" #askinstall1))
	(set #installed2 (cat "¡ATENCIÓN! La versión %ld.%ld del programa \"%s\" ya existe en el cajón de destino.\n" #askinstall2))

	(set #pr_copylibs "Copiando biblioteca de soporte")
	(set #pr_copycats "Copiando catálogo de idioma")
	(set #pr_copysdir "Copiando guión y ficheros de opciones")
	(set #pr_copyguide "Copiando guía del usuario")
	(set #pr_copymain "Copiando programa principal")

	(set #newer "más reciente ")
	(set #older "más antigua ")
	(set #no "No")
	(set #yes "Sí")
	))

	; Italian strings (12.3.00) by Rosario D'Angelo <mystical@mystical.ontheweb.nu>
	(if (= #language #lang_it) (
	(set #chdir "Seleziona una directory per l'installazione\n\nUn cassetto NON verrà creato.")
	(set #chdirhelp "Devi specificare una directory dove i file debbano essere copiati.\nNuovi cassetti possono essere creati da questa installazione assieme alle rispettive icone.")

	(set #asklibdir "In quale cassetto vuoi che le librerie di supporto vengano installate?")

	(set #lchelp "Seleziona quali linguaggi debbano essere installati")
	(set #askcatdir "In quale cassetto vuoi che i file di catalog vengano installati?")

	(set #iconnew "\nVuoi che l'icona già presente di YGM venga sovrascritta da quella copiata dall'installazione?\nScegli 'No' se hai modificato i parametri dell'icona esistente.\n(Scelta raccomandata: 'No')")
	(set #owhelp "Se rispondi di 'Si' a questo requester, un'icona possibilmente %sversion già esistente verrà sovrascritta completamente!")
	(set #owhelp2 "Se rispondi di 'Si' a questo requester, un file possibilmente esistente verrà sovrascritto completamente!")

	(set #askinstall1 "Vuoi installare il programma principale un'altra volta?")
	(set #askinstall2 "Vuoi installare il programma con la versione %ld.%ld?")
	(set #installed1 (cat "La versione %ld.%ld del programma \"%s\" è già stata installata precedentemente.\n" #askinstall1))
	(set #installed2 (cat "ATTENZIONE! La versione %ld.%ld del programma \"%s\" esiste già nel cassetto destinazione.\n" #askinstall2))

	(set #pr_copylibs "Copia libreria di supporto ")
	(set #pr_copycats "Copia file di catalogo")
	(set #pr_copysdir "Copia script e file con le opzioni")
	(set #pr_copyguide "Copia manuale utente")
	(set #pr_copymain "Copia programma principale")

	(set #newer "più nuova ")
	(set #older "più vecchia ")
	(set #no "No")
	(set #yes "Si")
	))
)

(procedure askUserOpts
	(chooseDestDir)
	(chooseLibDir)
	(chooseCats)

	(set #ddir @default-dest)
	(checkMain (tackon #ddir #prg_name) #prg_name)
)

(procedure startcopy
	(working)

	(set Install_src "")

	(if (= #docopymain 1) (
		(copyMain #ddir #prg_name)

		(copyLibs "fgui.library")
		(copyLibs "ygm_fgui.gui")
		(copyLibs "ygm_ra.gui")
		(copyCats)

		(copyGuides "YGM.guide")

		(set cpattern "#?")
		(copyDir (tackon #install_dest "rexx") "rexx")

		(set cpattern "~(#?.dat)")
		(copyDir (tackon #install_dest "S") "S")

		(copyDat (tackon #install_dest "S") "S")
	))

)

(procedure chooseLibDir
	(set libdirc (askchoice
			(choices (tackon @default-dest "libs") "LIBS:")
			(prompt #asklibdir)
			(help #asklibdir)
			(default 0)
		)  
	)

	(if (= libdirc 0) (
		(set libdir @default-dest)
	)(
		(set libdir "LIBS:")
	))
)

(procedure copyLibs _source
	(if (= libdirc 0) (
		(if (< (exists (tackon libdir "libs")) 2)
			(makedir (tackon libdir "libs"))
		)
	))

	(set path (tackon Install_src (cat "libs/" _source)))

	(copylib
		(prompt (cat #pr_copylibs _source))
		(help @copylib-help)
		(source path)
		(dest (tackon libdir "libs"))
		(optional "nofail")
		(confirm)
	)
)

(procedure chooseCats
	(set catalog (askchoice
			(choices #lch_dku #lch_deu #lch_enu #lch_esu #lch_itu #lch_nou)
			(prompt #lchelp)
			(help #lchelp)
			(default #language)
		)
	)

	(if (= catalog #lang_dk) (set #ulcat #lch_dkl))
	(if (= catalog #lang_de) (set #ulcat #lch_del))
	(if (= catalog #lang_en) (set #ulcat #lch_enl))
	(if (= catalog #lang_es) (set #ulcat #lch_esl))
	(if (= catalog #lang_it) (set #ulcat #lch_itl))
	(if (= catalog #lang_no) (set #ulcat #lch_nol))

	(if (= catalog #lang_builtin) (set #ulcat ""))
	(if (<> #ulcat "") (
		(set catdirc (askchoice
				(choices (tackon @default-dest (cat "Catalogs/" #ulcat)) (cat "LOCALE:Catalogs/" #ulcat) )
				(prompt #askcatdir)
				(help #askcatdir)
				(default 0)
			)  
		)

		(if (= catdirc 0) (
			(set catdir @default-dest)
		)(
			(set catdir "LOCALE:")
			(if (< (exists "LOCALE:" (noreq)) 2) (
				(makedir "sys:Locale")
				(makeassign "LOCALE" "sys:Locale")
			))
			)
		)
	))
)

(procedure copyCats
	(if (<> #ulcat "") (
		(if (< (exists (tackon catdir "Catalogs")) 2)
			(makedir (tackon catdir "Catalogs"))
		)
		(if (< (exists (tackon catdir (cat "Catalogs/" #ulcat)) ) 2)
			(makedir (tackon catdir (cat "Catalogs/" #ulcat)) )
		)
		(copylib
			(prompt #pr_copycats)
			(help @copylib-help)
			(source (cat (tackon Install_src "Catalogs/") #ulcat "/ygm.catalog"))
			(dest (tackon catdir (cat "Catalogs/" #ulcat)) )
			(optional "nofail")
			(confirm)
		)
	))
)

(procedure copyDir _dest _source
	(if (< (exists _dest) 2)
		(makedir _dest)
	)
	(copyfiles
		(prompt #pr_copysdir)
		(help @copyfiles-help)
		(source _source)
		(dest _dest)
		(pattern cpattern)
		(confirm)
	)
)

(procedure copyDat _dest _source
	(if (= (exists (tackon _dest "YGM.dat")) 0)
		(copyfiles
			(prompt #pr_copysdir)
			(help @copyfiles-help)
			(source (tackon _source "YGM.dat"))
			(dest _dest)
			(confirm)
		)
	)
)

(procedure copyGuides _dest
	(set file (tackon Install_src _dest))

	(if (= (exists file) 1)
		(copyfiles
			(prompt #pr_copyguide)
			(help @copyfiles-help)
			(source file)
			(dest #install_dest)
			(infos)
			(optional "nofail")
			(confirm)
		)
	)

	(if (>= #os_ver 39)
		(tooltype
			(dest (tackon #install_dest _dest))
			(setdefaulttool "MultiView")
		)
		(tooltype
			(dest (tackon #install_dest _dest))
			(setdefaulttool "AmigaGuide")
		)
	)
)

(procedure copyMain _destdir _source
	(if (= #nocopyicon 1) (
		(copyfiles
			(prompt #pr_copymain)
			(help @copyfiles-help)
			(source _source)
			(dest _destdir)
			(optional "force")
			(confirm)
		)
	)(
		(copyfiles
			(prompt #pr_copymain)
			(help @copyfiles-help)
			(source _source)
			(dest _destdir)
			(infos)
			(optional "force")
			(confirm)
		)
	))
)

(procedure checkMain _dest _source
	(if (= (exists _dest) 1) (
		(set ver_source (getversion _source))
		(set ver_s (/ ver_source 65536))
		(set rev_s (- ver_source (* ver_s 65536)))

		(set ver_dest (getversion _dest))
		(set ver_d (/ ver_dest 65536))
		(set rev_d (- ver_dest (* ver_d 65536)))

		(if (= ver_source ver_dest) (
			(set vprompt (#installed1 ver_s rev_s #prg_name))
			(set vhelp (#owhelp ""))
			(set #docopymain
				(askbool
					(prompt	vprompt)
					(help		vhelp)
					(choices #yes #no)
				)
			)
			(if (= @user-level 0) (set #docopymain 1))
		))
		(if (< ver_source ver_dest) (
			(set vprompt (#installed2 ver_d rev_d #prg_name ver_s rev_s))
			(set vhelp (#owhelp #newer))
			(set #docopymain
				(askbool
					(prompt	vprompt)
					(help		vhelp)
					(choices #yes #no)
				)
			)
			(if (= @user-level 0) (set #docopymain 0))
		))
		(if (> ver_source ver_dest) (
			(set vprompt (#installed2 ver_d rev_d #prg_name ver_s rev_s))
			(set vhelp (#owhelp #older))
			(set #docopymain
				(askbool
					(prompt	vprompt)
					(help		vhelp)
					(choices #yes #no)
				)
			)
			(if (= @user-level 0) (set #docopymain 1))
		))
	)(
		(set #docopymain 1)
	))

	(if (= #docopymain 1) (
		(set #nocopyicon 0)

		(if (exists (cat (tackon #install_dest #prg_name) ".info"))
			(set #nocopyicon
				(askchoice	(choices #yes #no)
					(prompt #iconnew)
					(help   #iconnew)
					(default 1)
				)
			)
		)
	))
)

(procedure chooseDestDir
	(if (= (exists (cat #assign ":") (noreq)) 2) (
		(set #install_dest (getassign #assign))
	)(
		(if (= (exists #destdev (noreq)) 0) (
			(set #destdev (cat (getdevice "sys:") ":"))
			(set #install_dest #destdev)
		))
		(if (= @user-level 0)
			(set #install_dest (cat #destdev #destdir))
			(set #install_dest #destdev)
		)
	))

	(set @default-dest #install_dest)

	(set #install_dest
		(askdir
			(prompt	#chdir)
			(help		#chdirhelp)
			(default	#install_dest)
			(newpath)
			(disk)
		)
	)

	(set assname (cat #assign ", © 1999-2002 by Stefan Falke"))
	(set cmd (cat "assign "#assign": \"" #install_dest "\""))

	(if (= @default-dest #install_dest) (
		(if (= (exists @default-dest) 0) (
			(makedir @default-dest
					(infos)
			)
		))

		(if (= (exists (cat #assign ":") (noreq)) 0) (
			(startup assname
				(prompt	(#askassign #assign #install_dest))
				(help		(#assignhelp #assign #prg_name))
				(command	cmd)
				(confirm)
			)
		))

	)(
		(set @default-dest #install_dest)

		(startup assname
			(prompt	(#askassign #assign #install_dest))
			(help		(#assignhelp #assign #prg_name))
			(command	cmd)
			(confirm)
		)

	))

	(makeassign #assign #install_dest)

	(user defuser)
)

;
; Start
;
(if (>= #in_ver 44 ) (
	(effect "center" "horizontal" $0000FF $000000)
))

(setLanguage)

(message (cat "\n" #prg_name " V" #verstr #welcome) (all))

(message #welcome2 (all))

; We need at least Installer 42.6
(if (< #invernum 2752518) (
	(message #wrongversion (all))
	(exit (quiet))
))

(welcome)

(set defuser @user-level)

(askUserOpts)

(message #installnow (all))

(startcopy)

(exit)
