; This is the MacroForm Installer

(Transcript "MacroForm Install")

;***********************************************
;Initialize global variables
;***********************************************

(set Disk1 "Disk1:")
(set Disk2 "Disk2")
(set Disk3 "Disk3")

(set MacMem 850000)
(set TutMem 1400000)

(set CDir "Sys:C")
(set SDir "Sys:S")
(set LDir "Sys:LIBS")

;***********************************************
;Get MacroForm installation directory
;***********************************************

(if (exists "Work:Toaster" (noreq))
	(set @default-dest "Work:Toaster")
	((set MacInstall
		(askdir
			(prompt "Where is your Toaster or NewTek directory?")
			(help "MacroForm MUST be installed in the top level of your Toaster or NewTek directory.")
			(default @default-dest)
		)
	 )
	 (set @default-dest MacInstall)
	)
)

(set MacDir (tackon @default-dest "MacroForm"))

;***********************************************
;Check available disk space
;***********************************************

(if (< (getdiskspace @default-dest) MacMem)
		(exit (("There isn't enough storage space on %s " @default-dest)
				"to perform this installation!")
		)
)

;***********************************************
;Prompt user for modules to install
;***********************************************

(set ModNames
	(askoptions
		(prompt "Deselect the modules that you don't want to install.")
		(help @askoptions-help)
		(choices "MacroForm" "Tutorials")
;		(default 2)
	)
)

;***********************************************
;Check available disk space against selections
;***********************************************

(set avspace 0)
(set FulMem 0)
(if (in ModNames 0)
	(+ FulMem MacMem)
)
(if (in ModNames 1)
	(+ FulMem TutMem)
)

(if (< (getdiskspace @default-dest) FulMem)
		(exit "There isn't enough storage space on %s/n" @default-dest
				"To perform this installation!/n"
		)
)

;***********************************************
;Find Modeler Macro drawer
;***********************************************

(if (exists (tackon @default-dest "Arexx_Examples/lwm"))
	(set LWMDir (tackon @default-dest "Arexx_Examples/lwm"))
	(if (exists (tackon @default-dest "Arexx/Modeler"))
		(set LWMDir (tackon @default-dest "Arexx/Modeler"))
		(set LWMDir
			(askdir
				(prompt "Where are your Modeler macros located?")
				(help "MacroForm needs to know where to install the programs.")
				(default @default-dest)
			)
		)
	)
)


;***********************************************
;Copy MacroForm
;***********************************************

(if (in ModNames 0)
	(
		;COPY MACROFORM FILES
		(copyfiles
			(prompt "Copy MacroForm Files...")
			(help @copyfiles-help)
			(source (tackon Disk1 "MacroForm"))
			(dest MacDir)
			(all)
			(confirm)
		)

		;COPY LWM FILES
		(copyfiles
			(prompt "Copy RailToolz and the Productivity Set...")
			(help @copyfiles-help)
			(source (tackon Disk1 "lwm"))
			(dest LWMDir)
			(all)
			(confirm)
		)

		;COPY C FILES
		(copyfiles
			(prompt "Copy MacroForm Support Files to C:...")
			(help @copyfiles-help)
			(source (tackon Disk1 "C"))
			(dest CDir)
			(all)
			(confirm)
		)

		;COPY S FILES
		(copyfiles
			(prompt "Copy MacroForm Support Files to S:...")
			(help @copyfiles-help)
			(source (tackon Disk1 "S"))
			(dest SDir)
			(all)
			(confirm)
		)

		;EDIT USER STARTUP
		(run "rx DF0:CheckRP"
			(prompt "Edit user-startup...")
			(help "MacroForm MUST edit the user-startup file in order to work.  For more information, read the ReadMe file on this disk.")
			(confirm)
		)

		;Remove RPStart from WBStartup
		(if (exists ("SYS:WBStartup/RPStart") (noreq))
			((delete "SYS:WBStartup/RPStart")
		 	 (delete "SYS:WBStartup/RPStart.info")
			)
		)

		;Shut down RexxMast and RPControl, then restart them
		(if (exists ("c:rxc") (noreq))
			(run "c:rxc"))
		(if (exists ("SYS:rexxc/rxc") (noreq))
			(run "c:rxc")
		)
		(run "c:RPStart")

		;GET MOD-CONFIG FILE
		(if (exists (tackon @default-dest "3D/Mod-config"))
			(set ModFile (tackon @default-dest "3D/Mod-config"))

			(if (exists (tackon @default-dest "Programs/Mod-config"))
				(set ModFile (tackon @default-dest "Programs/Mod-config"))
				(set ModFile
					(askfile
						(prompt "Where is your Mod-Config file?")
						(help "MacroForm needs to alter your Mod-Config file.")
						(default @default-dest)
					)
				)
			)
		)

		;ASSIGN KEYMASTER
		(run ("rx DF0:KeyChange %s %s" ModFile LWMdir)
			(prompt "Assigning KeyMaster to F-Key 1...")
			(help "As a convenience, the installer will assign KeyMaster to F-Key 1 in Modeler.  This will allow you to access the full MacroForm environment with just a few mouse clicks.")
			(confirm)
		)

		;COPY LIBS FILES
		(askdisk
			(prompt "Please insert Disk2 into your floppy drive...")
			(help @askdisk-help)
			(dest Disk2)
		)

		(copyfiles
			(prompt "Copy MacroForm Support Files to LIBS:...")
			(help @copyfiles-help)
			(source "Disk2:LIBS")
			(dest LDir)
			(all)
			(confirm)
		)
	)
)

;***********************************************
;Copy Tutorials
;***********************************************

(if (in ModNames 1)
	(
		(askdisk
			(prompt "Please insert Disk2 into your floppy drive...")
			(help @askdisk-help)
			(dest Disk2)
		)

		(copyfiles
			(prompt "Copy Scenes...")
			(help @copyfiles-help)
			(source "Disk2:scenes")
			(dest (tackon MacDir "scenes"))
			(all)
			(confirm)
		)

		(copyfiles
			(prompt "Copy Turorial Macro...")
			(help @copyfiles-help)
			(source "Disk2:lwm")
			(dest LWMdir)
			(all)
			(confirm)
		)

		(copyfiles
			(prompt "Copy Tutorials...")
			(help @copyfiles-help)
			(source "Disk2:tutorials")
			(dest (tackon MacDir "tutorials"))
			(all)
			(confirm)
		)

		(askdisk
			(prompt "Please insert Disk3 into your floppy drive...")
			(help @askdisk-help)
			(dest Disk3)
		)

		(copyfiles
			(prompt "Copy Tutorials...")
			(help @copyfiles-help)
			(source "Disk3:tutorials")
			(dest (tackon MacDir "tutorials"))
			(all)
			(confirm)
		)
	)
)

;EDIT USER STARTUP
(if (exists "sys:utilities/multiview")
(if (askbool
		(prompt "Do you want to read the ReadMe file now?")
		(help "The ReadMe file contains important information for using MacroForm.")
		(default 1)
	)
	(run "multiview DF0:ReadMe")
)
)

(if (in ModNames 0)
	(Message "You MUST reboot your system to start using MacroForm!                                                    Don't forget to send in your registration card... Enjoy MacroForm!")
)

