; Install Directory Opus 4
; $VER: Install-Directory Opus 4 V1.0 (2.1.2001)

(set #catalog 0) ; english language is default

; Find the current language
(set #i 0)
(while (set #thisfile (select #i
		"english" "italiano" "deutsch" "español" "czech" "català" "dansk" "français"
		"hrvatski" "nederlands" "norsk" "polski" "português"
		"russian" "srpski" "suomi" "svenska" "ÃeÓtina"
		""))
	(
		(if (= @language #thisfile)
			(
				(set #catalog #i)
				(set #catalogname #thisfile)
			)
		)
		(set #i (+ #i 1))
	)
)

(set #catalog "English")
; Query user for their language, using system as default
;(set #catalog
;	(askchoice
;		(prompt "Select your native language (language for installer)")
;		(help @askoptions-help)
;		(choices "English" "Italiano" "Deutsch" "Español" "Czech")
;		(default #catalog)
;	)
;)

; Reset #catalogname as the user may have changed the language above
(if (< #catalog 5)
	(
		(set #catalogname (select #catalog "english" "italiano" "deutsch" "español" "czech"))
	)
)

; Some string defaults common for all languages
(set #DOPUS4 "Directory Opus 4")
(set #HOMEPAGE "http://viper.pl/~opus")
(set #BLANK "\n")


; ************************** English texts ******************************
(set #WRONG_INSTALLER_VERSION (cat "\n\n\n\nYou need at least version 42.9 of Installer\nto install " #DOPUS4))
(set #WRONG_CPU (cat "\n\n\n\nYou need a 68020 CPU or better\nto use " #DOPUS4))
(set #WRONG_OS_VERSION (cat "\n\n\n\nYou need at least AmigaOS V3.0\nto use " #DOPUS4))
(set #INSTALLING "\nInstalling")
(set #PROMPT_INSTALL_DOCS (cat "\nInstall " #DOPUS4 " documentation?"))
(set #INSTALLING_DOCS (cat "\nInstalling " #DOPUS4 " documentation"))
(set #PROMPT_INSTALL_CATALOG "\nInstall which language catalogs and help files")
(set #INSTALLING_CATALOG "\nInstalling catalogs and help files")
(set #UPDATES_AVAILABLE (cat "\nYou can obtain updates and other information\nabout " #DOPUS4 " from the homepage\n\n" #HOMEPAGE))
(set #YES "Yes")
(set #NO "No")


; ************************* Global procedures ***************************
(procedure P_copylib lib destpath newlibname
	(
		(copylib
			(prompt (cat (cat #INSTALLING " ") (fileonly newlibname)))
			(help @copylib-help)
			(newname newlibname)
			(source lib)
			(dest destpath)
			(confirm)
			(optional askuser force)
		)
	)
)


; *********************** Directory Opus 4 install

(if (< @installer-version (+ (* 65536 42) 9))
	(abort #WRONG_INSTALLER_VERSION)
)

(if (< (database "cpu") 68020 )
	(abort #WRONG_CPU)
)

(set os_version (/ (getversion "exec.library" (resident)) 65536))
(if (< os_version 39)
	(abort #WRONG_OS_VERSION)
)

(complete 0)


; *********************** Sort out what the user has where

; Establish CPU type

(set #ourcpu (database "cpu"))

(if (= #ourcpu "68020") (set #ourcpu 0))
(if (= #ourcpu "68030") (set #ourcpu 0))
(if (= #ourcpu "68040") (set #ourcpu 2))
(if (= #ourcpu "68060") (set #ourcpu 4))

(complete 0)


; *********************** Install Directory Opus 4

;(if (= @user-level 2) ;If expert user, ask directory
	(
		(set @default-dest
			(askdir
				(prompt #SELECT_INSTALL_DIRECTORY)
				(help @askdir-help)
				(default @default-dest)
			)
		)
	)
;)

(P_copylib "Libs/dopus.library" "Libs:" "dopus.library")

(complete 25)

(copyfiles
	(source "c/DOpusRT")
  (help @copyfiles-help)
	(dest "c:")
)

(complete 50)

(copyfiles
	(source "modules")
	(help @copyfiles-help)
	(dest (tackon @default-dest "Modules"))
	(files)
	(infos)
	(all)
)

(complete 60)

(copyfiles
	(source "DirectoryOpus")
  (help @copyfiles-help)
	(dest @default-dest)
)

(copyfiles
	(source "")
	(choices "DirectoryOpus" "DirectoryOpus.info")
  (help @copyfiles-help)
	(dest @default-dest)
)

(complete 75)

(copyfiles
	(prompt #INSTALLING_DOCS)
	(choices "DOpus4.guide" "DOpus4.guide.info" "DOpus4_ARexx.guide" "DOpus4_ARexx.guide.info")
	(source "Documentation/English")
	(help @copyfiles-help)
	(dest @default-dest)
	(files)
	(noposition)
	(optional askuser)
	(confirm "average")
)

; *********************** Install locale catalog

(set #localedest "S:")

(if (<> #catalog 0)
	(
		(set #localesrc 1) ; Defaults to first entry
		(set #i 0)
		(while (set #thiscat (select #i "english" "deutsch" ""))
			(
				(if (= #catalogname #thiscat)
					(
						(set #x #i)
						(while (> #x 0)
							(set #localesrc (* #localesrc 2))

							(set #x (- #x 1))
						)
					)
				)

				(set #i (+ #i 1))
			)
		)
	)
	(
		(set #localesrc 0)
	)
)

(set #installcat
	(askoptions
		(prompt #PROMPT_INSTALL_CATALOG)
		(choices "English" "Deutsch")
		(default #localesrc)
		(help @askoptions-help)
	)
)

(set #i 0)
(while (< #i 5)
	(set #x #i)
	(set #y 1)

	(while (> #x 0)
		(set #y (* #y 2))

		(set #x (- #x 1))
	)

	(if (bitand #installcat #y)
		(
			(set #localecat (select #i "English" "Deutsch"))

			(copyfiles
				(prompt #INSTALLING_CATALOG)
				(help @copyfiles-help)
				(source (tackon "S" #localecat))
				(all)
				(dest "T:")
;				(confirm)
				(optional askuser)
				(files)
			)
		)
	)

	(set #i (+ #i 1))
)

(complete 100)

; *********************** Finished installation

(message #UPDATES_AVAILABLE )
