;======================================================================
;
; BattleDuel Install Script $VER: Install 1.5.42 (2.8.96)
;
; Copyright © 1995-1996 Jochen Terstiege
;
;======================================================================
;
;======================================================================
; language strings
;======================================================================

(if (= @language "deutsch")
	(
		(set #hello "\nWillkommen zur BattleDuel Installation\nund Update\n\n\Version 1.5.42")
		(set #update (cat "Sie haben BattleDuel auf ihrem System schon installiert. "
								"Alle alten Dateien werden gelöscht und die neuen werden installiert."))
		(set #select_destination "Bitte wählen Sie aus, wo das BattleDuel-Verzeichnis erzeugt werden soll")
		(set #destination_help (cat "Wählen Sie eine Partition oder ein Verzeichnis aus. "
											"Ein Verzeichnis mit dem Namen 'BattleDuel' wird dort erzeugt."))
		(set #install_to1 "\nBattleDuel nach \"")
		(set #install_to2 "\" installieren?")
		(set #startup "Ergänze user-startup")
		(set #startup_help "Dieser Assign wird von BattleDuel gebraucht")
		(set #have_fun "Viel Spaß mit BattleDuel...")
		(set #which_chipset "Welchen Chipsatz haben Sie?")
		(set #chipset_help (cat "Wenn Sie einen Amiga 4000, A1200 oder eine Grafikkarte "
										"besitzen, dann müssen Sie AGA wählen, ansonsten ECS!"))
		(set #want_mwb_icons "Wollen Sie MagicWB Icons installieren?")
		(set #mwb_icons (cat "MagicWB ist ein Set von Icons mit 8 Farben.\n"
									"MagicWB ist © by Martin Huttenloher"))
		(set #error_extract (cat "Fehler beim Entpacken der Datei: "))
	)
	(
		(set #hello "\nWelcome to the BattleDuel Installation\nand update\n\n\Version 1.5.42")
		(set #update (cat "You already have BattleDuel installed on your system. "
								"All old files will be deleted and the new ones installed."))
		(set #select_destination "Select the location to install the BattleDuel directory")
		(set #destination_help (cat "Choose a destination partition or directory. "
											"A directory called 'BattleDuel' will be created there."))
		(set #install_to1 "\nInstall BattleDuel to \"")
		(set #install_to2 "\" ?")
		(set #startup "Adding assign to user-startup")
		(set #startup_help "This assign is needed by BattleDuel!")
		(set #have_fun "Have fun with BattleDuel...")
		(set #which_chipset "Which Chipset do you have?")
		(set #chipset_help (cat "If you own an Amiga 4000, A1200 or a graphicboard then "
										"you must select AGA, otherwise you must select ECS!"))
		(set #want_mwb_icons "Do you want to install MagicWB icons?")
		(set #mwb_icons (cat "MagicWB is a set of nice icons with 8 colors.\n"
									"MagicWB is © by Martin Huttenloher"))
		(set #error_extract (cat "Error while extracting from file: "))
	)
)

;======================================================================
; variables
;======================================================================

(set inputdir	(pathonly @icon))		; from where we were started
(set bd_drawer "BattleDuel")			; destination drawer name
(set bd_dest	(getassign "BD"))		; default destination

;======================================================================
; welcome
;======================================================================

(message #hello)

;======================================================================
; already there?
;======================================================================

(if (<> bd_dest "")
	(; update
		(set update true)
		(message #update)
	)
	(; first installation
		(set update false)
		(set bd_dest
			(askdir
				(prompt #select_destination)
				(default "Work:")
				(help #destination_help)
			)
		)
	)
)
(set @default-dest bd_dest)

;======================================================================
; delete old files
;======================================================================

;(if (= update true)
;	(
;		(set del_pattern "#?")
;		(foreach bd_dest del_pattern
;			(delete (tackon bd_dest @each-name))
;		)
;	)
;)

;======================================================================
; make directory
;======================================================================

(if (= update false)
	(
		(set bd_dest (tackon bd_dest bd_drawer))
		(message (cat #install_to1 bd_dest #install_to2))
		(makedir bd_dest (infos))
		(makeassign "BD" bd_dest)
	)
)

;======================================================================
; ask for chipset
;======================================================================

(set aga
	(askbool
		(prompt #which_chipset)
		(help #chipset_help)
		(choices "ECS" "AGA/Graphicboard")
		(default 1)
	)
)

;======================================================================
; extract files
;======================================================================

(procedure extract
	(set lha (cat "decrunch -a -m -q x \"" (tackon inputdir current) ".lha\" * " dir_dest))
	(working "Installing " current)
	(if (<> (run lha) 0)
		(message #error_extract current)
	)
) 

;======================================================================
; patch landscapes with balloon (registered v1.03 and v1.4.80)
;======================================================================

(if (and (= update true)
			(	(or (exists ("BD:BattleDuel.key"))
				(exists ("devs:BattleDuel.key"))
				(exists ("s:BattleDuel.key"))	)
	))
	(
		(if (= (getsize "BD:BattleDuel") 96424)
			(if (= aga 1)
				( (set current "Landscapes_Patch3_ECS") (set dir_dest "RAM:") (extract) (execute "RAM:patch") )
				( (set current "Landscapes_Patch3_AGA") (set dir_dest "RAM:") (extract) (execute "RAM:patch") )
			)
		)
		(if (= (getsize "BD:BattleDuel") 131236)
			(if (= aga 1)
				( (set current "Landscapes_Patch4_ECS") (set dir_dest "RAM:") (extract) (execute "RAM:patch") )
				( (set current "Landscapes_Patch4_AGA") (set dir_dest "RAM:") (extract) (execute "RAM:patch") )
			)
		)
	)
)

(complete 0)
(set current "Program")                (set dir_dest "BD:") (extract)
(complete 10)
(if (= aga 1)
	( (set current "Gfx_ECS")           (set dir_dest "BD:Gfx/ECS/") (extract) )
	( (set current "Gfx_AGA")           (set dir_dest "BD:Gfx/AGA/") (extract) )
)
(complete 20)
(if (= update false)
(
	(if (= aga 1)
		( (set current "Landscapes_ECS") (set dir_dest "BD:Landscapes/ECS/") (extract) )
		( (set current "Landscapes_AGA") (set dir_dest "BD:Landscapes/AGA/") (extract) )
	)
) )
(complete 30)
(if (or (exists ("BD:BattleDuel.key"))
        (exists ("devs:BattleDuel.key"))
        (exists ("s:BattleDuel.key"))
    )
    (if (= aga 1)
		( (set current "Gfx_ECS_Reg")    (set dir_dest "BD:Gfx/ECS/") (extract) )
		( (set current "Gfx_AGA_Reg")    (set dir_dest "BD:Gfx/AGA/") (extract) )
	 )
)
(complete 40)
(set current "Mods")                   (set dir_dest "BD:Mods/") (extract)
(complete 50)
(set current "Settings")               (set dir_dest "BD:Settings/") (extract)
(complete 60)

;======================================================================
; copy selected language
;======================================================================

(if (= @language "deutsch")
	( (set current "Deutsch") (set dir_dest "BD:") (extract) )
	( (set current "English") (set dir_dest "BD:") (extract) )
)
(complete 70)

;======================================================================
; add MagicWB icons?
;======================================================================

(set mwb
	(askbool
		(prompt #want_mwb_icons)
		(help #mwb_icons)
		(choices "Yes" "No")
		(default 1)
	)
)

(if (= mwb 1)
	( (set current "MWB_Icons") (set dir_dest "BD:") (extract) )
	( (set current "Icons") (set dir_dest "BD:") (extract) )
)
(complete 80)

;======================================================================
; set tooltypes
;======================================================================

(if (= aga 1)
	(tooltype
		(dest "BD:BattleDuel")
		(settooltype "DISPLAY_ID"   "0x0")
		(settooltype "DISPLAY_TYPE" "ECS")
	)
	(tooltype
		(dest "BD:BattleDuel")
		(settooltype "DISPLAY_ID"   "0x0")
		(settooltype "DISPLAY_TYPE" "AGA")
	)
)
(complete 90)

;======================================================================
; modify user-startup
;======================================================================

(if (= update false)
	(
		(startup "BattleDuel"
			(prompt #startup)
			(command (cat "Assign >NIL: BD: " bd_dest))
			(help #startup_help)
		)
	)
)

(complete 100)

(exit #have_fun)
