;VideoMaster Installation utility
;*************************set up some stuff************************
(set default_dest @default-dest)
(transcript "VideoMasterInstall" "Ram:")
(set default-user @user-level)

;Get the videomaster version
(set VMVersion (getversion "VMInstall:RegularFiles/VideoMaster"))
(Set VMVer (/ VMVersion 65536))
(set VMRev (- VMVersion (* VMVer 65536)))

(set processor (database "cpu"))
(if (or (= processor 68020) (= processor 68030) (= processor 68040))
	(Set CPU 0)
	(Set CPU 1)
)

(set SOURCE1 "VMInstall")
(set SOURCE2 "VMInstall:")
(set SOURCE4 "VMInstall:Examples")
(set SOURCE5 "VMInstall:Tools")

;**************Version 39************
(if (>= (getversion "exec.library" (resident)) 2555904)
(set SOURCE6 "VMInstall:Prefs/Env-Archive_3.x"))
;**************Version 36-39************
(if (AND (>= (getversion "exec.library" (resident)) 2359296) (< (getversion "exec.library" (resident)) 2555904))
(set SOURCE6 "VMInstall:Prefs/Env-Archive_2.x"))
;**************Version 33-36************
(if (< (getversion "exec.library" (resident)) 2359296) (
	(set SOURCE6 "VMInstall:Prefs/Env-Archive_1.3")
))

(set SOURCE7 "VMInstall:Tools2.x")
(set SOURCE8 "VMInstall:Tools1.x")
(set SOURCE9 "VMInstall:ReadMe")
(set SOURCE10 "VMInstall:Utilities")
(set SOURCE11 "VMInstall:CommonFiles")

(if (>= (getversion "exec.library" (resident)) 2359296)
	(set SOURCE12 "VMInstall:Files2.0")
	(set SOURCE12 "VMInstall:Files1.3")
)

;*************************set up Source3 if a 68000/010**********
(Procedure Machine
	(User 2)
	(Set Accelerated (askchoice
		(prompt "Install the accelerated or non accelerated VideoMaster - Select help for more Information?")
		(Help "Do you want to install the accelerated version of VideoMaster. This version is only designed for"
			" use on an Amiga which is faster than a standard A500 or A600 - such as an A1200, or an A500 with accelerator card.\n\n"
			"If you are not sure which version to use, leave the setting on the default."
			" If you choose to install the accelerated version and your machine is not"
			" accelerated, you will experience problems with the software. See the ReadMe file for further"
			" information." )
		(Choices "Install the Accelerated Version" "Install the Non-Accelerated Version")
		(default CPU)))
	(if (= Accelerated 1)
		(set SOURCE3 "VMInstall:FastNLooseFiles")
		(set SOURCE3 "VMInstall:RegularFiles"))

	(User Default-User)
)

;*******************Create Env-Archive for hard disk users if Envarc=0*********
(Procedure EnvArchive
	(if (= (exists "SYS:Prefs/Env-Archive") 0)
		(Makedir "SYS:Prefs/Env-Archive" (safe))
	)
	(Makeassign "ENVARC" "SYS:Prefs/Env-Archive" (safe))
	(startup "EnvArc"
	 (Prompt "Select Proceed to add essential environment paths to the Startup-Sequence")
	 (Help @startup-help) (Command "assign ENVARC: remove\n")
	 (Command "assign ENVARC: SYS:Prefs/Env-Archive ;2.0 style environment setup\n")
	 (Command "copy ENVARC: RAM:ENV ALL QUIET\n")
	)
)

;***************************Introduction**************************
(Procedure HELLO
	(User 2)
	(if (= MEDIA 0)
		(message ("\n Welcome to the installation utility for VideoMaster version %ld.%ld\n" VMVer VMRev)
			"\n Please Note,:\n To ensure correct installation of the package, it is essential that"
			" you boot your machine from the installation disk before using the installation utility!"))

	(if (= MEDIA 1)
		(message ("\n Welcome to the installation utility for VideoMaster version %ld.%ld\n" VMVer VMRev)
			"\n Please Note,:\n To ensure correct installation of the package, it is essential that"
			" you boot from your hard disk before using the installation utility!"))

	(User Default-User)
)

