(set @default-dest "")

(if (< (getversion "LIBS:version.library") (* 38 65536))
	(abort "MultiFileSystem requires Workbench 2.1 or higher")
)

(set mfs_dest "SYS:Tools/Commodities")
(if (= (exists "SYS:WBStartup/MFS") 1)
	(set mfs_dest "SYS:WBStartup")
)

(set mfs_dest
	(askdir
		(prompt "In which drawer should the MFS commodity be copied?")
		(help @askdir-help)
		(default mfs_dest)
	)
)

(copylib
	(prompt "Copying MFS commodity")
	(help @copylib-help)
	(source "Tools/Commodities/MFS")
	(dest mfs_dest)
	(infos)
	(confirm)
)

(copylib
	(prompt "Copying mfs-handler")
	(help @copylib-help)
	(source "l/mfs-handler")
	(dest "L:")
	(confirm)
)

(copylib
	(prompt "Copying MFSMount")
	(help @copylib-help)
	(source "c/MFSMount")
	(dest "C:")
	(confirm)
)

(if (= (exists "DEVS:DOSDrivers/DF0") 0)
	(makedir "DEVS:DOSDrivers/DF0"
		(prompt "Creating drawer \"DEVS:DOSDrivers/DF0\"")
		(help @makedir-help)
		(infos)
		(confirm)
	)
)

(if (= (exists "DEVS:DOSDrivers/DF0") 2)
	(
		(run "FileNote DEVS:DOSDrivers/DF0 Amiga")

		(if (= (exists "DEVS:DOSDrivers/PC0") 1)
			(
				(rename "DEVS:DOSDrivers/PC0" "DEVS:DOSDrivers/DF0/PC0"
					(prompt "Moving PC0 to drawer \"DEVS:DOSDrivers/DF0\"")
					(help @rename-help)
					(confirm)
				)

				(if (= (exists "DEVS:DOSDrivers/DF0/PC0") 1)
					(rename "DEVS:DOSDrivers/PC0.info" "DEVS:DOSDrivers/DF0/PC0.info")
				)
			)
		)

		(if (= (exists "DEVS:DOSDrivers/DF0/PC0") 1)
			(run "FileNote DEVS:DOSDrivers/DF0/PC0 MS-DOS")
			(message "\n\nPC0 not found in DEVS:DosDrivers. You'll have to move it to DEVS:DosDrivers/DF0 yourself.")
		)
	)
)

(if (getassign "DF1" "d")
	(if (= (exists "DEVS:DOSDrivers/DF1") 0)
		(makedir "DEVS:DOSDrivers/DF1"
			(prompt "Creating drawer \"DEVS:DOSDrivers/DF1\"")
			(help @makedir-help)
			(infos)
			(confirm)
		)
	)
)

(if (= (exists "DEVS:DOSDrivers/DF1") 2)
	(
		(run "FileNote DEVS:DOSDrivers/DF1 Amiga")

		(if (= (exists "DEVS:DOSDrivers/PC1") 1)
			(
				(rename "DEVS:DOSDrivers/PC1" "DEVS:DOSDrivers/DF1/PC1"
					(prompt "Moving PC1 to drawer \"DEVS:DOSDrivers/DF1\"")
					(help @rename-help)
					(confirm)
				)

				(if (= (exists "DEVS:DOSDrivers/DF1/PC1") 1)
					(rename "DEVS:DOSDrivers/PC1.info" "DEVS:DOSDrivers/DF1/PC1.info")
				)
			)
		)

		(if (= (exists "DEVS:DOSDrivers/DF1/PC1") 1)
			(run "FileNote DEVS:DOSDrivers/DF1/PC1 MS-DOS")
			(message "\n\nPC1 not found in DEVS:DosDrivers. You'll have to move it to DEVS:DosDrivers/DF1 yourself.")
		)
	)
)

(if (getassign "DF2" "d")
	(if (= (exists "DEVS:DOSDrivers/DF2") 0)
		(makedir "DEVS:DOSDrivers/DF2"
			(prompt "Creating drawer \"DEVS:DOSDrivers/DF2\"")
			(help @makedir-help)
			(infos)
			(confirm)
		)
	)
)

(if (= (exists "DEVS:DOSDrivers/DF2") 2)
	(
		(run "FileNote DEVS:DOSDrivers/DF2 Amiga")

		(if (= (exists "DEVS:DOSDrivers/PC2") 1)
			(
				(rename "DEVS:DOSDrivers/PC2" "DEVS:DOSDrivers/DF2/PC2"
					(prompt "Moving PC2 to drawer \"DEVS:DOSDrivers/DF2\"")
					(help @rename-help)
					(confirm)
				)

				(if (= (exists "DEVS:DOSDrivers/DF2/PC2") 1)
					(rename "DEVS:DOSDrivers/PC2.info" "DEVS:DOSDrivers/DF2/PC2.info")
				)
			)
		)

		(if (= (exists "DEVS:DOSDrivers/DF2/PC2") 1)
			(run "FileNote DEVS:DOSDrivers/DF2/PC2 MS-DOS")
			(message "\n\nPC2 not found in DEVS:DosDrivers. You'll have to move it to DEVS:DosDrivers/DF2 yourself.")
		)
	)
)

(if (getassign "DF3" "d")
	(if (= (exists "DEVS:DOSDrivers/DF3") 0)
		(makedir "DEVS:DOSDrivers/DF3"
			(prompt "Creating drawer \"DEVS:DOSDrivers/DF3\"")
			(help @makedir-help)
			(infos)
			(confirm)
		)
	)
)

(if (= (exists "DEVS:DOSDrivers/DF3") 2)
	(
		(run "FileNote DEVS:DOSDrivers/DF3 Amiga")

		(if (= (exists "DEVS:DOSDrivers/PC3") 1)
			(
				(rename "DEVS:DOSDrivers/PC3" "DEVS:DOSDrivers/DF3/PC3"
					(prompt "Moving PC3 to drawer \"DEVS:DOSDrivers/DF3\"")
					(help @rename-help)
					(confirm)
				)

				(if (= (exists "DEVS:DOSDrivers/DF3/PC3") 1)
					(rename "DEVS:DOSDrivers/PC3.info" "DEVS:DOSDrivers/DF3/PC3.info")
				)
			)
		)

		(if (= (exists "DEVS:DOSDrivers/DF3/PC3") 1)
			(run "FileNote DEVS:DOSDrivers/DF3/PC3 MS-DOS")
			(message "\n\nPC3 not found in DEVS:DosDrivers. You'll have to move it to DEVS:DosDrivers/DF3 yourself.")
		)
	)
)

(startup "MultiFileSystem"
	(prompt "Adding a line to S:user-startup")
	(help @startup-help)
	(command "C:MFSMount DEVS:DOSDrivers/~(#?.info)")
)

(set doit
	(askchoice
		(prompt "Do you want to install the Format and DiskCopy replacements?")
		(help @askchoice-help)
		(choices "Yes" "No")
		(default 0)
	)
)

(if (= doit 0)
	(
		(message "\n\nPlease insert the \"Amiga Workbench\" disk in DF0:")

		(run "c/mergex system/format.mergex DF0:System/Format SYS:System/Format"
			(prompt "Patching Format")
			(help @run-help)
			(confirm)
		)

		(run "c/mergex system/diskcopy.mergex DF0:System/DiskCopy SYS:System/DiskCopy"
			(prompt "Patching DiskCopy")
			(help @run-help)
			(confirm)
		)
	)
)
