; Script to install TrapFax, Version 1.1 (20-Nov-93)

; ---- Environmental section ----

; The number of K needed to install TrapFax
(set diskspace_needed 820)

; The current version
(set tfax_ver 1)
(set tfax_rev 1)

; Source disk name
(set source_disk "TrapFax-Install:")

; Do not change. Magick.
(set current_version (+ (* 65536 tfax_ver) tfax_rev))
(set tfax_verstr (cat "TrapFax " tfax_ver "." tfax_rev))

(set osversion (/ (getversion "libs:version.library") 65536))
;(set osversion 36)

(set @app-name tfax_verstr)

; ---- Language section ----
;  1 English
;  2 Deutsch
;  3 Franįais
;  4 Svenska
;  5 Nederlands
;  6 Dansk

(set lang 0)
(if (>= osversion 38)
	(
;		(run "c/lang english deutsch franįais svenska nederlands dansk" (safe))
		(run "c/lang english deutsch" (safe))
		(set x (getenv "pref_language"))
		(set lang (- x 1))
		(if (= lang -1) (set lang 0))
	)
)

(set msg_readme (select lang
	"Read-Me"
	"Lies-Mich"
	"Read-Me"
	"Read-Me"
	"Read-Me"
	"Read-Me"
))

(set msg_aborted (select lang
	"\n\nInstallation aborted\n\n"
	"\n\nInstallation abgebrochen\n\n"
	"\n\nInstall terminé\n\n"
	"\n\n(S) Installation aborted\n\n"
	"\n\n(NL) Installation aborted\n\n"
	"\n\n(DK) Installation aborted\n\n"
))

(set msg_intro (select lang
	"\n\nThis program lets you install %s on a hard drive from scratch or upgrade from an older release."
	"\n\nHiermit können Sie %s auf einer Festplatte von Grund auf neu installieren oder eine ältere Version aktualisieren."
	"\n\nCe programme vous permet d'installer %s sur un disque dur pour la premičre fois, ou de mettre ā jour une version antérieure."
	"\n\nDetta program låter dig installera %s på en hårddisk. Det kan användas för att uppgradera en äldre version av TrapFax, eller för att installera från början."
 	"\n\nMet dit programma installeert u %s op een harddisk. Hetzij voor het eerst, hetzij om op een nieuwere versie over te gaan."
	"\n\nDette program lader dig installere %s på en harddisk.  Det kan opgradere en ældre version eller installere påny."
))

;(set msg_intro (select lang
;	"\n\nThis program lets you install %s on a hard drive from scratch."
;	"\n\nHiermit können Sie %s auf einer Festplatte von Grund auf neu installieren."
;	"\n\nCe programme vous permet d'installer %s sur un disque dur pour la premičre fois."
;	"\n\nDetta program låter dig installera %s på en hårddisk. Det kan användas för att installera från början."
; 	"\n\nMet dit programma installeert u %s op een harddisk. Hetzij voor het eerst, hetzij om op een nieuwere versie over te gaan."
;	"\n\nDette program lader dig installere %s på en harddisk.  Det kan installere påny."
;))

(set msg_where? (select lang
	"In which disk or drawer should a drawer called 'TrapFax' containing all files pertaining to %s be created?"
	"In welcher Schublade oder auf welcher Platte soll eine Schublade 'TrapFax', die alle Dateien für %s beinhaltet, angelegt werden?"
	"Dans quel tiroir ou partition voulez-vous créer un nouveau tiroir 'TrapFax', qui contient tous les fichier de %s?"
 	"På vilken partition eller låda skall en ny låda 'TrapFax' skapas, där %s placeras?"
 	"Op welke partitie of in welke lade moet een lade 'TrapFax', die alle bestanden voor %s bevat, worden aangemaakt?"
	"På hvilken disk/i hvilken skuffer skal %s installeres?"
))

(set msg_already_installed (select lang
	"\n%s is already installed in\n\n%s.\n\nInstall anyway?"
	"\n%s ist bereits in\n\n%s\n\ninstalliert.\n\nTrotzdem installieren?"
	"\n%s est déjā installé dans\n\n%s.\n\nInstaller quand męme?"
	"\n%s är redan installerat i\n\n%s.\n\nInstall?"
 	"\n%s is reeds in\n\n%s\n\ngeīnstalleerd. Install?"
	"\n%s er allerede installeret i\n\n%s.\n\nInstall?"
))

