(set default-user @user-level)
(set WBVer (< 2424832 (getversion "exec.library" (resident))))
(User 2)
(set MM_Dest
(askdir
(prompt "Select the location to install the MaxonMagic drawer?")
(help @askdir-help)
(default @default-dest))
)
(if (<> (substr MM_Dest (- (strlen MM_Dest) 1) ) ":")
(set MM_Dest ("%s/MaxonMAGIC" MM_Dest))
(set MM_Dest ("%sMaxonMAGIC" MM_Dest))
)
(if (<> (exists MM_Dest) 2)
(makedir MM_Dest (infos))
)

(if (<> (exists ("%s/MM_Effekte" MM_Dest)) 2)
(makedir ("%s/MM_Effekte" MM_Dest) (infos))
)

(if (<> (exists ("%s/MM_SModule" MM_Dest)) 2)
(makedir ("%s/MM_SModule" MM_Dest) (infos))
)

(if (<> (exists ("%s/MM_Sounds" MM_Dest)) 2)
(makedir ("%s/MM_Sounds" MM_Dest) (infos))
)

(set hardware
(askchoice
(Prompt (cat "Select the modules you wish to install"
" depending upon your machines hardware configurartion"))
(help @askchoice-help)
(Choices "OCS/ECS/AA" "Graphics board" "All Modules")
)
)

(if (= hardware 0)
(set mask 262143)
)
(if (= hardware 1)
(set mask 208890 )
)
(if (= hardware 2)
(set mask 262143)
)

(set modules
(askoptions
(prompt "Select the modules you would like to install")
(help @askoptions-help)
(choices
"Aquarium"
"BlackScreen"
"Blanctris"
"Clock"
"CrazyWorms"
"Eyes"
"Fireworks"
"Flying Breakfast"
"Lissajous Figures"
"Lightning"
"Messages"
"Password"
"Rain"
"Spots"
"Stars"
"Plasma"
"WBJoke"
"WipeOut"
)
(default mask)
))

(set sound
(askbool
(prompt "Extract sound files?")
(help "Do you want to extract the sound files that go with MaxonMagic?"
" The sound files can be attached to Workbench actions by MaxonMagic"
" See the manual for further details.")
(Choices "Extract files" "Don't Extract Files")
(default 1)
)
)

(set autorun
(askbool
(prompt "Auto run MaxonMagic at boot up?")
(help "If your machine is running Workbench 1.3 the installation"
" will line in the User-Startup to auto run MaxonMagic. If you are using a"
" 2.0/3.0 machine and you have a WBStartup drawer, MaxonMagic will be placed"
" there.\n\n")
(Choices "Auto Run" "Don't Auto Run")
(default 1)
))

(User default-user)

(copyfiles
(source "MMInstall:Tools/lhex")
(dest "T:")
)
(copyfiles
(source "MMInstall:MMAGIC.LHA")
(dest "RAM:")
)
(copylib
(source "MMInstall:Libs/rct.library")
(dest "LIBS:")
)
(set n 0)
(while (set Mod (select n "Aquari*" "Black*"
"Blanc*" "Clock*" "Crazy*" "Eyes*"
"Fire*" "Fly*" "LFig*" "Light*" "Message*"
"Password*" "Rain*" "Spot*" "Star*" "Plasma*"
"WB*" "Wipe*" ""))
	(
	(if (IN modules n)
	(
	(Working "Extracting modules hold a moment...")
	(Run ("T:Lhex -fFw=%s x RAM:MMAGIC.LHA MM_Effekte/%s" MM_Dest Mod))
	)
	)
	(set n (+ n 1))
	)
)

(if (= sound 1)
(
(Working "\n\nExtracting sound modules hold a moment..")
(run ("T:Lhex -fFw=%s x RAM:MMAGIC.LHA MM_Sounds/*" MM_Dest))
(run ("T:Lhex -fFw=%s x RAM:MMAGIC.LHA MM_SModule/*" MM_Dest))
)
)

(Working "\n\nExtracting MaxonMagic program file hold a moment..")
(if (= autorun 1)
(
(if (AND (= WBVer 1) (= (exists "SYS:WBStartup") 2))
	(
	(run "T:Lhex -fFw=SYS:WBStartup x RAM:MMAGIC.LHA Maxon*")
	(tooltype
	(settooltype "PATH" ("\"%s\"" MM_Dest))
	(dest "SYS:WBStartup/MaxonMAGIC")
	)
	)
)

(If (= WBVer 0)
(
	(run ("T:Lhex -fFw=%s x RAM:MMAGIC.LHA Maxon*" MM_Dest))

	(tooltype (dest ("%s/MaxonMAGIC" MM_Dest))
	(settooltype "PATH" MM_Dest)
	)

	(startup "MaxonMAGIC"
	(Prompt "\n\nSet MaxonMagic to auto run from the user-startup?")
	(help @startup-help)
	(Command
	("%s/MaxonMagic\n" MM_Dest))
	)
)

)

)
(
(run ("T:Lhex -fFw=%s x RAM:MMAGIC.LHA Maxon*" MM_Dest))
(tooltype
(settooltype "PATH" ("\"%s\"" MM_Dest))
(dest ("%s/MaxonMAGIC" MM_Dest))
)
)
)
(run ("T:Lhex -fFw=%s x RAM:MMAGIC.LHA Play*" MM_Dest))
(delete "T:Lhex")
(delete "RAM:MMAGIC.LHA")
