; This installs the files for VistaPro 3.0

(procedure
    get_path (
	(set old_level @user-level)
	(user 1)
	(set install_dir "")
	(while (= install_dir "")
		(set install_dir
		    (askdir
			(prompt "Where is VistaPro installed? ")
			(help @askdir-help)
			(default @default-dest)
			(disk)
		    )
		)
		(if (not (exists install_dir))(set install_dir ""))
		(if (= @default-dest install_dir)
		    (
			(set install_dir (tackon install_dir "VistaPro3.0"))
			(if (not (exists install_dir))(set install_dir ""))
		    )
		)
	)
	(debug "Install dir " install_dir)
	(user old_level)
    )
)

(procedure
    copy_files	(
		    (debug "Copying " src " to " destination)
		    (if (NOT (= floppy 1))
			(
			    (copyfiles
				(help @copyfiles-help)
				(prompt "Copy files to " destination)
				(confirm)
				(all)
				(source src)
				(dest destination)
				(files)
				(safe)
				(optional "nofail")
			    )
			)
		    )
;		     (set dexist (exists destination))
;		     (if (and (= 1 floppy) (= 2 dexist))
		    (if (= 1 floppy)
			(
			    (askdisk
				(prompt "Insert the " ddisk " disk that you used "
					"for the original install of VistaPro on floppies. "
				)
				(help @askdisk-help)
				(dest ddisk)
			    )
			    (copyfiles
				(prompt "Install " fix_dir "?")
				(help @copyfiles-help)
				(all)
				(safe)
				(source (tackon rpath fix_dir))
				(dest (cat ddisk ":" fix_dir))
				(optional "nofail")
				(confirm)
			    )
			    (askdisk
				(prompt "Insert the fix disk we just sent you.")
				(help @askdisk-help)
				(dest "VP3_fix")
			    )
			    (run clean_up)
			)
		    )
		)
)

(procedure extract
    (
	(set rextract ("%s/lharc -m x %s %s/ %s" c archive rpath file))
	(debug "Extract " rextract)
	(working "Extracting " file)
	(run (rextract))
    )
)

(procedure
    install_icon
    (
	(if (= floppy 1)
	    (askdisk
		(prompt "Insert the disk you installed VistaPro on, "
		    "called VistaPro3.0")
		(help @askdisk-help)
		(dest "VistaPro3.0")
	    )
	)
	(if (NOT (exists (tackon install_dir "VistaPro3.0.info"))) ; If the icon doesn't exist
	    (
		(if (= floppy 1)
		    (
			(set install_dir rpath)
			(askdisk
			    (prompt "Insert the fix disk we sent you.")
			    (help @askdisk-help)
			    (dest "VP3_fix")
			)
		    )
		)
		(copyfiles
		    (help @copyfiles-help)
		    (prompt "Install VistaPro icon to " install_dir)
		    (confirm)
		    (source (tackon fix_disk "VistaPro3.0.info"))
		    (dest install_dir)
		)
		(if (= floppy 1)
		    (
			(askdisk
			    (prompt "Insert the disk you installed VistaPro on, "
				"called VistaPro3.0")
			    (help @askdisk-help)
			    (dest "VistaPro3.0")
			)
			(set install_dir "VistaPro3.0:")
			(copyfiles
			    (files)
			    (source (tackon rpath "VistaPro3.0.info"))
			    (dest install_dir)
			    (safe)
			    (nogauge)
			)
		    )
		)
		(set stack
		    (asknumber
			(prompt "Would you like VistaPro to start with a high stack setting ")
			(help "The default value works fine for small landscapes.  If "
			    "you have 8-12 mb of ram, work with large or huge landscapes, "
			    "create rivers or lakes, or use the new 3D trees, then you might "
			    "want a higher stack value.  A simple guideline to use: "
			    "Small: 50000, Large 75000-100000, and Huge 150000. "
			    "If you have more questions about which stack setting you should use, "
			    "check the index of the VistaPro manual for more information.  "
			)
			(default 50000)
			(range 50000 200000)
		    )
		)
		(set vp_icon (tackon install_dir "VistaPro3.0"))
		(tooltype
		    (dest vp_icon)
		    (setstack stack)
		)
		(askdisk
		    (prompt "Insert the fix disk we sent you.")
		    (help @askdisk-help)
		    (dest "VP3_fix")
		)
	    )
	)
    )
)

(procedure
    install_fix (
		    (set sys (database "cpu"))
		    (set prob_fpu (if (or (= sys "68000") (= sys "68020")) 0 1))
		    (set math
			(if
			    (askchoice
				(prompt "Does your system have a math co-processor?")
				(help "If you have an Amiga 500, 600, 1000, 1200, or "
				      "2000, and haven't ever added a faster processor, "
				      "you probably don't have a math coprocessor. "
				      "If you have an Amiga 3000 or 4000, you have a math coprocessor. "
				      "If you aren't sure, then select no.")
				(default prob_fpu)
				(choices "No" "Yes")
			    )
			    "881"
			    "000"
			)
		    )
		    (set archive (tackon fix_disk "vp30"))
		    (set file (cat "VistaPro." math))
		    (if floppy
			(
			    (askdisk
				(prompt "Insert the disk you installed VistaPro on, "
				    "called VistaPro3.0")
				(help @askdisk-help)
				(dest "VistaPro3.0")
			    )
			    (set install_dir "VistaPro3.0:")
			)
		    )
		    (run clean_up)
		    (working "Extracting VistaPro3.0.")
		    (extract)
		    (set src (tackon rpath file))
		    (working "Copying VistaPro3.0.")
		    (copyfiles
			(files)
			(source src)
			(dest install_dir)
			(safe)
			(nogauge)
			(newname "VistaPro3.0")
		    )
		    (run clean_up)
		)
)

(procedure
    install_viewer
    (
	(if (= floppy 1)
	    (
		(askdisk
		    (prompt "Insert the disk you installed VistaPro on, "
			"called VistaPro3.0")
		    (help @askdisk-help)
		    (dest "VistaPro3.0")
		)
	    )
	)
	(set archive (tackon fix_disk "vp30"))
	(set file "Viewer3")
	(extract)
	(set src (tackon rpath file))
	(working "Copying Viewer to " install_dir)
	(copyfiles
	    (source src)
	    (dest install_dir)
	    (safe)
	    (nogauge)
	)
	(askdisk
	    (prompt "Insert the fix disk we just sent you.")
	    (help @askdisk-help)
	    (dest "VP3_fix")
	)
    )
)

(procedure
    yo
    (
	(message "The disk contains: a VistaPro icon, two dems, a tutorial iff file, a fixed "
		 "version of the viewer, a fixed lightning script, and VistaPro 3.04b.  If you "
		 "only wish to install some of these files, then select Expert as your User "
		 "Level."
	)
	(if
	    (askbool
		(prompt "Are you running VistaPro from floppies?")
		(help @askbool-help)
	    )
	    (
		(set install_dir "VistaPro3.0:")
		(set floppy 1)
		(debug "Floppy " floppy)
	    )
	    (get_path)
	)
    )
)

(user 1)
(yo)
(welcome)

(set fix_disk "VP3_fix:")
(set workbench (getversion))
(set work (/ workbench 65536))
(set wb (if (>= work 37) 2 1))
(debug "WB: " wb)
(if (< wb 2)
    (
	(set c (tackon fix_disk "c_13")) ; use 1.3 commands.
    )
    (
	(set c (tackon fix_disk "c")) ; use 2.0 commands.
    )
)

(set n 0)
(set rpath "ram:vpfix")
(makedir rpath)
(set clean_up ("%s/delete %s/#? all" c rpath))
(debug clean_up)
(set ddisk "VistaPro_Extras")
(install_icon)

(set n 0)
(while (< n 4)
    (
	(set fix_dir
	    (select n "script" "iff" "rexx" "dem")
	)
	(if (= n 3) (set ddisk "VistaPro3.0"))
	(set archive (tackon fix_disk "left_out"))
	(set file (cat fix_dir "/#?"))
	(extract)
	(set src (tackon rpath fix_dir))
	(set destination (tackon install_dir fix_dir))
	(copy_files)
	(set n (+ n 1))
	(complete (* n 20))
    )
)
(install_viewer)
(install_fix)
(set clean_up ("%sdelete %s#? all" c c))