(set help_already_installed (select lang
	"\nThe current version of TrapFax is already installed in the directory shown.  Select 'Yes' if you want to re-install TrapFax, 'No' to abort."
	"\nDie aktuelle Version von TrapFax befindet sich bereits im angegebenen Verzeichnis. Wählen Sie bitte 'Ja' um TrapFax trotzdem zu installieren, 'Nein' um den Installationsvorgang abzubrechen."
	"\n%s est déjā installé dans\n\n%s.\n\nInstaller quand męme?"
	"\n%s är redan installerat i\n\n%s.\n\nInstall?"
 	"\n%s is reeds in\n\n%s\n\ngeīnstalleerd. Install?"
	"\n%s er allerede installeret i\n\n%s.\n\nInstall?"
))

(set msg_newer_installed (select lang
	"You are about to install %s in\n\n%s.\n\nHowever, version %ld.%ld is already installed.\n\nAre you sure you want to\noverwrite your newer version?"
	"Sie versuchen gerade %s in\n\n%s\n\nzu installieren. Allerdings ist dort bereits Version %ld.%ld installiert.\n\nMöchten Sie wirklich Ihre\nneuere Version überschreiben?"
	"Vous essayez d'installer %s dans\n\n%s,\n\nmais version %ld.%ld a été y installé auparavant.\n\nInstallation terminée. *****"
	"Du ska just installera %s i\n\n%s.\n\nVersion %ld.%ld finns dock redan installerad.\n\nInstallationen avbryts. *****"
 	"U wilde %s in\n\n%s\n\ninstalleren. Daar is versie %ld.%ld echter reeds geīnstalleerd.\n\nInstallatie afgebroken. *****"
	"Du er ved at installere %s i\n\n%s.\n\nVersion %ld.%ld er dog allerede installeret.\n\nInstallation afbrudt. *****"
))

(set msg_no_room (select lang
	"The installation of %s requires about %ldK of free storage on drive %s which only has %ldK available.\n\nDo you want to continue anyway?"
	"Um %s zu installieren, werden etwa %ldK freier Plattenplatz auf %s (etwa %ldK frei) benötigt.\n\nWollen Sie die Installation fortsetzen?"
	"Pour installer %s, il nous faut environ %ldKo libres sur %s, qui n'a plus que %ldKo libres.\n\nDésirez-vous de terminer l'install? *****"
 	"Installationen av %s kräver ca %ldK fritt lagringsutrymme på enhet %s, som bara har %ldK ledigt.\n\nVill du avbryter installationen? *****"
	"Voor het installeren van %s is ongeveer %ldK nodig. Op %s is echter slechts %ldK beschikbaar.\n\nWilt u *** Abort? *****"
	"Installationen af %s behøver ca. %ldK fri diskplads på drev %s, som kun har %ldK fri.\n\nInstallation afbrudt. *****"
))

(set help_no_room (select lang
	"TrapFax requires a certain amount of disk space on the hard disk.  There seems to be insufficient space available on the drive you want to install it on.\n\nSelect 'Yes' to ignore this warning and continue the installation procedure, select 'No' to abort."
	"TrapFax benötigt mehr Speicherplatz als auf der von Ihnen angegebenen Partition verfügbar ist.  Das kann dazu führen, daß der Installationsprozeß nicht vollständig ausgeführt werden kann.\n\nWählen Sie 'Ja' um die Warnung zu ignorieren und TrapFax trotzdem zu installieren, wählen Sie 'Nein' um den Installationsvorgang abzubrechen."
	"Pour installer %s, il nous faut environ %ldKo libres sur %s, qui n'a plus que %ldKo libres.\n\nDésirez-vous de terminer l'install? *****"
 	"Installationen av %s kräver ca %ldK fritt lagringsutrymme på enhet %s, som bara har %ldK ledigt.\n\nVill du avbryter installationen? *****"
	"Voor het installeren van %s is ongeveer %ldK nodig. Op %s is echter slechts %ldK beschikbaar.\n\nWilt u *** Abort? *****"
	"Installationen af %s behøver ca. %ldK fri diskplads på drev %s, som kun har %ldK fri.\n\nInstallation afbrudt. *****"
))

