;$VER: CD1200 Install 38.3 (02.08.94)
;Copyright ©1993/1994 Elaborate Bytes, Oliver Kastl

(onerror
	(makeassign "TandemCDInst" (safe))
	(makeassign "TandemCD" (safe))
)

(set #autoMount 1)
(set #CDDevice_NC "CD0" )

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

(set #instEjectCD 1)
(set #ReplaceOld 1 )

; (set #TandemUnit 0)
; (set #TandemDevice 0)

(complete 0)

(if (< #wbversion 37)
	(abort "\n\nAmigaDOS 2.04 or higher is required for TandemCD! "
			 "\n\nAn upgrade will be needed for your Amiga." )
)


(if (< (getdiskspace "SYS:") 61440)
	(abort "\n\nApproximately 60K of disk space is needed on your SYS: volume."
			 "\n\nYou only have " (/ (getdiskspace "SYS:") 1024)	"K free.\n\n"
			 "Delete or transfer some files from the SYS: volume and try again." )
)

(askdisk
	(prompt "\n\nPlease insert the disk labeled \"CD1200Install\".")
	(help	"\n\nTandemCD driver, FileSystem and other utilities will be copied "
			"from this disk into your system.")
	(dest  "CD1200Install")
	(newname "TandemCDInst")
)

( set #TandemDevice "tandemcd_pcmcia.device")
( set #TandemUnit 0)

(set #theirlevel @user-level )
(user 2)

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


(set #CDDevice (cat #CDDevice_NC ":") )


(set #autoMount
	(askbool
		(prompt "\n\nWould you like the CD-Rom drive automatically mounted upon bootup?" )
		(help "\n\nIf you would like, the appropriate commands will be added to your user-startup file to automatically mount TandemCD.\n")
		(default 1)
	)
)


(if #autoMount
	(set #mountDirectory "DEVS:DOSDrivers")
)

(if (not #autoMount)
	(set #mountDirectory "SYS:Storage/DOSDrivers")
)


(set #tandemDir
	(askdir
		(prompt "\n\nSpecify the directory in which the TandemCD support programs will be placed:" )
		(help "\n\nTandemCD contains a number of support programs.  This directory will specifiy where the programs will be placed.  If you need, create a separate directory for the files.")
		(default @default-dest)
		(newpath)
	)
)

(set @default-dest #tandemDir)

(makeassign "TandemCD" #tandemDir (safe))

(user #theirlevel)

(protect "l:TandemCacheCDFS" "rwed" )
(copylib
	(prompt "\n\nCopying CDROM FileSystem to the l: directory.\n" )
	(source "TandemCDInst:l/TandemCacheCDFS")
	(dest "l:")
	(confirm)
	(help "\n\nThis will copy over the CDROM FileSystem program to your "
		"l: directory\n\nThis is an essential step in the installation "
		"process.\n" )
)



(complete 10 )

(protect (cat "devs:" #TandemDevice ) "rwed" )
(copylib
	(prompt "\n\nCopying tandem.device to the devs: directory.\n" )
	(source (cat  "TandemCDInst:devs/" #TandemDevice ))
	(dest "devs:")
	(confirm)
	(help "\n\nThis will copy over the tandemcd.device program to your "
		"devs: directory\n\nThis is an essential step in the installation "
		"process.\n" )
)



(complete 20 )

	(copylib
			(source "TandemCDInst:C/Mount")
			(dest "C:")
	)

	(copylib
			(source "TandemCDInst:C/SetPatch")
			(dest "C:")
	)

(if (< #wbversion 38)
	((set #startupCommand (cat "mount " #CDDevice " from devs:MountList." #CDDevice_NC "\n") )
	(if #autoMount
		((protect "S:User-Sequence" "srwed" )

		(startup "TandemCD"
			(command #startupCommand )
			(prompt "\n\nInserting MOUNT command into the startup-sequence")
			(help "\n\nThe command \"MOUNT " #CDDevice " FROM DEVS:MOUNTLIST." #CDDevice_NC "\" is being inserted into your "
					"\"S:Startup-Sequence\" or \"S:User-Startup\" file to "
					"automatically start TandemCD upon bootup." )
		))
	)
	(if (not #autoMount)
		((protect "S:User-Sequence" "srwed" )

		(startup "TandemCD"
			(prompt "\n\nRemoving MOUNT command from the startup-sequence")
			(help "\n\nThe command \"MOUNT " #CDDevice " FROM DEVS:MOUNTLIST." #CDDevice_NC "\" will be removed from your "
					"\"S:Startup-Sequence\" or \"S:User-Startup\" file because you didn't "
					"want to automatically start TandemCD upon bootup." )
		))
	)

	(if (exists (cat "devs:MountList." #CDDevice_NC ) )
		((set #ReplaceOld
			(askbool
			(prompt "\n\nDEVS:MountList." #CDDevice_NC" already exists!\n\n"
			        "Do you want to replace it?" )
			(help "\n\nClick \"YES\" if DEVS:MountList."#CDDevice_NC" should be "
			      "replaced and \"NO\" if not!")
			(default 1)
			)
		))
	)

	(if #ReplaceOld

	((protect (cat "devs:MountList." #CDDevice_NC) "rwed" )

	(textfile
		(dest (cat "devs:MountList." #CDDevice_NC) )
		(append "/***************************************************************/\n"
				  "/*  TandemCD mountlist entry © 1993 Elaborate Bytes, O. Kastl  */\n"
				  "/***************************************************************/\n")
		(append #CDDevice "\n")
		(append "	FileSystem     = L:TandemCacheCDFS /* The name of the game */\n" )
		(append "	Device         = "#TandemDevice" /* Name of exec device driver */\n" )
		(append "	Unit           = "#TandemUnit" /* exec device unit */\n" )
		(append "	Flags          = 0 /* OpenDevice flags */\n")
		(append "	BlocksPerTrack = 1 /* Unused */\n")
		(append "	BlockSize      = 2048 /* True, but unused */\n")
		(append "	Mask           = 0x7ffffffe /* Memory mask for direct read */\n")
		(append "	MaxTransfer    = 0x100000 /* Maximum amount of bytes for direct read */\n")
		(append "	Reserved       = 0 /* Unused */\n")
		(append "	Interleave     = 0 /* Unused */\n")
		(append "	LowCyl         = 0 /* Unused */\n")
		(append "	HighCyl        = 5000 /* Unused */\n")
		(append "	Surfaces       = 1 /* Unused */\n")
		(append "	Buffers        = 50 /* Number of cache lines */\n")
		(append "	BufMemType     = 1 /* MEMF_PUBLIC, use whatever you require */\n")
		(append "	GlobVec        = -1 /* Do not change! */\n")
		(append "	Mount          = 1 /* Mount it immediately */\n")
		(append "	Priority       = 10 /* Priority of FileSystem task */\n")
		(append "	DosType        = 0x43443031 /* Currently unused */\n")
		(append "	StackSize      = 3000 /* Minimum stack required is 3000! */\n")
		(append "	Control        = \"MD=0 LC=1 DC=8 L LV AL LFC=1\"\n")
		(append "   /* The Control field is for special adjustments */\n")
		(append "   /* L/S convert all file names to lowercase */\n")
		(append "   /* LV/S convert volume names to lowercase */\n")
		(append "   /* LFC/N start converting at this character */\n")
		(append "   /* AL/S Auto-Lower converts only non-Amiga CDs */\n")
		(append "   /* LC/N/A number of blocks per cache line */\n")
		(append "   /* DC/N/A number of cache lines for the data cache */\n")
		(append "   /* MD/N/A number of blocks, when starting direct read, not using */\n")
		(append "   /* the cache. 0 will be a reasonable default (LC*DC+1) */\n")
		(append "   /* S/S Do SCSI direct commands, no Trackdisk like commands! */\n")
		(append "   /* NC/S Do NOT use TD_ADDCHANGEINT, poll for DiskChange! */\n")
		(append "   /* M/S Issue a TD_MOTOR (OFF) command after read */\n")
		(append "#\n")
	))
))
)


(if (> #wbversion 37)

	((if (exists (tackon #mountDirectory #CDDevice_NC ) )
		((set #ReplaceOld
			(askbool
			(prompt "\n\n" (tackon #mountDirectory #CDDevice_NC) " already exists!\n\n"
			        "Do you want to replace it?" )
			(help "\n\nClick \"YES\" if " (tackon #mountDirectory #CDDevice_NC) " should be "
			      "replaced and \"NO\" if not!")
			(default 1)
			)
		))
	)

	(if #ReplaceOld

	((protect (tackon #mountDirectory #CDDevice_NC) "rwed" )

	(textfile
		(dest (tackon #mountDirectory #CDDevice_NC) )
		(append "/***************************************************************/\n"
				  "/*  TandemCD mountlist entry © 1993 Elaborate Bytes, O. Kastl  */\n"
				  "/***************************************************************/\n")
		(append "	FileSystem     = L:TandemCacheCDFS /* The name of the game */\n" )
		(append "	Device         = "#TandemDevice" /* Name of exec device driver */\n" )
		(append "	Unit           = "#TandemUnit" /* exec device unit */\n" )
		(append "	Flags          = 0 /* OpenDevice flags */\n")
		(append "	BlocksPerTrack = 1 /* Unused */\n")
		(append "	BlockSize      = 2048 /* True, but unused */\n")
		(append "	Mask           = 0x7ffffffe /* Memory mask for direct read */\n")
		(append "	MaxTransfer    = 0x100000 /* Maximum amount of bytes for direct read */\n")
		(append "	Reserved       = 0 /* Unused */\n")
		(append "	Interleave     = 0 /* Unused */\n")
		(append "	LowCyl         = 0 /* Unused */\n")
		(append "	HighCyl        = 5000 /* Unused */\n")
		(append "	Surfaces       = 1 /* Unused */\n")
		(append "	Buffers        = 50 /* Number of cache lines */\n")
		(append "	BufMemType     = 1 /* MEMF_PUBLIC, use whatever you require */\n")
		(append "	GlobVec        = -1 /* Do not change! */\n")
		(append "	Mount          = 1 /* Mount it immediately */\n")
		(append "	Priority       = 10 /* Priority of FileSystem task */\n")
		(append "	DosType        = 0x43443031 /* Currently unused */\n")
		(append "	StackSize      = 3000 /* Minimum stack required is 3000! */\n")
		(append "	Control        = \"MD=0 LC=1 DC=8 L LV AL LFC=1\"\n")
		(append "   /* The Control field is for special adjustments */\n")
		(append "   /* L/S convert all file/volume names to lowercase */\n")
		(append "   /* LV/S convert volume names to lowercase */\n")
		(append "   /* LFC/N start converting at this character */\n")
		(append "   /* LC/N/A number of blocks per cache line */\n")
		(append "   /* AL/S Auto-Lower converts only non-Amiga CDs */\n")
		(append "   /* DC/N/A number of cache lines for the data cache */\n")
		(append "   /* MD/N/A number of blocks, when starting direct read, not using */\n")
		(append "   /* the cache. 0 will be a reasonable default (LC*DC+1) */\n")
		(append "   /* S/S Do SCSI direct commands, no Trackdisk like commands! */\n")
		(append "   /* NC/S Do NOT use TD_ADDCHANGEINT, poll for DiskChange! */\n")
		(append "   /* M/S Issue a TD_MOTOR (OFF) command after read */\n")
	)

	(copyfiles
			(prompt "\n\nCopying Mountlist icon")
			(source "TandemCDInst:Devs/DOSDrivers/CD0.info")
			(dest #mountDirectory)
			(newname (cat #CDDevice_NC ".info"))
			(help "\n\nThis will copy over an icon for the mountlist file.")
			(confirm)

	)

	(protect "S:User-Sequence" "srwed" )
	(startup "TandemCD"
		(prompt "\n\nRemoving MOUNT command from the startup-sequence")
		(help "\n\nThe command \"MOUNT " #CDDevice " FROM DEVS:MOUNTLIST." #CDDevice_NC "\" will be removed from your "
				"\"S:Startup-Sequence\" or \"S:User-Startup\" file if it is present from "
				"an earlier installation." )
		)

	(if ( exists ( cat "devs:MountList." #CDDevice_NC ) )

		((protect (cat "devs:MountList." #CDDevice_NC) "rwed " )
		(delete (cat "devs:MountList." #CDDevice_NC)
			(prompt "\n\nDeleting file \"DEVS:MOUNTLIST." #CDDevice_NC "\"" )
			(help "\n\nThe file \"DEVS:MOUNTLIST." #CDDevice_NC "\" will be deleted "
					"if it is present from an earlier installation." )
			(confirm)
			)
		))
	)
))
)


(complete 40 )

(set #instCDFSprefs
	(askbool
		(prompt "\n\nShould the CDFSprefs utility be installed?")
		(help "\n\nThis will copy over the CDFSprefs utility "
				"to your SYS:Prefs directory\n\nIf you do not "
				"wish the CDFSprefs program to be transferred to your system, "
				"skip this step.\n" )
		(default 1)
	)
)

(if #instCDFSprefs
	((protect "SYS:Prefs/CDFSprefs" "rwed" )
	(protect "SYS:Prefs/CDFSprefs.info" "rwed" )
	(copylib
		(prompt "\n\nCopying the CDFSprefs program to the "
				  "SYS:Prefs directory.\n" )
		(source "TandemCDInst:CDFSprefs")
		(dest "SYS:Prefs")
		(infos)
		(help "\n\nThis will copy over the CDFSprefs "
				"program to your SYS:Prefs directory\n\nIf you do not "
				"wish the CDFSprefs program to be transferred to your system, "
				"skip this step.\n" )
		(confirm)
	)

	(tooltype
		(dest "SYS:Prefs/CDFSprefs" )
		(noposition)
	)
))

(complete 50 )

(set #instKillDev
	(askbool
		(prompt "\n\nShould the KillDev utility be installed?")
		(help "\n\nThis will copy over the KillDev utility "
				"to your TandemCD directory\n\nIf you do not "
				"wish the KillDev program to be transferred to your system, "
				"skip this step.\n" )
		(default 1)
	)
)

(if #instKillDev
	((protect "TandemCD:KillDev" "rwed" )
	(protect "TandemCD:KillDev.info" "rwed" )
	(copylib
		(prompt "\n\nCopying the KillDev program to the "
				  "TandemCD: directory.\n" )
		(source "TandemCDInst:KillDev")
		(dest "TandemCD:")
		(infos)
		(help "\n\nThis will copy over the KillDev "
				"program to your TandemCD: directory\n\nIf you do not "
				"wish the KillDev program to be transferred to your system, "
				"skip this step.\n" )
		(confirm)
	)

	(tooltype
		(dest "TandemCD:KillDev" )
		(settooltype "DOSDEV" #CDDevice )
		(noposition)
	)
))

(complete 60 )

(set #instFindCD
	(askbool
		(prompt "\n\nShould the FindCD utility be installed?")
		(help "\n\nThis will copy over the FindCD utility "
				"to your TandemCD directory\n\nIf you do not "
				"wish the FindCD program to be transferred to your system, "
				"skip this step." )
		(default 1)
	)
)

(if #instFindCD
	((protect "TandemCD:FindCD" "rwed" )
	(protect "TandemCD:FindCD.info" "rwed" )
	(copylib
		(prompt "\n\nCopying the FindCD program to the "
				  "TandemCD: directory.\n" )
		(source "TandemCDInst:FindCD")
		(dest "TandemCD:")
		(infos)
		(help "\n\nThis will copy over the FindCD "
				"program to your TandemCD directory\n\nIf you do not "
				"wish the FindCD program to be transferred to your system, "
				"skip this step." )
		(confirm)
	)

	(tooltype
		(dest "TandemCD:FindCD" )
		(noposition)
	)

))

(set #instPlayCD
	(askbool
		(prompt "\n\nShould the PlayCD utility be installed?")
		(help "\n\nThis will copy over the PlayCD utility "
				"to your TandemCD directory\n\nIf you do not "
				"wish the PlayCD program to be transferred to your system, "
				"skip this step.\n" )
		(default 1)
	)
)

(complete 70 )

(if #instPlayCD
	((protect "TandemCD:PlayCD" "rwed" )
	(protect "TandemCD:PlayCD.info" "rwed" )
	(copylib
		(prompt "\n\nCopying PlayCD CDAudio controller program to the "
				  "TandemCD: directory.\n" )
		(source "TandemCDInst:PlayCD")
		(dest "TandemCD:")
		(infos)
		(help "\n\nThis will copy over the PlayCD CDAudio controller "
				"program to your TandemCD: directory\n\nIf you do not "
				"wish the PlayCD program to be transferred to your system, "
				"skip this step.\n" )
		(confirm)
	)


	(copyfiles
		(prompt "\n\nCopying PlayCD font to the "
				  "Fonts: directory.\n" )
		(source "TandemCDInst:fonts")
		(dest "fonts:")
		(all)
		(help "\n\nThis will copy over the fonts used by the PlayCD CDAudio controller "
				"program to your Fonts: directory. Note that the PlayCD program will also work "
				"without its fonts copied!\n\nIf you do not "
				"wish the PlayCD fonts to be transferred to your system, "
				"skip this step.\n" )
		(confirm)
	)

	(tooltype
		(dest "TandemCD:PlayCD" )
		(settooltype "DEVICE" #TandemDevice )
		(settooltype "UNIT" ("%ld" #TandemUnit ))
		(noposition)
	)
))


(set #instJukebox
	(askbool
		(prompt "\n\nShould the JukeBox Audio Player be installed?")
		(help "\n\nThis will copy over the JukeBox drawer "
				"to your TandemCD directory\n\nIf you do not "
				"wish the JukeBox drawer to be transferred to your system, "
				"skip this step." )
		(default 1)
	)
)

(complete 80 )

(if #instJukebox
	(
	(protect "TandemCD:JukeBox" "rwed" )
	(protect "TandemCD:JukeBox.info" "rwed" )
	(makedir "TandemCD:JukeBox" 
		(infos)
		(prompt "\n\nCreating drawer for JukeBox\n")
		(help "\n\nThis will create a drawer for the JukeBox "
				"Audio Player." )
	(safe)
	)

(makeassign "JukeBox" "TandemCD:JukeBox")

(working "\n\nDecrunching Jukebox...."
         "\n\nPlease Wait!")

( if ( run "TandemCDInst:c/lha e -a TandemCDInst:JukeBox JukeBox:" )
	(
	(makeassign "JukeBox")
	(abort "\n\nUnable to decrunch JukeBox!")
	)
)


	(tooltype
		(dest "JukeBox:JukeBox" )
		(settooltype "DEVICE" #TandemDevice )
		(settooltype "UNIT" ("%ld" #TandemUnit ))
		(settooltype "PLAYER" ("tandem.player"))
	)

	(makeassign "JukeBox")
))


(set #instYACDP
	(askbool
		(prompt "\n\nShould the YACDP Audio Player be installed?")
		(help "\n\nThis will copy over the YACDP drawer "
				"to your TandemCD directory\n\nIf you do not "
				"wish the YACDP drawer to be transferred to your system, "
				"skip this step." )
		(default 1)
	)
)

(if #instYACDP
	(

	(protect "LIBS:reqtools.library" "rwed" )

	(copylib
	(source "TandemCDInst:LIBS/reqtools.library")
	(dest "LIBS:"))

	(working "\n\nDecrunching YACDP...."
	         "\n\nPlease Wait!")

	( if ( run "TandemCDInst:c/lha e -a TandemCDInst:YACDP TandemCD:" )
		(
		(abort "\n\nUnable to decrunch YACDP!")
		)
	)


	(tooltype
		(dest "TandemCD:YACDP/YACDP" )
		(settooltype "DEVICE" #TandemDevice )
		(settooltype "UNIT" ("%ld" #TandemUnit ))
	)
	)
)


(if #instEjectCD
	(
	(set #instEjectCD
	(askbool
		(prompt "\n\nShould the EjectCD utility be installed?")
		(help "\n\nThis will copy over the EjectCD utility "
				"to your TandemCD directory\n\nIf you do not "
				"wish the EjectCD program to be transferred to your system, "
				"skip this step.\n" )
		(default 1)
	)
	))
)

(if #instEjectCD
	((protect "TandemCD:EjectCD" "rwed" )
	(protect "TandemCD:EjectCD.info" "rwed" )
	(copylib
		(prompt "\n\nCopying EjectCD program to the "
				  "TandemCD: directory.\n" )
		(source "TandemCDInst:EjectCD")
		(dest "TandemCD:")
		(help "\n\nThis will copy over the EjectCD utility "
				"to your TandemCD directory\n\nIf you do not "
				"wish the EjectCD program to be transferred to your system, "
				"skip this step.\n" )
		(infos)
		(confirm)
	)

	(tooltype
		(dest "TandemCD:EjectCD" )
		(settooltype "DEVICE" #TandemDevice )
		(settooltype "UNIT" ("%ld" #TandemUnit ))
		(noposition)
	)
))

(complete 90 )

(if (AND (> #wbversion 38) (exists "TandemCDInst:CD32"))

	((set #instCD32
		(askbool
			(prompt "\n\nShould the CD32-Emulator Demo be installed?"
			        "\n\nNote that the CD32-Emulator Demo is completely useless "
			        "if you don't have an Amiga with AA/AGA chipset and "
			        "at least Kickstart version 3.0!")
			(help "\n\nThis will copy over the CD32 drawer "
					"to your TandemCD directory\n\nIf you do not "
					"wish the CD32 drawer to be transferred to your system, "
					"skip this step.")
			(default 1)
		)
	)

	(if #instCD32
		(
		(copyfiles
			(prompt "\n\nCopying CD32 drawer to the "
					  "CDFS directory.\n" )
			(source "TandemCDInst:CD32")
			(dest "TandemCD:CD32")
			(help "\n\nThis will copy over the CD32 drawer "
					"to your TandemCD directory\n\nIf you do not "
					"wish the CD32 drawer to be transferred to your system, "
					"skip this step." )
			(all)
			(infos)
			(confirm)
		)

		(tooltype
			(dest "TandemCD:CD32/CD1200_CD32" )
			(settooltype "DOSDEV" #CDDevice_NC)
			(settooltype "BLOCKS" "4")
			)

		(set #instInst
			(askbool
			(prompt "\n\nShould the Installer utility be installed?"
			        "\n\nNote that you only need to install the Installer "
			        "utility if you don't have it already installed on "
			        "your harddisk in your actual path!")
			(help "\n\nThis will copy over the Installer utility "
					"to your CD32 directory\n\nIf you do not "
					"wish the Installer utility to be transferred to your system, "
					"skip this step." )
			(default 1)
			)
		)

		(if #instInst
			(
			(copyfiles
			(source "TandemCDInst:Installer")
			(dest "TandemCD:CD32")
			)
		)
		)
	))
))

(complete 100 )

(set #doMount
	(askbool
	(prompt "\n\nMount " #CDDevice " now ?")
	(help "Select, if " #CDDevice " should be mounted now, or not.")
	(default 1)
	)
)

(set #MountError 0)

(if #doMount
	(
	(run (cat "TandemCDInst:KillDev " #CDDevice " Quiet"))
	(if (< #wbversion 38)
		(
		(set #MountError
			(run (cat "C:Mount " #CDDevice " from devs:MountList." #CDDevice_NC ))
		)
		)
	)

	(if (> #wbversion 37)
		(
		(set #MountError
			(run (cat "C:Mount " #CDDevice  ))
		)
		)
	)
	)
)

(if #MountError
	(
	(message "\n\nMounting " #CDDevice " failed!")
	)
)

(makeassign "TandemCDInst" (safe))
(makeassign "TandemCD" (safe))

