; Install PhotoFolio
; $VER: Install-PhotoFolio V1.0 (2.3.99)
; © 1999 Steve Quartly and Paul Huxham

(set #catalog 1) ; english language is default

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

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

; Some string defaults common for all languages
(set #HOMEPAGE "http://mafeking.scouts.org.au/~paulh/photofolio.html")
(set #BLANK "\n")

; ************************** English texts ******************************
(set #INITIAL_MESSAGE
  (cat "\nWelcome to the PhotoFolio installer\n\n\n"
	"You can obtain free updates to PhotoFolio\n"
	"at the PhotoFolio homepage\n\n"
	#HOMEPAGE
	"\n\n\nThe authors, Steve Quartly and Paul Huxham\n"
	"would like to thank you for using PhotoFolio")
)
(set #WRONG_INSTALLER_VERSION "\n\n\n\nYou need at least version 42.9 of Installer\nto install PhotoFolio")
(set #WRONG_OS_VERSION "\n\n\n\nYou need AmigaOS V3.0\nto run PhotoFolio")
(set #WRONG_MUI_VERSION "\n\n\n\nYou need MUI 3.8\nto run PhotoFolio")
(set #WRONG_LISTTREE_VERSION "\n\n\n\nYou need Listtree.mcc 17.53\nto run PhotoFolio")
(set #WRONG_NLIST_VERSION "\n\n\n\nYou need NList.mcc 19.90\nto run PhotoFolio")
(set #WRONG_NLISTVIEW_VERSION "\n\n\n\nYou need NListview.mcc 19.90\nto run PhotoFolio")
(set #YOU_NEED_GUIGFX "\n\nTo run PhotoFolio on an ECS, AGA or other non-CyberGraphX system,\n\nyou need to obtain render.library and guigfx.library from Aminet\n\nand install them before running PhotoFolio")
(set #CONTINUE_INSTALLATION "Continue PhotoFolio installation")
(set #STOP_INSTALLATION "Don't install PhotoFolio now")
(set #SELECT_INSTALL_DIRECTORY "Select a directory to install PhotoFolio into.\n(If you want PhotoFolio in its own directory - create one now)")
(set #INSTALLING_PROGRAM "\n\n\n\nInstalling PhotoFolio program")
(set #PROMPT_SET_TOOLTYPE "\n\n\nSet PhotoFolio graphics mode tooltype?\n(guigfx or cybergraphics, determined automatically)")
(set #PROMPT_INSTALL_DOCS "\n\n\n\nInstall PhotoFolio documentation?\n\n(Amigaguide)")
(set #INSTALLING_DOCS "\n\n\n\nInstalling PhotoFolio documentation")
(set #BETTER_PROCESSOR "\n\n\nYou should obtain versions of jpeg.library and proof.library\n\noptimised for your CPU from\n\n")
(set #INSTALL_68020_VERSIONS "Versions for the 68020 CPU will now be installed")
(set #INSTALLING_LIBRARIES "Installing required PhotoFolio libraries\n\n")
(set #PROMPT_SET_PREFS "\n\n\n\nSet up proof.library preferences in ENVARC: and ENV:?")
(set #UPDATES_AVAILABLE "\n\nUpdates of PhotoFolio and its required libraries\n\nare available from the PhotoFolio home page")
(set #YES "Yes")
(set #NO "No")
(set #WHICH_LANGUAGES  "\n\n\n\nWhat language catalogs would you like to install?")

; ************************** Italian texts ******************************
(if (= #catalog 2)
(
	(set #INITIAL_MESSAGE
	  (cat "\nBenvenuto all'installazione di PhotoFolio\n\n\n"
  	 "Puoi ottenere gli aggiornamenti gratuiti di PhotoFolio\n"
	   "alla homepage di PhotoFolio\n\n"
  	 #HOMEPAGE
	   "\n\n\nGli autori, Steve Quartly e Paul Huxham\n"
  	 "desiderano ringraziarti per aver scelto PhotoFolio")
	)
	(set #WRONG_INSTALLER_VERSION "\n\n\n\nNecessiti almeno della versione 42.9 dell'Installer\nper installare PhotoFolio")
	(set #WRONG_OS_VERSION "\n\n\n\nNecessiti di AmigaOS 3.x\nper lanciare PhotoFolio")
	(set #WRONG_MUI_VERSION "\n\n\n\nNecessiti di  MUI 3.8\nper lanciare PhotoFolio")
	(set #WRONG_LISTTREE_VERSION "\n\n\n\nNecessiti di Listtree.mcc 17.53\nper lanciare PhotoFolio")
	(set #WRONG_NLIST_VERSION "\n\n\n\nNecessiti di NList.mcc 19.90\nper lanciare PhotoFolio")
	(set #WRONG_NLISTVIEW_VERSION "\n\n\n\nNecessiti di NListview.mcc 19.90\nper lanciare PhotoFolio")
	(set #YOU_NEED_GUIGFX "\n\nPer lanciare PhotoFolio su un sistema ECS, AGA o un altro non CyberGraphX,\n\nhai bisogno delle render.library e guigfx.library da Aminet\n\ne devi installarle prima di lanciare PhotoFolio")
	(set #CONTINUE_INSTALLATION "Continua l'installazione di PhotoFolio")
	(set #STOP_INSTALLATION "Non installare ora PhotoFolio")
	(set #SELECT_INSTALL_DIRECTORY "Scegli un cassetto in cui installare PhotoFolio.\n(Se vuoi PhotoFolio in un suo cassetto - creane uno adesso)")
	(set #INSTALLING_PROGRAM "\n\n\n\nInstallazione del programma PhotoFolio")
	(set #PROMPT_SET_TOOLTYPE "\n\n\nImposto la modalità grafica di PhotoFolio via tooltype?\n(guigfx o cybergraphics, determinato automaticamente)")
	(set #PROMPT_INSTALL_DOCS "\n\n\n\nInstallo la documentazione di  PhotoFolio?\n\n(Amigaguide)")
	(set #INSTALLING_DOCS "\n\n\n\nInstallazione della documentazione di PhotoFolio")
	(set #BETTER_PROCESSOR "\n\n\nPuoi ottenere versioni ottimizzate della jpeg.library\n\ne proof.library per la tua CPU da\n\n")
	(set #INSTALL_68020_VERSIONS "Ora verranno installate le versioni per la CPU 68020")
	(set #INSTALLING_LIBRARIES "Installazione delle librerie richieste da PhotoFolio\n\n")
	(set #PROMPT_SET_PREFS "\n\n\n\nImposto le preferenze per la proof.library in ENVARC: e ENV:?")
	(set #UPDATES_AVAILABLE "\n\nAggiornamenti di PhotoFolio e delle sue librerie\n\nsono disponibili alla homepage di PhotoFolio")
	(set #YES "Sì")
	(set #NO "No")
	(set #WHICH_LANGUAGES  "\n\n\n\nPer quale lingua vuoi installare i cataloghi?")
)
)

; ************************* Global procedures ***************************
(procedure P_copylib lib path
  (
    (set #libr (cat lib ".library"))
    (copylib (prompt (cat #INSTALLING_LIBRARIES #libr))
      (help @copylib-help)
      (source (cat path #libr))
      (dest "LIBS:")
      (confirm expert)
    )
  )
)

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

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

(set mui_version (getversion "MUI:Libs/muimaster.library" ))
(if (AND (< mui_version 1245219) (<> mui_version 0 ))
	(abort #WRONG_MUI_VERSION)
)

(set listtree_version (getversion "MUI:Libs/mui/Listtree.mcc" ))
(if (AND (< listtree_version 1114165) (<> listtree_version 0 ))
	(abort #WRONG_LISTTREE_VERSION)
)

(set nlist_version (getversion "MUI:Libs/mui/NList.mcc" ))
(if (AND (< nlist_version 1245246) (<> nlist_version 0 ))
	(abort #WRONG_NLIST_VERSION)
)

(set nlistview_version (getversion "MUI:Libs/mui/NListview.mcc" ))
(if (AND (< nlistview_version 1245246) (<> nlistview_version 0 ))
	(abort #WRONG_NLISTVIEW_VERSION)
)

; All essential version numbers are correct, continue installation
(message #INITIAL_MESSAGE)

(set cgfx_version (/ (getversion "cybergraphics.library" (resident)) 65536))
(if (= cgfx_version "")
	(
		(set continue
			(askbool
				(prompt #YOU_NEED_GUIGFX)
				(help @askbool-help)
				(choices #STOP_INSTALLATION #CONTINUE_INSTALLATION)
				(default 1)
			)
		)

		(if (= continue 1)
			(exit (quiet))
		)

		(set ttv_guigfx "YES")
	)
	(
		(set ttv_guigfx "NO")
	)
)

; Set destination directory for install
(set destination
	(askdir
		(prompt #SELECT_INSTALL_DIRECTORY)
		(help @askdir-help)
		(default @default-dest)
	)
)

(set @default-dest destination)

; Install executable and icon
(copyfiles
	(prompt #INSTALLING_PROGRAM)
	(source "")
	(choices "PhotoFolio" "PhotoFolio.info")
	(dest @default-dest)
	(files)
	(optional askuser)
)

; Set the tooltypes
(tooltype
	(prompt #PROMPT_SET_TOOLTYPE)
	(help @tooltype-help)
	(dest (tackon @default-dest "PhotoFolio"))
	(settooltype "GUIGFX" ttv_guigfx)
	(noposition)
)

; Install documentation
(set install_docs
	(askbool
		(prompt #PROMPT_INSTALL_DOCS)
		(help @askbool-help)
		(choices #YES #NO)
		(default 1)
	)
)

(if (= install_docs 1)
	(copyfiles
		(prompt #INSTALLING_DOCS)
		(source "")
		(choices "PhotoFolio.guide" "PhotoFolio.guide.info")
		(dest @default-dest)
		(files)
		(optional askuser)
	)
)

; Remind user of beeter libraries for their cpu
(if (> (database "cpu") 68020 )
	(message (cat #BETTER_PROCESSOR #HOMEPAGE #BLANK #BLANK #BLANK #INSTALL_68020_VERSIONS))
)

; Install required libraries
(set #i 0)
(while (set #thislib (select #i "proof" "image" "jpeg" ""))
	(
		(if (<> #thislib "")
			(P_copylib #thislib "Libs/")
		)
		(set #i (+ #i 1))
	)
)

; Set up prefs in envarc
(if (not (exists "ENVARC:proof.library"))
	(makedir "ENVARC:proof.library")
)

(textfile
	(prompt #PROMPT_SET_PREFS)
	(help @textfile-help)
	(dest "ENVARC:proof.library/Test_Proof_By_Protection")
	(append "no\n")
)

; Set up prefs in env
(if (not (exists "ENV:proof.library"))
	(makedir "ENV:proof.library")
)

(textfile
	(prompt #PROMPT_SET_PREFS)
	(help @textfile-help)
	(dest "ENV:proof.library/Test_Proof_By_Protection")
	(append "no\n")
)

; Finished installation
(message (cat #UPDATES_AVAILABLE #BLANK #BLANK #HOMEPAGE))