(set msg_abort_room (select lang
	"Not enough diskspace on destination drive '%s'.\n\nInstallation aborted."
	"Nicht genug Plattenplatz auf dem Ziellaufwerk '%s'.\n\nInstallation beendet."
	"Pas assez d'espace libre sur le disque destination '%s'.\n\nInstallation terminée."
 	"(S) *** Not enough diskspace on destination drive '%s'.\n\nInstallationen avbryts."
	"(NL) *** %s \n\nInstallatie afgebroken."
	"(DK) %s Installation aborted."
))


(set msg_create_dir (select lang
	"Creating drawer"
	"Erzeuge neue Schublade"
	"Création du tiroir"
 	"Skapar låda"
 	"Nieuwe lade wordt aangemaakt"
	"Opretter skuffe"
))

(set msg_which_lang? (select lang
	"Which languages do you want to install?"
	"Welche Sprachen sollen installiert werden?"
	"Quelles sont les langages ā installer?"
	"Vilka språk skall installeras?"
	"Welke taal moet geīnstalleerd worden?"
	"Hvilke sprog ønsker du at installere?"
))

(set msg_welcome (select lang
	"Welcome to the %s installation utility."
	"Willkommen beim %s-Installationsprogramm."
	"Bienvenu ā l'utilitaire d'installation %s"
 	"Välkommen till installationsprogrammet för %s."
 	"Welkom bij het %s installatieprogramma."
	"Velkommen til %s installationsprogramet."
))

(set msg_datatypes? (select lang
	"Do you want to install the FAXX datatype on your system? It will allow you to view fax files using the MultiView utility."
	"Soll der FAXX-DataType installiert werden? Er ermöglicht es, Fax-Dateien mit MultiView zu verwenden."
	"Voulez-vous installer le 'datatype FAXX' sur votre systčme? Il permet d'utilisier MultiView avec des fichier fax."
 	"Vill du installera datatypen FAXX i ditt system? Med den, kan du t.ex titta på fax dokument från MultiView."
 	"Wilt u het FAXX DataType installeren? Dit maakt het mogelijk, fax-bestanden te bekijken met MultiView."
	"Ønsker du at installere FAXX datatypen på dit system? Den giver dig mulighed for at se fax filer fra MultiView programmet."
))

(set help_datatypes? (select lang
	"With the FAXX datatype installed you can use MultiView in addition to TFaxView to view faxes.  It also allows other programs that support datatypes to display fax files.\n\nThe FAXX data type will be installed on your system partition (SYS:)\n\nSelect 'Yes' to install the FAXX datatype, 'No' to skip this part of the installation procedure."
	"Mit Hilfe des FAXX-DataTypes können Sie MultiView dazu benutzen, Faxe anzuzeigen.  Außerdem erlaubt es Programmen, die den DataType-Standard unterstützen, ebenfalls Faxe anzuzeigen.\n\nBitte wählen Sie 'Ja', um den FAXX-DataType auf Ihrer Systempartition (SYS:) zu installieren, wählen Sie 'Nein', wenn Sie das nicht wünschen."
	"Voulez-vous installer le 'datatype FAXX' sur votre systčme? Il permet d'utilisier MultiView avec des fichier fax. *****"
 	"Vill du installera datatypen FAXX i ditt system? Med den, kan du t.ex titta på fax dokument från MultiView. *****"
 	"Wilt u het FAXX DataType installeren? Dit maakt het mogelijk, fax-bestanden te bekijken met MultiView. *****"
	"Ønsker du at installere FAXX datatypen på dit system? Den giver dig mulighed for at se fax filer fra MultiView programmet. *****"
))

(set msg_examples? (select lang
	"\nDo you want to install the example fax files?"
	"\nWollen Sie Beispiel-Faxdateien installieren?"
	"\nVoulez-vous installer les fichiers exemplaires?"
	"\nVill du installera exempel fax filerna?"
 	"\nWilt u het *** fax example files *** installeren?"
	"\n(DK) Do you want to install the example fax files?"
	"\n(I) Do you want to install the example fax files?"
))

