;$VER: CD32 HD-Install 42.1 (21.11.94)
;Copyright  1994 Elaborate Bytes, Oliver Kastl

(onerror
	(if (exists "S:Startup-Sequence.std")
		(
		( protect "S:Startup-Sequence.std" "-e +rwsd" )
		(if (exists "S:Startup-Sequence")
			(
			( protect "S:Startup-Sequence" "-e +rwsd" )
			(delete "S:Startup-Sequence")
			)
		)
		(rename "S:Startup-Sequence.std" "S:Startup-Sequence")
		)
	)
	(makeassign "CD32Inst" (safe))
)

(set #wbversion (getversion "libs:version.library"))
(set #wbversion (/ #wbversion 65536) )

(set #Expansion 1)

(set @default-dest "")

(complete 0)


(if (< #wbversion 39)
	((abort "\n\nAmigaDOS 3.0 or higher is required for the CD32-Emulator! "
			 "\n\nAn upgrade will be needed for your Amiga." )
))


(message
	"\nThis program will install or remove a special \"S:Startup-Sequence\" for the CD32-Emulator. "
		 "With the help of this, you may directly boot from a CD32-CD if you press a function key during boot. "
		 "\n\nIf you wish to install, the CacheCDFS MUST be already installed and running! "
       "\n\nWARNING: This program MUST NOT be started from the CDFS Install Disk!"
		)

(makeassign "CD32Inst" "" (safe))

(if (NOT (exists "CD32Inst:PutPrefs"))
	(
	(abort "\n\nCould not find the PutPrefs program!")
	)
)

(set #install
	(askbool
		(prompt "\n\nDo you wish to install or remove the special \"S:Startup-Sequence\" ?")
		(help   "Choose if you wish to install, or if you wish to remove an installation.")
		(default 1)
		(choices "Install" "Remove")
	)
)

(if (NOT #install)
	(
	(if (exists "S:Startup-Sequence.std")
		(
		( protect "S:Startup-Sequence.std" "-e +rwsd" )
		(if (exists "S:Startup-Sequence")
			(
			( protect "S:Startup-Sequence" "-e +rwsd" )
			(delete "S:Startup-Sequence")
			)
		)
		(rename "S:Startup-Sequence.std" "S:Startup-Sequence")
		)
	)
	(if (exists "C:KeyCheck")
		(
		(user 2)
		(delete "C:KeyCheck" 
			(help "Select \"Proceed\", if you want C:KeyCheck to be deleted.")
			(prompt "\n\nDelete C:KeyCheck ?")
			(confirm)
		)
		)
	)

	(makeassign "CD32Inst" (safe))
	(exit)
	)
)

(set #CDDevice_NC "CD0" )

(set #CDDevice_NC
	(askstring
		(prompt "\n\nWhat is the name of the CD-ROM device?\n\n"
		"(The trailing colon MUST NOT be present)" 
		)
		(default #CDDevice_NC )
		(help "\n\nThis is the name under which AmigaDOS references the "
				"CD-Rom as.  While usually "
				#CDDevice_NC
				", it can be any name you choose. "
				"\n\nThe trailing : (colon) MUST NOT be present." )
	)
)

(complete 30)

(working "\n\nLaunching the FindCD32 program to find "
         "the Device and Unit of your CD-Rom..."
         "\n\nNote that the CacheCDFS MUST be already installed and running!")

(if (NOT (exists "CD32Inst:FindCD32"))
	(
	(abort "\n\nCould not find the FindCD32 program!")
	)
)

(set #Product ( run (cat "CD32Inst:FindCD32 " #CDDevice_NC) ( safe ) ) )

(if ( NOT (= #Product 0) )
	(
	(abort "\nCould not find your CDROM hardware!"
			 "\n\nThe CacheCDFS MUST be already installed and running! "
          "\n\nYour CD-Rom MUST be installed as " #CDDevice_NC "!")
	)
)

( set #CDROM_Device (getenv "CDROM_Device" ))

(complete 50)

(set #FKey
	(askchoice
		(prompt "Select the funktion key which starts the CD32-Emulator during bootup")
		(help "\n\nHere you must select the function key you wish to use for "
		      "booting into CD32-Emulation. If you press this key while you "
		      "boot, the CD32-Emulator will be started instead of your normal "
		      "\"S:Startup-Sequence\".")
		(default 9)
		(choices "F1" "F2" "F3" "F4" "F5" "F6" "F7" "F8" "F9" "F10")
	)
)

(set #FKey (+ #FKey 50))
		
(set #CD32_Name "NotPresent")

(if (exists "CD32Inst:CD32-Demo" )
	(
	(set #CD32_Name "CD32-Demo")
	)
)

(if (exists "CD32Inst:TandemCD32" )
	(
	(set #CD32_Name "TandemCD32")
	)
)

(if (exists "CD32Inst:CD1200_CD32" )
	(
	(set #CD32_Name "CD1200_CD32")
	)
)

(if (exists "CD32Inst:CD32" )
	(
	(set #CD32_Name "CD32")
	)
)

(if (= #CD32_Name "NotPresent")
	(
	(abort "\n\nCould not find a CD32-Emulator!")
	)
)

(set #CD32_Path (getassign "CD32Inst"))

(CopyLib
	(source "CD32Inst:KeyCheck")
	(dest "C:")
)


(if (exists (tackon "DEVS:" #CDROM_Device) )
	((set #Expansion 0))
)

(if #Expansion
	(
	(set #Expansion ( NOT (askbool
		(prompt "\n\nIs your CD-Rom controller an Autoboot controller ?")
		(default 0 )
		(help "\n\nChoose \"YES\" if your controller is an autoboot controller "
				"and \"NO\" if not!")

		))
	))
)

(if #Expansion
	(
	(set #BindDrivers "	C:BindDrivers\n")
	)
)

(if (NOT #Expansion)
	(
	(set #BindDrivers "")
	)
)

(complete 80)

( protect "S:Startup-Sequence" "-e +rwsd" )

(if (NOT (exists "S:Startup-Sequence.std" ))
	(
	(rename "S:Startup-Sequence" "S:Startup-Sequence.std")
	)
)

(textfile
	(dest "S:Startup-Sequence" )
	(append ";********************************************************************\n"
			  ";*  CD32-Emulator startup-sequence  1994 Elaborate Bytes, O. Kastl *\n"
			  ";********************************************************************\n")
	(append "\n")
	(append "C:Assign T: RAM:\n")
	(append "C:Assign ENV: RAM:\n")
	(append "C:KeyCheck " #FKey "\n")
	(append "if warn\n")
	(append #BindDrivers)
	(append "	")
	(append (tackon #CD32_Path #CD32_Name) "\n")
	(append "endif\n\n")
	(append "C:Execute S:Startup-Sequence.std\n")
	(append "EndCLI >NIL:\n")
)	

( protect "S:Startup-Sequence" "-e +rwsd" )

( if (NOT @pretend )
	((if ( run "CD32Inst:PutPrefs NonLace" )
	(
	(abort "\n\nPutPrefs program failed!")
	))
))

(complete 90)

(tooltype
	(dest (tackon "CD32Inst:" #CD32_Name) )
	(settooltype "DOSDEV" #CDDevice_NC )
	(noposition)
)

(complete 100)

(makeassign "CD32Inst" (safe))

