(set #MSG_NOHELP "No help available. Sorry ...")

;file muß gesetzt sein
(procedure P_NOICONPOS
	(
		(set #iconname (tackon #doomdir #file))
		(if (= 1 (exists (cat #iconname ".info")))
			(run ("c/noiconpos \"%s\"" #iconname)
				(prompt ("Correcting position of icon of \"%s\"" #iconname))
				(help #MSG_NOHELP)
				(confirm)
			)
		)
	)
)



(set #doomdir
	(expandpath
		(askdir
			(prompt "Where is the DOOM directory (the one containing the WAD file?)")
			(help #MSG_NOHELP)
			(default "ram:")
		)
	)
)


(set #cpu 0)

(if (patmatch "FPU040" (database "fpu"))
	(set #cpu 1)
	(if (patmatch "(68040|68060)" (database "cpu"))
		(set #cpu 1)
	)
)
		
(set #cpu
	(askchoice
		(prompt "Which version do you want to install?")
		(choices "68030" "68040/68060 (untested)")
		(default #cpu)
		(help #MSG_NOHELP)
	)
)

(if (= #cpu 0)
	(set #exe "DoomAttack")
	(set #exe "DoomAttack.040")
)

(copyfiles
	(prompt "Copying executable")
	(source #exe)
	(newname "DoomAttack")
	(dest #doomdir)
	(help #MSG_NOHELP)
	(confirm)
)

(copyfiles
	(prompt "Copying icon for executable")
	(source (cat #exe ".info"))
	(newname "DoomAttack.info")
	(dest #doomdir)
	(help #MSG_NOHELP)
	(confirm)
)

(if (<> 2 (exists (tackon #doomdir "c" (noreq))))
	(
		(makedir (tackon #doomdir "c")
			(prompt ("Creating command directory in \"%s\"" #doomdir))
			(help #MSG_NOHELP)
			(confirm)
		)
	)
)

(if (<> 2 (exists (tackon #doomdir "c2p" (noreq))))
	(
		(makedir (tackon #doomdir "c2p")
			(prompt ("Creating directory for chunky2planar routine(s) in \"%s\"" #doomdir))
			(help #MSG_NOHELP)
			(confirm)
		)
	)
)

(copyfiles
	(prompt "Copying chunky2planar routine")
	(source "c2p/c2p")
	(dest (tackon #doomdir "c2p"))
	(help #MSG_NOHELP)
	(confirm)
)

(copyfiles
	(prompt "Copying readme file")
	(source "")
	(choices "DoomAttack.readme" "DoomAttack.readme.info")
	(dest #doomdir)
	(help #MSG_NOHELP)
	(confirm)
)

(set #text1 "SetPatch >NIL:\n\nmakedir ram:env\nassign ENV: ram:env\nassign ENVARC: sys:prefs/env-archive\nmakedir ram:t\nassign T: ram:t\n\n")
(set #text2 "C:List >NIL: DEVS:Monitors/~(#?.info|VGAOnly) TO T:M LFORMAT \"DEVS:Monitors/%s\"\nExecute T:M\nC:Delete >NIL: T:M\n\n")
(set #text3 ("setenv DOOMHOME \"%s\"\ncd \"%s\"\nstack 150000\naddbuffers \"\" 200\n\n" #doomdir #doomdir))
(set #text4 "DoomAttack\n\n")

(textfile
	(prompt "Creating DoomAttack_Start script")
	(help #MSG_NOHELP)
	(dest "T:DoomAttack_Start")
	(append #text1 #text2 #text3 #text4)
	(safe)
)

(protect "T:DoomAttack_Start" "+s")

(copyfiles
	(prompt "Copying start script to \"S:\"\n\nIt allows you to boot without startup-sequence and start DoomAttack by simply typing \"S:DoomAttack_Start\".")
	(source "T:DoomAttack_Start")
	(dest "S:")
	(confirm)
	(help #MSG_NOHELP)
)

(if (= 1 (askbool
			(prompt "Do you want the DOOMHOME environment variable to be set in the user-startup? If you select \"No\" then everytime you want to start DoomAttack from Workbench you first have to double-click the \"DoomAttack_ClickMe\" icon!")
			(default 1)
			(help #MSG_NOHELP)
		 )
    )
    (
    	(startup "DoomAttack"
    		(prompt "Changing user-startup")
    		(command ("setenv DOOMHOME \"%s\"" #doomdir))
    		(help #MSG_NOHELP)
    	)
    )
    (
    	(copyfiles
    		(prompt "Copying \"DoomAttack_ClickMe\". When double-clicked, the environment variable DOOMHOME will be set, which must be done before starting DoomAttack from Workbench.")
    		(source "")
    		(choices "DoomAttack_ClickMe" "DoomAttack_ClickMe.info")
    		(dest #doomdir)
    		(confirm)
    		(help #MSG_NOHELP)
    	)
    )
)

(if (= 1 (askbool
			(prompt "Do you want the \"DoomAttack_BootStart\" utility to be installed? It allows you to start DoomAttack 'with no startup-sequence' by simply double-clicking the icon and resetting the computer.")
			(help #MSG_NOHELP)
			(default 1)
		)
	)
	(
		(copyfiles
			(prompt "Copying \"DoomAttack_BootStart\"")
			(source "")
			(choices "DoomAttack_BootStart" "DoomAttack_BootStart.info")
			(dest #doomdir)
			(help #MSG_NOHELP)
			(confirm)
		)

		(copyfiles
			(prompt "Copying small utility needed by \"DoomAttack_BootStart\"")
			(source "c/KillLastChar")
			(dest (tackon #doomdir "c"))
			(help #MSG_NOHELP)
			(confirm)
		)
		
		(if (<> 2 (exists (tackon #doomdir "dosdrivers")))
			(makedir (tackon #doomdir "dosdrivers")
				(prompt "Creating directory for DoomRAD mountlist file needed by \"DoomAttack_BootStart\"")
				(help #MSG_NOHELP)
				(confirm)
			)
		)
		
		(copyfiles
			(prompt "Copying mountlist for DOOMRAD (needed by \"DoomAttack_BootStart\")")
			(source "dosdrivers/DoomRAD")
			(dest (tackon #doomdir "dosdrivers"))
			(confirm)
			(help #MSG_NOHELP)
		)
	)
)

(if (= 1 (askbool
			(prompt "Do you want the position of the icons to be corrected (unsnapshot)?")
			(default 1)
			(help #MSG_NOHELP)
		 )
 	)
	(
	 	(set #file "DoomAttack")
	 	(P_NOICONPOS)
	 	
	 	(set #file "DoomAttack.readme")
	 	(P_NOICONPOS)
	 	
	 	(set #file "DoomAttack_ClickMe")
	 	(P_NOICONPOS)
	 	
	 	(set #file "DoomAttack_BootStart")
	 	(P_NOICONPOS)
	 	
	)
)

(exit "Installation done"
	(quiet)
)
