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

(onerror
	(makeassign "CD32Inst" (safe))
	(makeassign "CD32" (safe))
)

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

(set #Expansion 1)

(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
	"\n\nThis program will create a Boot Floppy for the CD32-Emulator. "
		 "You must have a floppy disk handy and place it in your "
		 "internal drive (DF0:)."
		 "\n\nThe CacheCDFS MUST be already installed and running! "
         "\n\nThis program MUST NOT be started from the CDFS Install Disk!"
		)

(makeassign "CD32Inst" "" (safe))

(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." )
	)
)


(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" ))
( set #CDROM_FileSystem (getenv "CDROM_FileSystem" ))
( set #CDROM_Unit (+ (getenv "CDROM_Unit" )))

(if (askbool
		(prompt "\n\nDo you want to format the disk in drive DF0: ?")
		(default 1 )
		(help "\n\nChoose \"YES\" to format the disk in drive DF0: "
				"and \"NO\" if you don't want to format!")

	)
	(

	(working "\n\nLaunching the WBformat program to create "
         "an empty Disk where the CD32-Emulator will be installed")

	( run "CD32Inst:WBformat DF0:" ) 
	)
)

(makeassign "CD32" "DF0:" (safe))

(complete 50 )

(set @default-dest (getassign "CD32"))

(protect "CD32:Devs" "rwed" )
(protect "CD32:Devs.info" "rwed" )
(makedir "CD32:Devs" 
	(infos)
)

(if (exists (tackon "DEVS:" #CDROM_Device) )
	((protect (tackon "CD32:Devs" #CDROM_Device)  )
	(set #Expansion 0)
	(CopyLib
		(source (tackon "DEVS:" #CDROM_Device))
		(dest  "CD32:Devs") 
	))
)

(protect "CD32:Devs/DosDrivers" "rwed"  )
(protect "CD32:Devs/DosDrivers.info" "rwed"  )
(makedir "CD32:Devs/DosDrivers" 
	(infos)
)

(protect (tackon "CD32:Devs/DosDrivers" #CDDevice_NC ) "rwed"  )
(protect ( cat (tackon "CD32:Devs/DosDrivers" #CDDevice_NC ) ".info") "rwed"  )

(if (exists (tackon "DEVS:DosDrivers" #CDDevice_NC))
	((copyfiles
		(source (tackon "Devs:DosDrivers" #CDDevice_NC))
		(dest "CD32:Devs/DosDrivers")
		(infos)
	))
)

(if (NOT(exists (tackon "DEVS:DosDrivers" #CDDevice_NC)))
	((copyfiles
		(source (tackon "SYS:Storage/DosDrivers" #CDDevice_NC))
		(dest "CD32:Devs/DosDrivers")
		(infos)
	))
)

(complete 60 )

(protect "CD32:S" "rwed" )
(makedir "CD32:S" 
)

(protect "CD32:Libs" "rwed"  )
(makedir "CD32:Libs" 
)

(protect "CD32:L" "rwed"  )
(makedir "CD32:L" 
)

(protect "CD32:Libs/asl.library" "rwed"  )
(CopyLib
	(source "LIBS:asl.library")
	(dest "CD32:LIBS")
)

(if (exists "LIBS:68040.library")
	(
	(protect "CD32:Libs/68040.library" "rwed"  )
	(CopyLib
		(source "LIBS:68040.library")
		(dest "CD32:LIBS")
	))
)

(if (exists "LIBS:workbench.library" )
	(
	(protect "CD32:Libs/workbench.library" "rwed"  )
	(CopyLib
		(source "LIBS:workbench.library")
		(dest "CD32:LIBS")
	))
)

(protect (tackon "CD32:" #CDROM_FileSystem) "rwed"  )
(CopyLib
	(source #CDROM_FileSystem)
	(dest "CD32:L")
)

(complete 70 )

(protect "CD32:C" "rwed"  )
(makedir "CD32:C" 
)

(protect "CD32:C/SetPatch" "rwed"  )
(CopyLib
	(source "C:SetPatch")
	(dest "CD32:C")
)

(protect "CD32:C/LoadWB" "rwed"  )
(CopyLib
	(source "C:LoadWB")
	(dest "CD32:C")
)

(protect "CD32:C/Mount" "rwed"  )
(CopyLib
	(source "C:Mount")
	(dest "CD32:C")
)

(protect "CD32:C/Execute" "rwed"  )
(CopyLib
	(source "C:Execute")
	(dest "CD32:C")
)


(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")
	)
)
	

(complete 80 )

(protect (tackon "CD32:" #CD32_Name) "rwed"  )
(CopyLib
	(source (tackon "CD32Inst:" #CD32_Name))
	(dest "CD32:")
	(infos)
)

(complete 90 )

(protect "CD32:S/Startup-Sequence" "rwed" )

(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 "")
	)
)

(textfile
	(dest "CD32:S/Startup-Sequence" )
	(append ";********************************************************************\n"
			  ";*  CD32-Emulator startup-sequence  1994 Elaborate Bytes, O. Kastl *\n"
			  ";********************************************************************\n")
	(append "\n")
	(append #BindDrivers)
	(append #CD32_Name)
	(append "\n")
)

(if #Expansion
	(
	(protect "CD32:Expansion" "rwed" )
	(protect "CD32:Expansion.info" "rwed"  )

	(makedir "CD32:Expansion" 
		(infos)
	)

	(protect "CD32:C/BindDrivers" "rwed"  )
	(CopyLib
		(source "C:BindDrivers")
		(dest "CD32:C")
	)

	(message
		"\n\nIf your CD-Rom controller is no Autoboot controller, you have to "
		 "drag its driver icon from the SYS:Expansion drawer to the Expansion drawer "
		 "on the CD32 Emulator disk!" 
		)
	)
)

(makedir "CD32:GameStore" 
	(infos)
)

(tooltype
	(dest (tackon "CD32:" #CD32_Name) )
	(settooltype "NVPATH" "GameStore" )
	(settooltype "DOSDEV" #CDDevice_NC )
	(noposition)
)

( protect "CD32:S/Startup-Sequence" "-e +s" )

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

( if (NOT @pretend )
(( run "C:Install DF0:" ))
)

(complete 100 )

(makeassign "CD32" (safe))
(makeassign "CD32Inst" (safe))

