;EasyPatch Installation Script
;$VER: EasyInstall 1.31

(set iver (/ @installer-version 65536))
(set irev (- @installer-version (* ver 65536)))


(set #ver "1.40")
(set #nver "140")

(set #vc 0)


;/// ***** Voice strings

;(set #Voice         "-s180 Welcome to EasyPatch. Prepare your requesters to be destroyed!")
(set #Voice         "-s180 EasyPatch is coming back. Back for the future!")
(set #Voice_End		"-s180 EasyPatch has been succesfuly installed.")
(set #Voice_Upgrade	"-s180 Upgrading to ")


;/// ***** English

(set #Welcome		"Welcome to EasyPatch %s\nPrepare your requesters to be destroyed!\n\n(( Dolby Surround where available ))\nTurn on your speakers!")
(set #wrongOS  		"EasyPatch needs at least OS2.04 to run\n")
(set #EasyPatchDir  "Where I should install EasyPatch and his support utilities?\n(A directory will be created)\n")
(set #EasyUtilDir   "Where I should install the\nsupport utilities?\n")
(set #GuideDir   	"Where I should install the\nAmigaGuide documentation?\n")
(set #CpuChoice 	"Please, select your processor!\n")
(set #CreateCpu 	"Creating 68%s version of EasyPatch")
(set #Wait 			"Please wait\n")
(set #Done 			"\nEasyPatch has been succesfuly installed in\n %s.\n\n")
(set #Aminet        "You are going to install the Aminet version of EasyPatch.\nYou can obtain the full version on EasyPatch homepage.")
(set #BootUp		"Should be EasyPatch automatically runned at bootup?")
(set #GuideFile     "English.guide")
(set #OldInstaller  "You have an outdated version of the Installer.\nPlease get the latest from Aminet or EasyPatch might not be\ninstalled succesfully.")

;/// ***** Italiano

(IF (= @language "italiano")
(

(set #Welcome		"Benvenuto in EasyPatch %s\nPrepara i tuoi requesters ad essere distrutti!")
(set #wrongOS  		"EasyPatch necessita del Sistema Operativo 2.04\n per funzionare.\n")
(set #EasyPatchDir  "Dove devo installare EasyPatch e le sue utility di supporto?\n (Una directory verra' creata)\n")
(set #EasyUtilDir   "Dove devo installare le utility\ndi supporto?\n")
(set #GuideDir   	"Dove devo installare la \ndocumentazione AmigaGuide?\n\n")
(set #CpuChoice 	"Seleziona il tuo processore\n")
(set #CreateCpu 	"Creo l'eseguibile di EasyPatch\n ottimizzato per 68%s")
(set #Wait 			"Attendere prego :->\n")
(set #Done 			"\nEasyPatch è stato installato con successo in\n %s.\n\n")
(set #Aminet        "Stai per installare la versione Aminet di EasyPatch.\nPotrai trovare la versione completa sulla homepage di EasyPatch.")
(set #BootUp		"Devo caricare EasyPatch automaticamente al bootup?")
(set #OldInstaller  "Hai una versione vecchia dell'Installer.\nPrendi la nuova da Aminet, o EasyPatch potrebbe\nnon essere installato con successo.\n")
)
)

;/// ***** Svenska

(IF (= @language "svenska")
(
(set #Welcome		"EasyPatch %s\nBered dig på kuvade requestrar!")
(set #wrongOS  		"EasyPatch kräver OS2.04+\n")
(set #EasyPatchDir  "Ange sökväg till EasyPatch och dess stödprogram?\n(Ett bibliotek kommer att skapas.)\n")
(set #EasyUtilDir   "Var skall stödprogrammen\ninstalleras?\n")
(set #GuideDir   	"Var skall \nGuiden installeras?\n")
(set #CpuChoice 	"Specificera din processor!\n")
(set #CreateCpu 	"Skapar en 68%s-version av EasyPatch")
(set #Wait 			"Var god vänta.\n")
(set #Done 			"\nEasyPatch installerat i\n %s.\n\n")
(set #Aminet        "Du är i färd med att installera Aminet-versionen av EasyPatch.\nDu kan erhålla den kompletta versionen på EasyPatchs hemsida.")
(set #BootUp		"Skall EasyPatch köras vid systemstart?")
(set #GuideFile     "Svenska.guide")
(set #OldInstaller  "Du har en föråldrad version av Installer.\nSkaffaden senaste versionen från Aminet för att kunna installera\nEasyPatch på ett tillfredsställande sätt.")
)
)

;----------------------------------------------------------------------------

;/// Checking environment
(set OS_ver (getversion "exec.library" (resident)))
(if (< OS_ver (* 37 65536)) (abort #wrongOS))


;----------------------------------------------------------------------------


(complete 0)

(debug "EasyInstall")
(debug ("Language: %s" @language))

(if (exists("SYS:Utilities/Say"))
(
	(run (cat "Run <>NIL: SYS:Utilities/Say " #Voice))
	(set #vc 1)
)
)

(message (#Welcome #ver))


(if(exists("/AMINET-VERSION.txt"))
(
	(message #Aminet)
	(set #nver (cat #nver "a"))
)
)


(if (< iver 43)
(
	(message #OldInstaller)
)
)

(if (AND (= iver 43) (< irev 3))
(
	(message #OldInstaller)
)
)

(complete 1)

(set #EasyPatchDir
    (askdir
    	(prompt #EasyPatchDir)
		(newpath)
        (default @default-dest)
		(help @askdir-help)
    )
)


(set #EasyIcon #EasyPatchDir)
(set #EasyPatchDir (tackon #EasyPatchDir "EasyPatch"))


(complete 10)


(set #opt 
	(askbool
		(prompt #BootUp)
		(default 1)
		(help @askoptions-help)
	)
)


(set #EasyGuideDir (tackon #EasyPatchDir "Docs"))


(complete 20)


(debug "Destination dir      : " #EasyPatchDir)
(debug "Destination guide dir: " #EasyGuideDir)


(complete 25)


(set #defcpu 

	(database "cpu")
)

(set #cpun
	(substr #defcpu 3 1)
)


(if (= #cpun 0)

	(set #cpud 0)
)

(if (= #cpun 1)

	(set #cpud 0)
)

(if (= #cpun 2)

	(set #cpud 1)
)

(if (= #cpun 3)

	(set #cpud 2)
)

(if (= #cpun 4)

	(set #cpud 3)
)

(if (= #cpun 6)

	(set #cpud 4)
)

(complete 30)



(set #CPU
        (askchoice 
                (prompt #CpuChoice)
                (choices "68000" "68020" "68030" "68040" "68060")
                (default #cpud)
				(help @askchoice-help)

        )
)

(complete 40)


(set #cpus (select #CPU "68000" "68020" "68030" "68040" "68060"))

(debug "Processor            : " #cpus)


(set #cpup 
	(substr #cpus 2 3
	)
)

(complete 50)



(if (= #opt 1)
(
	(set #EasyBoot "SYS:WBStartup")

	(complete 55)

	;WBStartup+ Support

	(if (AND (>= iver 42) (>= irev 12))
	(
		(if(exists("SYS:WBStartup/WBStartup+"))
		(
			(iconinfo
				(prompt #Wait)
				(dest "SYS:WBStartup/WBStartup+")
				(gettooltype "ENABLEDPATH" "#EasyBoot")
			)
			(debug "Destination of EasyPatch: " #EasyBoot)
		)
		)
	)
	)

	(complete 60)

	(if(not(exists (tackon #EasyBoot "EasyPatch.info")))
	(
		(copyfiles
		    (prompt #Wait)
		    (source "/EasyPatch.info")
		    (dest   #EasyBoot)
		)	
	)
	)

	(complete 65)


	(copyfiles
	    (prompt #Wait)
	    (source "/EasyPatch")
	    (dest   #EasyBoot)
		
	)	

	(set #ins #EasyBoot)
)
;else
(
	(if(not(exists (tackon #EasyPatchDir "EasyPatch.info")))
	(
		(copyfiles
		    (prompt #Wait)
		    (source "/EasyPatch.info")
		    (dest   #EasyPatchDir)
			
		)	
	)
	)

	(complete 55)


	(copyfiles
	    (prompt #Wait)
	    (source "/EasyPatch")
	    (dest   #EasyPatchDir)
		
	)	

	(set #ins #EasyPatchDir)

	(complete 60)

)
)


(complete 70)


(if (<> #cpup "000")
(
	(if (= #vc 1)
		(run (cat "Run <>NIL: SYS:Utilities/Say " (cat #Voice_Upgrade " " #cpus ".")))
	)

	(working (#CreateCpu #cpup))

	(run ("spatch -oT:EasyPatch%s -p/Pch/EP%s.pch /EasyPatch" #cpup #cpup))

	(complete 75)

	(copyfiles
	    (prompt #Wait)
    	(source ("T:EasyPatch%s" #cpup))
		(newname "EasyPatch")
    	(dest   #ins)
	)

	(delete ("T:EasyPatch%s" #cpup))
)
)



(complete 80)


(copyfiles
    (prompt #Wait)
	(source (cat "//EasyPatch" #nver ".info"))
	(newname "EasyPatch.info")
    (dest   #EasyIcon)
	
)


(copyfiles
    (prompt #Wait)
	(source "/EasyList")
	(infos)
    (dest   #EasyPatchDir)
	
)

(complete 83)

(copyfiles
    (prompt #Wait)
	(source "/EasyStat")
	(infos)
    (dest   #EasyPatchDir)
	
)

(complete 86)

(copyfiles
    (prompt #Wait)
	(source "/Configuration/EasyConfig")
    (dest   #EasyPatchDir)
	
)

(complete 89)

(copyfiles
    (prompt #Wait)
	(source "/Configuration/Config")
    (dest   #EasyPatchDir)
	
)

(complete 92)

(copyfiles
    (prompt #Wait)
	(source (cat "/Configuration/" @language ".info"))
	(newname "EasyConfig.info")
    (dest   #EasyPatchDir)
	
)

(tooltype 
	(prompt #Wait)
	(dest "/EasyConfig")
	(noposition)
)

(complete 95)


(copyfiles
    (prompt #Wait)
	(source (cat "/Docs/" #GuideFile))
    (newname "EasyPatch.guide")
    (dest   #EasyGuideDir)
	
)

(copyfiles
    (prompt #Wait)
	(source (cat (cat "/Docs/" #GuideFile) ".info"))
    (newname "EasyPatch.guide.info")
    (dest   #EasyGuideDir)
	
)

(copyfiles                   
    (prompt 	#Wait)           
	(source	 	"/Docs")     
	(pattern 	"~(#?.guide)")                
	(dest   	#EasyGuideDir)   
	(infos)              
)                            
                             

(copyfiles
    (prompt #Wait)
	(source "/Docs.info")
    (dest   #EasyPatchDir)
	
)


(if (= #vc 1)
	(run (cat "Run <>NIL: SYS:Utilities/Say " #Voice_End))
)

(run "AmigaGuide /Docs/EasyPatch.guide")

(complete 100)

(set @default-dest #EasyPatchDir)

(exit)


