; xpdisk.device Installation :vi:nosi:noai

(set @app-name "xpkdisk.device")
(welcome "xpkdisk.device Installation")

(if (= @user-level 2)
    (set DEVS
	(askdir
	    (prompt "Where do you keep your devices?")
	    (help @askdir-help)
	    (default "DEVS:")
	)
    )
    (set DEVS "DEVS:")
)

(copylib
    (prompt (cat "Copying the device to " DEVS))
    (help @copylib-help)
    (source "xpkdisk.device")
    (dest DEVS)
    (confirm)
)

(set mountliststyle (= 2 (exists "DEVS:DOSDrivers")))

(if (= @user-level 2)
    (set mountliststyle
	(askchoice
	    (prompt "What style of Mountlist do you want?")
	    (choices "1.2 .. 2.0 DEVS:Mountlist style"
		     "2.1+ DEVS:DOSDrivers/ style")
	    (default mountliststyle)
	    (help @askchoice-help))
    )
)

(set XD0 "XD0")
(set Compress0 "Compress0")

(select mountliststyle
; 0:
    (
	(set Mountfile (expandpath ("DEVS:Mountlist")))
	(if (= Mountfile "") (set Mountfile "DEVS:Mountlist"))
	(delete "T:TML2")
	(textfile
	    (prompt "Adding Mountlist entry for a compressed disk of 10 megabytes.")
	    (help (cat ("This will work on system versions 1.2 and higher. \n\n"
			@copyfiles-help)))
	    (dest "T:TML2")
	    (append (cat XD0 ":\n"))
	    (include "Mountfile")
	    (append "#\n")
	    (confirm)
	)
	(if (exists "T:TML2") (
	    (if (exists Mountfile) (
		(copyfiles (source Mountfile) (dest "T:") (newname "TML1"))
		(textfile (dest Mountfile) (include "T:TML1") (include "T:TML2"))
	    )
	    (
		(textfile (dest Mountfile) (include "T:TML2"))
	    ))
	    (delete "T:TML2")
	))
    )
; 1:
    ((set Mountfile (tackon "DEVS:DOSDrivers" XD0))
    (copyfiles
	(prompt "Adding Mountfile for a compressed disk of 10 megabytes.")
	(help (cat ("This will work on system versions 2.1 and higher. \n\n"
		    @copyfiles-help)))
	(source "Mountfile")
	(dest "DEVS:DOSDrivers")
	(newname XD0)
	(infos)
	(confirm)
    ))
)

(if (exists "ENV:EDITOR")
    (set Editor (getenv "EDITOR"))
    (set Editor "")
)
(if (and (= Editor "") (exists "SYS:Tools/MEmacs"))
    (set Editor "SYS:Tools/MEmacs")
)
(if (and (= Editor "") (exists "C:Ed"))
    (set Editor "C:Ed")
)

(if (not (= Editor ""))
    (run (cat Editor " " Mountfile)
	(prompt "Do you want to edit the Mountlist?")
	(help (cat "You may want this to change the size "
		   "of your compressed disk."))
	(confirm)
    )
)

(if (exists "XPKD:" (noreq))
    (set XPKD (expandpath "XPKD:"))
    (set XPKD "Work:XPKD")
)

(set XPKD
    (askdir
	(prompt "Where do you want the compressed data to be stored?")
	(help (cat "You should preferably select an empty directory, or "
		   "create new directory. \n\n"
		   @askdir-help))
	(default XPKD)
    )
)

(set UserStartup (cat "Assign XPKD: " XPKD "\nMount " XD0 ":\n"))

(startup "xpkdisk"
    (prompt (cat
	    "One Assign needs to be added to the \"S:user-startup\" "
	    "so that your system will be properly configured to use "
	    "xpkdisk.\n"
	    "The disk also needs to be mounted before use."))
    (command UserStartup)
    (help @startup-help)
)

(makeassign "XPKD" XPKD (safe))

(run "xdprefs"
    (prompt "Running xpkdisk preferences.")
    (help "You want this to select further options.")
    (safe)
)

(copyfiles
    (prompt "Copying xpkdisk preferences program.")
    (help @copyfiles-help)
    (source "XdPrefs")
    (dest "SYS:Prefs")
    (infos)
    (confirm)
)

(run (cat "C:Mount " XD0 ":"))

(run (cat "SYS:System/Format <NIL: drive " XD0 ": name " Compress0 " QUICK FFS")
    (prompt "Quick-formatting the compressed disk with the FastFileSystem.")
    (help "The disk must be formatted before use.")
    (confirm)
)

(run "AmigaGuide xpkdisk.guide"
    (prompt "Running AmigaGuide xpkdisk.guide.")
    (help "You want this to read the documentation.")
    (safe)
)