(set help_examples? (select lang
	"TrapFax comes with example fax files.  Experimenting with these examples will help you understanding the program and getting acquainted with its functions.\n\nSelect 'Yes' to install the example faxes, select 'No' if you don't want them installed."
	"TrapFax wird mit einer Reihe von Beispielfaxen ausgeliefert.  Mit Hilfe dieser Faxe können Sie den Umgang mit TrapFax leicht erlernen.\n\nWählen Sie 'Ja' um die Beispielfaxe zu installieren, 'Nein' um sie nicht zu installieren."
	"Voulez-vous installer les fichiers exemplaires? *****"
	"Vill du installera exempel fax filerna? *****"
 	"Wilt u het *** fax example files *** installeren? *****"
	"(DK) Do you want to install the example fax files? *****"
	"(I) Do you want to install the example fax files? *****"
))

; ---- Program section ---- Oops, COBOL? :)

(welcome (msg_welcome tfax_verstr))
(message (msg_intro tfax_verstr))

(complete 0)

(if (< osversion 37)
	(abort "TrapFax needs at least version 2.04 of the operating system")
)

(set tfaxdir
	(set @default-dest
		(tackon
			(expandpath
				(askdir
					(prompt (msg_where? tfax_verstr))
					(help @askdir-help)
					(default @default-dest)
				)
			)
		"TrapFax"
		)
	)
)


; Find out whether this may be an update from an earlier version...

(set is_update 0)
(set ver_file (tackon tfaxdir "TrapFax.version"))

(if (exists ver_file)
	(if (= (set installed_ver (getversion ver_file)) current_version)
		(if (not (askbool (prompt (msg_already_installed tfax_verstr tfaxdir))
								(help help_already_installed)
					)
			 )
			(abort msg_aborted)
		)
		(if (< installed_ver current_version)
			(
				(set is_update 1)
			)
			(if (not (askbool (prompt (msg_newer_installed tfax_verstr tfaxdir
							(/ installed_ver 65536) (bitand installed_ver 65535)))
								(help @askbool-help)
						)
				 )
				(abort msg_aborted)
				(set is_update 1)
			)

;			(abort (msg_newer_installed tfax_verstr tfaxdir
;							(/ installed_ver 65536) (bitand installed_ver 65535))
;			)
		)
	)
;	(
;		(run (cat (tackon source_disk "c/initprefs") " " tfaxdir) (safe))
;	)
)

(run (cat (tackon source_disk "c/initprefs") " " tfaxdir) (safe))

; if update, delete obsolete stuff
(if is_update
	(
		(run ("C:Delete >NIL: Quiet All " (tackon tfaxdir "Catalogs/#?")))
;		(run "C:Delete >NIL: Quiet All ENV:TrapFax/#? ENVARC:TrapFax/#?")
		(run "C:Delete >NIL: Quiet LOCALE:Catalogs/#?/trapfax-printer.catalog")
	)
)

(if (< (getdiskspace (pathonly tfaxdir)) (* diskspace_needed 1024))
	(if (not (askbool (prompt (msg_no_room tfax_verstr diskspace_needed (pathonly tfaxdir)
				 			(/ (getdiskspace (pathonly tfaxdir)) 1024)))
					 (help help_no_room)
					 (default 1)
				)
		 )
		 (abort (msg_abort_room (pathonly tfaxdir)))
	)
)

(complete 10)

(makedir tfaxdir (prompt msg_create_dir tfaxdir)
					  (infos)
)

(complete 20)

(copyfiles
	(source (tackon source_disk "TrapFax"))
	(dest tfaxdir)
	(all)
	(infos)
	(optional force)
)

(complete 29)

(if (not (exists (tackon tfaxdir "TrapFax.Log")))
	(textfile
		(dest (tackon tfaxdir "TrapFax.Log"))
		(append "******  01/01 00:00 Preferences missing. Please set up using TFaxPrefs first.")
	)
)

(complete 30)

(copyfiles
	(source (tackon source_disk "TrapFax/Storage/Presets"))
	(dest "SYS:Prefs/Presets")
	(all)
	(infos)
	(optional force)
)

(complete 40)

(set do_it 0)
(if (< @user-level 2)
	(set do_it 1)
	(set do_it (askbool (prompt msg_examples?)
						(help help_examples?)
						(default 1)
					)
	)
)

(complete 45)

