; Installer script for RExpand

(set @default-dest "")

(message
	"RExpand 1.0\nCopyright ©1996 Peter Liljenberg\n\n"
	"Thank you for the decision to install RExpand.\n"
	"It will make your life happier and you will experience a warm, "
	"generous feeling toward the rest of humanity. If that isn't enough, "
	"RExpand will also cure your cat of any fatal diseases it might suffer from.\n"
)

(welcome)

(set start (askchoice
	(prompt "How do you want to start RExpand?")
	(choices "WBStartup" "User-Startup" "Manually")
	(default 0)
	(help "By choosing 'WBStartup' or 'User-Startup' RExpand will be "
		"started every time you boot your Amiga. If you choose 'Manually' "
		"you must start RExpand when you need it.")
) )

(if (= start 0)
	(set destdir "SYS:WBStartup")
	(set destdir (askdir
		(prompt "Where do you want to put RExpand?\n (A drawer won't be created!)")
		(help @askdir-help)
		(disk)
		(default "Work:")
	) )
)

(set docdir (askdir
	(prompt "Where do you want to put the documentation?")
	(help @askdir-help)
	(default destdir)
) )

(set utils (askoptions
	(prompt "Which utilities do you want to install?")
	(choices  "QuitRExpand" "Expand" "Includes2DataFile")
	(help @askoptions-help)
) )

(if (askbool
		(prompt "Do you want to install the data files for the Amiga includes?")
		(help @askbool-help)
		(default 1)
	)
	(set datadir (askdir
		(prompt "Where do you want to put the data files?")
		(help @askdir-help)
		(default (tackon destdir "Data"))
		(newpath)
	))
	(set datadir "")
)

(if (askbool
		(prompt "Do you want to install the C source code?")
		(help @askbool-help)
		(default 0)
	)
	(set srcdir (askdir
		(prompt "Where do you want to put the source code?")
		(help @askdir-help)
		(default (tackon destdir "Source"))
		(newpath)
	))
	(set srcdir "")
)

(set edits (askoptions
	(prompt "Which text editor scripts do you want?")
	(help @askoptions-help)
	(choices "Annotate" "BlacksEditor" "Edt" "PolyEd" "SkoEd" "TKEd")
	(default 0)
) )

(complete 10)
(set n 0)
(set editdir "REXX:")
(while (< n 6)
	( (if (IN edits n)
		( (set editor (select n "Annotate" "BlacksEditor" "Edt" "PolyEd" "SkoEd" "TKEd"))
		(set editdir (askdir
			(prompt ("Where do you want to put the ARexx script for %s?" editor))
			(help @askdir-help)
			(default editdir)
		) )
		(copyfiles
			(prompt ("Copying script for %s..." editor))
			(help @copyfiles-help)
			(source (cat "Editors/" editor))
			(all)
			(dest editdir)
		) )
	)
	(set n (+ n 1)) )
)

(complete 20)
(copyfiles
	(prompt "Copying RExpand...")
	(help @copyfiles-help)
	(source "RExpand")
	(dest destdir)
	(infos)
)

(complete 30)
(copyfiles
	(prompt "Copying documentation...")
	(help @copyfiles-help)
	(source "RExpand.guide")
	(dest docdir)
	(infos)
	(optional nofail)
)

(complete 40)
(if (IN utils 0)
	(copyfiles
		(source "Utils/QuitRExpand")
		(dest "REXX:")
		(help @copyfiles-help)
	)
)

(if (IN utils 1)
	( (copyfiles
		(source "Utils/Expand")
		(dest "S:")
		(help @copyfiles-help)
	)
	(copyfiles
		(help @copyfiles-help)
		(source "Utils/Rexx_Expand.rexx")
		(dest "REXX:")
	) )
)

(if (IN utils 2)
	(copyfiles
		(source "Utils/")
		(choices "Includes2DataFile" "Proto2DataFile")
		(dest "REXX:")
		(help @copyfiles-help)
	)
)

(complete 50)
(if datadir
	(copyfiles
		(prompt "Copying data files...")
		(help @copyfiles-help)
		(source "Data")
		(all)
		(dest datadir)
	)
)

(complete 60)
(if srcdir
	(copyfiles
		(prompt "Copying source code files...")
		(help @copyfiles-help)
		(source "Source")
		(all)
		(dest srcdir)
	)
)

(complete 90)
(if datadir
	(tooltype
		(dest (tackon destdir "RExpand"))
		(settooltype "DATADIR" datadir)
		(noposition)
	)
)

(if (run "findrexx" (safe))
	( (if (exists "SYS:System/RexxMast" (noreq))
		(set rexxmast "SYS:System/RexxMast")
		(set rexxmast (askfile
			(prompt "Where is the file RexxMast? (Needed to run ARexx)")
			(help "ARexx isn't running, which is needed to use RExpand. "
				  "RexxMast starts ARexx, but it can't be found in "
				  "'SYS:System/', where it usually is." @askfile-help)
			(default "SYS:System/RexxMast")
		) )
	)
	(startup "ARexx"
		(prompt "ARexx isn't running. Modify User-Startup to run "
				"ARexx every time you boot your computer?")
		(help @startup-help)
		(command "run >NIL: " rexxmast)
	) )
)

(if (= start 1)
	( (if datadir
		(set startcom (cat "run >NIL: " (tackon destdir "RExpand") " DATADIR " datadir))
		(set startcom (cat "run >NIL: " (tackon destdir "RExpand")))
	)
	(startup "RExpand"
		(prompt "Modify User-Startup so RExpand is started every time you boot?")
		(help @startup-help)
		(command startcom)
	) )
)

(complete 100)