;********** floppy only boot to program or Workbench***********************
(Procedure FLOPPYCHOICE
	(User 2)
	(set AUTORUN (askchoice
		(Prompt "Do you want VideoMaster to Auto-Run at startup or boot to Workbench?")
		(help "Do you want VideoMaster to Auto Run at Startup. If your Amiga has just 1 Megabyte"
			" of memory, we would suggest that you Auto Run the program to save memory by not loading Workbench.\n\n"
			"If your Amiga has over 1 Megabyte of memory, you will be able to run the program from"
			" Workbench without too many memory problem. It is however worth remembering that Auto running the program"
			" will give you the maximum amount of memory for grabs and sequences")
		(Choices "Boot to Workbench" "Auto Run VideoMaster") (Default 1)))
	(User Default-User)
)

;*************Workbench on/off+set paths***********************
(Procedure WBONOFFAUTO
	(user 2)
	(if (= AUTORUN 0) (
		; if auto-running you'll never see the WB anyway
		(set WBONOFF (askchoice
			(Prompt "Do you want to automatically turn off Workbench when running VideoMaster")
			(help "Turning Workbench off when running VideoMaster can give a significant increase"
				" in memory available to VideoMaster for grabs and sequences. If you want the maximum"
				" memory available to VideoMaster select turn Workbench off."
				"\n\nIt is worth noting that once Workbench has been turned off, you will not be able to"
				" use the Workbench screen until you quit VideoMaster")
				(Choices "Workbench on" "Workbench off") (Default 1)))
		; reconfigure the WORKBENCH tooltype depending on what they wanted
		(if (= WBONOFF 1)
			(tooltype (settooltype "WORKBENCH" "NO") (dest (tackon VM_DEST "VideoMaster"))))
	))
	
	; set up floppies for auto-booting
	(if (= MEDIA 0) (
		(set USSTR "\n;BEGIN VideoMaster\nAssign VMAS: VideoMaster:VideoMaster\n")
		(if (= AUTORUN 1) (
			(set USSTR (cat USSTR "cd VMAS:\nC:EndRun VMAS:VideoMaster\n"))
		))
		(textfile (dest "VideoMaster:S/User-Startup")
			(Append USSTR)
			(Append ";END VideoMaster\n"))
	))
	(User default-user)
)

;*******************swapcolors for WB1.3****************
(Procedure ICONCOLORS
	(tooltype (dest (tackon VM_DEST "VideoMaster")) (swapcolors))
	(tooltype (dest (tackon VM_DEST "VidiPlay")) (swapcolors))
	(tooltype (dest (tackon VM_DEST "Make-Disk")) (swapcolors))
	(tooltype (dest (tackon EXAMPLES_DEST "Demo.VSQ")) (swapcolors))
)

;***********************************************************************
;Hard drive Only Procedures
;***********************************************************************
;*********************Location of files**********
(Procedure VMHD
	(set VM_DEST (tackon (askdir 
		(prompt "Select the location for the VideoMaster Drawer")
		(help @askdir-help) (default default_dest)) "VideoMaster"))
	(Makedir VM_DEST (infos))
	(set EXAMPLES_DEST (tackon (askdir
		(prompt "Select the location for the Examples Drawer")
		(help @askdir-help) (default VM_DEST)) "Examples"))
	(Makedir EXAMPLES_DEST (infos))
)

;******************hard disk copy****************
(Procedure VMHDCOPY
	(copyfiles (Source SOURCE3) (dest VM_DEST) (All))
	(copyfiles (Source SOURCE12) (dest VM_DEST) (All))
	(copyfiles (Source SOURCE11) (dest VM_DEST) (All))
	(copyfiles (Source SOURCE4) (dest EXAMPLES_DEST) (All))
	(copyfiles (Source SOURCE6) (dest "envarc:") (All))
)

(Procedure USERHD
	(Makeassign "VMAS" VM_DEST (safe))
	(startup "VideoMaster"
		(Prompt "Going to add the VideoMaster path to the startup files")
		(Help @startup-help)
		(Command "Assign VMAS: "VM_Dest"\n")
	)
)