(if do_it
	(copyfiles
		(source (tackon source_disk "Examples"))
		(dest tfaxdir)
		(all)
		(infos)
		(optional force)
	)
)

(complete 50)

(tooltype
	(dest (tackon tfaxdir "TFaxAnswer"))
	(setdefaulttool (tackon tfaxdir "TFaxDoor"))
)

(tooltype
	(dest (tackon tfaxdir "Templates/incoming"))
	(setdefaulttool (tackon tfaxdir "TFaxView"))
	(noposition)
)

(tooltype
	(dest (tackon tfaxdir "Templates/fax"))
	(setdefaulttool (tackon tfaxdir "TFaxView"))
	(noposition)
)

(tooltype
	(dest (tackon tfaxdir "Templates/ilbm"))
	(noposition)
)

(complete 60)

(if (not @pretend)
	(copyfiles
		(source (tackon tfaxdir "Storage/Printers"))
		(dest "DEVS:Printers")
		(all)
		(infos)
		(optional force)
	)
)

(complete 70)

(if (>= osversion 38)
	(
      (set langbits
         (askoptions
            (prompt msg_which_lang?)
            (help @askoptions-help)
            (choices "English"
                     "Deutsch"
;                     "Franįais"
;                     "Svenska"
;                     "Nederlands"
;                     "Dansk"
            )
            (default -1)
         )
      )

      (set n 0)
      (set langpat "(%")
      (while (set this_lang (select n
      				    "English"
                                    "Deutsch"
;                                    "Franįais"
;                                    "Svenska"
;                                    "Nederlands"
;                                    "Dansk"
                                    ""
                            )
              )

              (
                  (if (in langbits n)
                     (set langpat (cat langpat "|" this_lang))
                  )
                  (set n (+ n 1))
              )
      )

      (set langpat (cat langpat ")"))

      (complete 80)

      (copyfiles
         (source (tackon source_disk "TFCatalogs"))
         (dest (tackon tfaxdir "Catalogs"))
         (pattern langpat)
         (optional force)
      )
	)
)

(complete 90)

(copyfiles
	(source source_disk)
	(dest tfaxdir)
	(pattern "(Read|Lies)#?")
	(optional force)
	(infos)
)

(tooltype
	(dest (tackon tfaxdir "Read-Me"))
	(setdefaulttool "More")
	(noposition)
)
(tooltype
	(dest (tackon tfaxdir "Lies-Mich"))
	(setdefaulttool "More")
	(noposition)
)

(complete 95)

; Now do some magic if we are running under 3.0

(if (>= osversion 39)
(
	(set do_it 0)
	(if (< @user-level 2)
		(set do_it 1)
		(set do_it (askbool (prompt msg_datatypes?)
							(help help_datatypes?)
							(default 1)
						)
		)
	)
	(if (and do_it (not @pretend))
		(
			(copyfiles
				(source (tackon source_disk "Classes/Datatypes/faxx.datatype"))
				(dest "SYS:Classes/Datatypes")
				(optional force)
			)

			(copyfiles
				(source (tackon tfaxdir "Storage/Datatypes"))
				(dest ("DEVS:Datatypes"))
				(all)
				(optional force)
			)

		   (run "C:AddDatatypes QUIET REFRESH")
		)
	)

   (complete 97)

	(tooltype
		(dest (tackon tfaxdir "Templates/ilbm"))
		(setdefaulttool "MultiView")
		(noposition)
	)

	(tooltype
		(dest (tackon tfaxdir "Read-Me"))
		(setdefaulttool "MultiView")
		(noposition)
	)
	(tooltype
		(dest (tackon tfaxdir "Lies-Mich"))
		(setdefaulttool "MultiView")
		(noposition)
	)
	(tooltype
		(dest (tackon tfaxdir "TrapFax.log"))
		(setdefaulttool "MultiView")
	)

))

(complete 99)

(if (>= osversion 39)
	(set disp_readme (cat "run <nil: >nil: SYS:Utilities/MultiView \"" (tackon tfaxdir msg_readme) "\""))
	(set disp_readme (cat "run <nil: >nil: SYS:Utilities/More \"" (tackon tfaxdir msg_readme) "\""))
)

(run disp_readme)

(complete 100)

(exit)
