;
; $VER: Install MultiView 3.1 (09.11.97)
;
; Installer script for MultiView.
;

(set #english-lang 1)
(set #polish-lang  2)


; Get current language (no need for lots of silly icons! ;). However, this
; won't properly work for all versions of the Installer. Some don't
; understand the language "default" in the tool types... :/

(if (= (exists "Env:Language") 1)
	; GetEnv reports "String too long" if the variable doesn't exist! :/
	; Dunno if this is fixed in V43... But we need to check anyway.
	(set @language (getenv "language"))
)


;**************************************************************************
;
; English strings
;

(set #default-lang #english-lang)

(set #builtin-lang "(built in)")

(set #bad-kick
	"You must have AmigaOS Release 2.04 or higher to use MultiView."
)

(set #install-parts "Please select the parts you wish to install")

(set #item-program "MultiView")

(set #item-library "FileID.library")

(set #item-guide   "MultiView.guide")

(set #item-locale  "Translations")

(set #parts-header-help
	(cat
		"    Here you select the different parts of MultiView that you would like to "
		"install. After that, you select the details of the installation (such as "
		"where the different files should be installed). You may choose to install "
		"the following items:\n"
	)
)

(set #item-program-help
	(cat
		"    MultiView: This program is a replacement for C= MultiView and should be "
                "installed in SYS:Utilities/ directory.\n"
	)
)

(set #item-library-help
	(cat
		"    FileID.library: This library contains filetype recognizing functions.\n"
	)
)

(set #item-guide-help
	(cat
		"    MultiView.guide: The manual, in AmigaGuide format. It contains "
		"some general information about MultiView.\n"
	)
)

(set #item-local-help
	(cat
		"    Translations: If you install a translation, then MultiView  "
		"and FileID.library can operate in the language(s) you select.\n"
	)
)

(set #parts-footer-help
	(cat
		"    For more information about these items, please see the manual.\n"
	)
)

; Only for expert users
(set #where-program "Where would you like to install Main program?")
(set #where-program-help
	(cat
                "    MultiView: This program is a replacement for old Multiview written "
                "by Commodore programmers. You should install it in SYS:Utilities.\n"
	)
)
(set #where-library "Where would you like to install FileID.library?")

(set #where-library-help
	(cat
		"    FileID.library is a shared library. As such, MultiView "
		"(and applications using it) expects this file to be "
		"avilable via the \"Libs:\"-assign, so please install this "
		"file into the \"Libs:\" drawer, or make sure that the "
		"drawer you install it in will be a part of your "
		"\"Libs:\"-assign.\n"
	)
)

(set #where-guide "Where would you like to install MultiView.guide?")

(set #where-guide-help
	(cat
		"    MultiView.guide is a file in the standard AmigaGuide format. "
		"As MultiView currently makes specific use of this file, you can install "
		"it whereever you find convenient. If you have OS 3.0 or higher, "
		"one such place is \"Help:\", as this is where other AmigaGuide "
		"files often are installed.\n"
	)
)

; Only for expert users, and an icon wasn't found
(set #copy-guide-icon "Do you want to install the icon for MultiView.guide?")

(set #copy-guide-icon-help
	(cat
		"    Since you stated that you are an expert user, and there currently "
		"is no icon for MultiView.guide where you selected to install it, "
		"you get a chance to decide if the icon should be installed as well.\n"
	)
)

(set #which-language "Which languages should be installed?")

(set #which-language-help
	(cat
		"    The Amiga can be operated in many different languages. If you "
		"want MultiView to use the same language as your Amiga Workbench, "
		"then a couple of catalog files must be copied to your harddisk "
		"for each language supported.\n"
		"    To reduce the amount of space consumed by the language files, "
		"you can select to have only the files of specific languages "
		"copied.\n"
		"    Simply check the boxes of the languages you wish to have have "
		"available on your system.\n"
	)
)

(set #copy "Copying %s to %s...")

;**************************************************************************
;
; Polish strings
;

(if (= @language "polski")
	(
		(set #default-lang #polski-lang)
		(set #builtin-lang "(wbudowany)")
		(set #bad-kick
			"Musisz mieź system w wersji przynajmniej 2.04."
		)

		(set #install-parts "Wybierz czėōci, które chcesz zainstalowaź")
		(set #item-program "MultiView")
		(set #item-library "FileID.library")
		(set #item-guide   "MultiView.guide")
		(set #item-locale  "Tīumaczenia")

		(set #parts-header-help
			(cat
		                "    Tu moūesz wybraź poszczególne czėōci pakietu do zainstalowania. Potem "
		                "wybierzesz gdzie chcesz je zainstalowaź. Do wyboru masz :\n"
			)
		)

		(set #item-program-help
			(cat
		                "    MultiView: Ten program jest zamiennikiem dla starego MultiView-a napisanego "
		                "jeszcze przez ludzi z Commodore. Powinieneō zainstalowaź go w katalogu SYS:Utilities.\n"
			)
		)

		(set #item-library-help
			(cat
		                "    FileID.library: Ta biblioteka zawiera funkcje do rozpoznawania plików.\n"
			)
		)

		(set #item-guide-help
			(cat
		                "    MultiView.guide: Dokumentacja w formacie AmigaGuide.\n"
			)
		)

		(set #item-local-help
			(cat
		                "    Tīumaczenia: Jeōli chcesz by MultiView i FileID.library mogīy "
		                "byź z polskimi komunikatami musisz zainstalowaź odpowiednie katalogi.\n\n"
			)
		)

		(set #parts-footer-help
			(cat
		                "    Dodatkowe informacje znajdziesz w dokumentacji.\n"
			)
		)

		; Only for expert users
		(set #where-program "Gdzie chcesz zainstalowaź gīówny program?")
		(set #where-program-help
			(cat
		                "    MultiView: Ten program jest zamiennikiem dla starego MultiView-a napisanego "
		                "jeszcze przez ludzi z Commodore. Powinieneō zainstalowaź go w katalogu SYS:Utilities.\n"
			)
		)

		(set #where-library "Gdzie chcesz zainstalowaź FileID.library?")
		(set #where-library-help
			(cat
			"    FileID.library jest zwykīā bibliotekā. MultiView "
	                "i inne programy spodziewajā siė, ūe znajdā jā w Libs:, tak wiėc "
	                "musisz jā zainstalowaź do katalogu bėdācego czėōciā twej kolekcji bibliotek.\n"
			)
		)

		(set #where-guide "Gdzie chcesz zainstalowaź MultiView.guide?")
		(set #where-guide-help
			(cat
				"    MultiView.guide jest plikiem w standardzie AmigaGuide. "
		                "Proponowanym miejscem jest HELP:\n"
			)
		)

		(set #copy-guide-icon "Czy chcesz zainstalowaź ikonė dla MultiView.guide?")
		(set #which-language "Które jėzyki powinny byź zainstalowane ?")
		(set #copy "Kopiujė %s do %s...")
	)
)

;**************************************************************************
;
; The actual installation script
;
; First some initializations
;

; Check Kickstart version. Exit if not at least 2.04
(if (< (/ (getversion) 65536) 37)
        (abort #bad-kick)
)

; Since files are scatter installed, don't mention any specific location.
(set @default-dest "")

; Request proportinal fonts, if supported. This string is
; prepended to the first askoptions choice.
(if (>= @installer-version 2752518)     ; 42 * 65536 + 6
	; At least version 42.6
	(set #propfont "[2p")
	; Pre V42
	(set #propfont "")
)

(set #item-num-lib       1)
(set #item-num-prog      2)
(set #item-num-guide     4)
(set #item-num-locale    8)

; Find out default values for parts to install
(set #install-default (BITOR #item-num-prog #item-num-lib #item-num-guide))

; Locale installed?
(if (AND (= 2 (exists "Locale:" (noreq))) (< 0 (getversion "locale.library" (resident))))
	(set #install-default (BITOR #install-default #item-num-locale))
)

; Everything ready

(welcome)

; Ask the user what to install
(set #install-files
	(askoptions
		(prompt	#install-parts)
		(help	#parts-header-help
                        #item-program-help
			#item-library-help
			#item-guide-help
			#item-local-help
			#parts-footer-help "\n"
			@askoptions-help)
		(choices
			(cat #propfont #item-program)
                        #item-library
			#item-guide
			#item-locale
		)
		(default #install-default)
	)
)

; Ask the user for the location of all parts

(set #program-dest  "SYS:Utilities")

; Location for MultiView program (for experts)
(if (AND (= @user-level 2) (BITAND #install-files #item-num-prog))
	(set #program-dest
		(askdir
			(prompt  #where-program)
			(help    #where-program-help "\n" @askdir-help)
			(default #program-dest)
		)
	)
)

(set #library-dest  "Libs:")

; Location for FileID.library (for experts)
(if (AND (= @user-level 2) (BITAND #install-files #item-num-lib))
	(set #library-dest
		(askdir
			(prompt  #where-library)
			(help    #where-library-help "\n" @askdir-help)
			(default #library-dest)
		)
	)
)

; Location for MultiView.guide
(if (BITAND #install-files #item-num-guide)
	(
		(set #guide-dest "Work:")

		(if (exists "Help:")
			(set #guide-dest "Help:")
		)

		(set #guide-dest
			(askdir
				(prompt  #where-guide)
				(help    #where-guide-help "\n" @askdir-help)
				(default #guide-dest)
			)
		)

		(set #dest-guide-name (tackon #guide-dest "MultiView.guide.info"))

		(set #guide-icon
			(if (AND (= @user-level 2 ) (= (exists #dest-guide-name) 0))
				(askbool
					(prompt #copy-guide-icon)
					(help	#copy-guide-icon-help " ")
				)
				0	; Default is to not copy the icon
			)
		)
	)
)

; .ct
; Which languages should be installed?
(if (BITAND #install-files #item-num-locale)
	(set #lang
		(askoptions
			(prompt	#which-language)
			(help	#which-language-help "\n" @askoptions-help)
			(choices
				(cat #propfont "Deutsch")
				(cat "English  " #builtin-lang)
				"Polski"
			)
			(default #default-lang)
		)
	)
)

; Everything set up. Now do the actual installation

(complete 10)

(if (BITAND #install-files #item-num-prog)
	(
		(copyfiles
			(prompt	(#copy "MultiView" #program-dest))
			(source	"MultiView")
			(dest	#program-dest)
		)
		(copyfiles
			(prompt	(#copy "MultiView" #program-dest))
			(source	"MultiView.info")
			(dest	#program-dest)
		)
	)
)

(complete 30)

(if (BITAND #install-files #item-num-lib)
	(
		(copylib
			(prompt	(#copy "FileID.library" #library-dest))
			(source	"libs/FileID.library")
			(dest	#library-dest)
		)
	)
)

(complete 50)

(if (BITAND #install-files #item-num-guide)
	(
		(set #guide-source
                        (tackon (tackon "Docs/" @language) "MultiView.guide")
                )
        	(copyfiles
			(prompt (#copy "MultiView.guide" #guide-dest))
			(source #guide-source)
			(dest   #guide-dest)
		)

		(if #guide-icon
			(
				(copyfiles
					(prompt (#copy "MultiView.guide.info" #guide-dest))
					(source (tackon (tackon "Docs/" @language) "MultiView.guide.info"))
					(dest   #guide-dest)
				)
			)
		)
	)
)

(complete 70)

; .ct
(if (BITAND #install-files #item-num-locale)
	(
		(set #n 0)

		(while
			(set #language
				(select #n
					"Deutsch"
					"English"
					"Polski"
					""
				)
			)

			(
				(if (AND (IN #lang #n) (<> #language "English"))
					(
						(set #catalog
							(tackon "Catalogs"
								(tackon #language "MultiView.catalog")
							)
						)

						(set #destination (tackon "Locale:Catalogs/" #language))

						(if (exists #catalog)
							(copylib
								(prompt (#copy #catalog #destination))
								(source #catalog)
								(dest   #destination)
							)
						)

						(set #catalog
							(tackon "Catalogs"
								(tackon #language "FileID_lib.catalog")
							)
						)

						(if (exists #catalog)
							(copylib
								(prompt (#copy #catalog #destination))
								(source #catalog)
								(dest   #destination)
							)
						)

					)
				)

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

(complete 100)

(exit)