;***********************************************************************
;Floppy Only Procedures
;***********************************************************************
;*****Procedure TOOLS(copy the necessary files to RAM:T ****
(Procedure TOOLS
	(copyfiles (source SOURCE5) (dest "RAM:T") (All) (files) (nogauge) (safe))
	(if (> (getversion "exec.library" (resident)) 2359296)
		(copyfiles (source SOURCE7) (dest "RAM:T") (All) (files) (nogauge) (safe))
	)
	(if (< (getversion "exec.library" (resident)) 2359296)
		(copyfiles (source SOURCE8) (dest "RAM:T") (All) (files) (nogauge) (safe))
	)
	(copyfiles (source SOURCE9) (dest "RAM:") (nogauge) (safe))
	(copyfiles (source SOURCE10) (dest "T:") (All) (nogauge)(safe))
)

;*****************Procedure SETDRIVE (Select drives to use)*********************
(Procedure SETDRIVE
	(set DRIVE (askchoice
		(prompt "If you have more than one disk drive connected, please select an extra device to use to reduce"
		" the number of disk swaps required during installation")
		(Help @askchoice-help)
		(choices "DF0" "DF1" "DF2" "DF3")
		(default 0))
	)
	(if (= DRIVE 0) (set DRIVE "DF0:"))
	(if (= DRIVE 1) (set DRIVE "DF1:"))
	(if (= DRIVE 2) (set DRIVE "DF2:"))
	(if (= DRIVE 3) (set DRIVE "DF3:"))
)

;************Procedure - FORMAT (Format VMBoot disk)************
(Procedure FORMAT
	(user 2)
	(Message "The Floppy Disk Installation Requires a Blank disk and"
	 " an Amiga Workbench Disk, Please have the blank disk and the"
	 " Workbench disk ready")
	(message ("Please Insert the blank disk in drive %s " DRIVE)
	 " - \n\nWait for the Drive light\n to go off before Proceeding")
	(Working "Formatting the VideoMaster disk\n\n This will take about 2 Minutes...")
	(run "RAM:T/Wait 10" (safe))
	(if (> (getversion "exec.library" (resident)) 2359296)
		(	(Run ("RAM:T/format drive %s name VideoMaster noicons ffs" DRIVE) (safe))
			(Run ("RAM:T/Install %s FFS" DRIVE) (safe))
		)
	)
	(if (< (getversion "exec.library" (resident)) 2359296)
		(	(Run ("RAM:T/format drive %s name VideoMaster noicons" DRIVE) (safe))
			(Run ("RAM:T/Install %s" DRIVE) (safe))
		)
	)
	(run "RAM:T/Wait 3" (safe))
	(Message ("Remove the Disk from %s and label it \n\nVideoMaster" DRIVE))
	(user default-user)
)

;*******Procedure WORKBENCH (Decide if it is a Workbench disk)***********
(Procedure WORKBENCH
	(User 2)
	(message ("Please insert your Workbench disk in Drive %s " DRIVE))
	(set WBDisk (expandpath DRIVE))
	(set WBDisk1 (substr WBDisk 0 9))
	(set WBDisk2 (substr WBDisk 8 9))
	(if (OR (= WBDisk1 "Workbench") (= WBDisk2 "Workbench"))
		(set WBDisk3 1)
		(set WBDisk3 0)
	)
	(user default-user)
)

;**Procedure CHECKWB (Decide what to do if it is not a Workbench disk)*****
(PROCEDURE CHECKWB
	(WORKBENCH)
	(user 2)
	(if (= WBDisk3 0)
		(Message ("This does not look like a Workbench disk\nPlease insert an")
			(" original Workbench disk in drive %s " DRIVE)))
	(WORKBENCH)
	(user 2)
	(If (= WBDisk3 0)
		(Message ("This disk still does not look like a Workbench disk, you can proceed")
			(" without a Workbench disk but the disks created may not work correctly and the")
			(" installation may stop due to an incorrect file/directory structure!\n\n")
			(" \nPlease insert the disk you want to use as a Workbench disk in drive %s " DRIVE)
			(" and select Proceed to continue or ABORT to cancel the installation.")))
	(WORKBENCH)
)

;******************Setup RAM for Boot disk files and copy files**********
(Procedure WBCOPY
	(Makedir "RAM:Boot" (safe))
	(Makedir "RAM:Boot/C" (safe))
	(Makedir "RAM:Boot/Devs" (safe))
	(Makedir "RAM:Boot/L" (safe))
	(Makedir "RAM:Boot/Libs" (safe))
	(Makedir "RAM:Boot/S" (safe))
	(Makedir "RAM:Boot/Utilities" (safe))
	(Makedir "RAM:Boot/System" (safe))
	(Makedir "RAM:Boot/Rexxc" (safe))
	(Makedir "RAM:Boot/Tools" (safe))
	(Makedir "RAM:Boot/Tools/Commodities" (safe))
	(makedir "RAM:Boot/Prefs" (safe))
	(makedir "RAM:Boot/Prefs/Env-Archive" (safe))
	(makedir "RAM:Boot/Prefs/Presets" (safe))
	(copyfiles (source (tackon WBdisk "C")) (dest "RAM:Boot/C") (All) (files))
	(copyfiles (source (tackon WBdisk "Devs")) (dest "RAM:Boot/Devs") (All) (files))
	(copyfiles (source (tackon WBdisk "L")) (dest "RAM:Boot/L") (All) (files))
	(copyfiles (source (tackon WBdisk "Libs")) (dest "RAM:Boot/Libs") (All) (files))
	(copyfiles (source (tackon WBdisk "System")) (dest "RAM:Boot/System") (All) (files) (infos))
	(copyfiles (source (tackon WBdisk "S")) (dest "RAM:Boot/S") (All) (files))
	(if (>= (getversion "exec.library" (resident)) 2359296)
		(copyfiles (source (tackon WBdisk "Prefs/Env-Archive"))
		 (dest "RAM:Boot/Prefs/Env-Archive") (All) (files))
	)
	(if (>= (getversion "exec.library" (resident)) 2359296)
		(copyfiles (source (tackon WBdisk "Prefs/Presets"))
		 (dest "RAM:Boot/Prefs/Presets") (All) (files))
	)
	(if (< (getversion "exec.library" (resident)) 2359296)
		(	(delete "RAM:Boot/S/StartupII")
			(rename "RAM:T/StartupII" "RAM:Boot/S/StartupII" (safe))
		)
	)
)

;****************delete unwanted files***************************
(Procedure DELETEFILES
	(delete "RAM:Boot/Devs/Narrator.Device")
	(delete "RAM:Boot/Libs/Rexxsupport.Library")
	(delete "RAM:Boot/Libs/Rexxsyslib.Library")
	(delete "RAM:Boot/Libs/Translator.Library")
	(delete "RAM:Boot/L/Speak-Handler")
	(delete "RAM:Boot/libs/AmigaGuide.Library")
	(delete "RAM:Boot/libs/bullet.Library")
	(delete "RAM:Boot/libs/datatypes.Library")
	(delete "RAM:Boot/L/CrossDOSFileSystem")
	(delete "RAM:Boot/Libs/Mathieeedoubbas.Library")
	(delete "RAM:Boot/Libs/Mathieeedoubtrans.Library")
	(delete "RAM:Boot/Libs/Mathieeesingtrans.Library")
	(delete "RAM:Boot/Libs/Mathtrans.Library")
	(delete "RAM:Boot/Devs/Parallel.Device")
	(delete "RAM:Boot/Devs/Serial.Device")
	(delete "RAM:Boot/Devs/Printer.Device")
	(delete "RAM:Boot/L/FastFileSystem")
	(delete "RAM:Boot/Devs/Clipboard.Device")
	(delete "RAM:Boot/C/Ed")
	(delete "RAM:Boot/C/Edit")
)

;************************copy files to VideoMaster boot disk***********
(Procedure COPYWB
	(askdisk (Prompt "Please Insert the disk you labeled"
		" \n`VideoMaster' in any drive") (help @askdisk-help) (dest "VideoMaster"))
	(copyfiles (source "RAM:Boot/") (dest "VideoMaster:") (All))
	(makedir "VideoMaster:WBStartup" (infos))
	(makedir "VideoMaster:T")
	(run "RAM:T/delete RAM:Boot all" (safe))
)

;*****Procedure VMFILES copy the program files to ram for the disk ****
(Procedure VMFILES
	(askdisk
	(Prompt "Please Insert the VideoMaster Installation Disk in any drive")
	(help @askdisk-help)
	(dest SOURCE1))

	(Makedir "RAM:VideoMaster" (safe))
	(copyfiles (source SOURCE3) (dest "RAM:VideoMaster") (Pattern "#?") (infos))
	(copyfiles (source SOURCE12) (dest "RAM:VideoMaster") (Pattern "#?") (infos))
	(copyfiles (source SOURCE11) (dest "RAM:VideoMaster") (Pattern "#?") (infos))
	(Makedir "RAM:Examples" (safe))
	(copyfiles (source SOURCE4) (dest "RAM:Examples") (All) (infos))
	(Makedir "RAM:Prefs" (safe))
	(copyfiles (source SOURCE6) (dest "RAM:Prefs") (All) (infos))
	(askdisk (Prompt "Please Insert the disk you labeled"
		" \n`VideoMaster' in any drive") (help @askdisk-help) (dest "VideoMaster"))
	(copyfiles (source "RAM:VideoMaster") (dest "VideoMaster:VideoMaster") (pattern "#?") (infos))
	(copyfiles (source "RAM:Examples") (dest "VideoMaster:Examples") (Pattern "#?") (Infos))
	(copyfiles (source "RAM:Prefs") (dest "VideoMaster:Prefs/Env-Archive/") (all))
	(copyfiles (source "RAM:T/Endrun") (dest "VideoMaster:C") (nogauge))
	(Working "")
	(run "RAM:T/delete RAM:VideoMaster All" (Safe))
	(run "RAM:T/delete RAM:Examples All" (safe))
	(run "RAM:T/delete RAM:Prefs All" (safe))
	(FLOPPYCHOICE)
	(WBONOFFAUTO)
)

;************************goodbye stuff************************
(Procedure BYE
	(askdisk (Prompt "Please Insert the VideoMaster Installation Disk in any drive")
		(help @askdisk-help)
		(dest SOURCE1))

	(user 2)
	(Message "Installation Complete. Installation log file can be found in Ram:."
		"\n\n To obtain your 30 days free technical support and notification of"
		" VideoMaster updates,	please complete your registration card and return"
		" it to:-\nMicrodeal.\nThe Old School\nGreenfield\nBedford\nMK45 5DE\n")
	(Message "Please remember, Technical support is\n between 2-3 p.m."
		" Mon-Fri\nIf you need technical support, please remember to have when you"
		" phone, your:-\nSerial Number\nSoftware version number\nMachine"
		" configuration (RAM,Processor,Hard disk etc)\n\n Please also have a"
		" clear and concise description of the problem you are having to ensure"
		" that we can deal with your problem as quickly as possible.\n\n"
		" Select Proceed to Quit to Workbench")
	(Run "Run VMInstall:Utilities/More VMInstall:ReadMe" (safe))
	(Exit (quiet))
)

;**********************Main Install start********************

(set AUTORUN 0)
(set envarc 1)
(if (< (getversion "exec.library" (resident)) 2359296) (
	(if (= (getassign "ENVARC") "") (set envarc 0))
))

;Floppy or Hard Disk?
(user 2)
(set MEDIA (Askchoice
	(Help @askchoice-help)
	(Prompt "Do you want to install the program to Hard Disk of Floppies?")
	(Choices "Floppy Disk Installation" "Hard Disk Installation")
	(Default 0)))
(user default-user)

(HELLO)
(Machine)

;floppies
(if (= MEDIA 0) (
	(set VM_DEST "VideoMaster:VideoMaster")
	(set EXAMPLES_DEST "VideoMaster:Examples")
	(TOOLS)
	(SETDRIVE)
	(FORMAT)
	(WORKBENCH)
	(if (= WBDisk3 0) (CHECKWB))
	(WBCOPY)
	(DELETEFILES)
	(COPYWB)
	(VMFILES)
))
;HD
(if (= MEDIA 1) (
	(if (= Envarc 0) (EnvArchive))
	(VMHD)
	(VMHDCOPY)
	(WBONOFFAUTO)
	(USERHD)
))
(ICONCOLORS)
(BYE)
