; InstallerFX script
(if (= x 1) (welcome))

(onerror (CLEANUP))

; Cleanup any temporary mess we created
(procedure CLEANUP
    ; Nothing to cleanup
    (delete "t:Logopic")
    (delete "t:Logopic.prefs")
) ; CLEANUP


(procedure P_NEWSTUFF
(message "Things New in Version "ver"\n\n* No Quick Guide Graphic\n* Updated Documentation\n* Custom WAD Support\n* View other peoples Settings via network\n* Command Line CheckGadgets moved into External file")
)

(procedure P_QUICKGUIDE
	(message "QuickGuide graphic not included in this release due to its size")
;	(if 	(askbool
;		(prompt "Do you wish to view the Quick Guide graphic ? This is recommended.")
;		(help @askbool-help)
;	)
;	(
;		(if (exists "sys:utilities/multiview")(set viewer "sys:utilities/multiview"))
;		(if (exists "c:vt")(set viewer "c:vt"))
;		(if (exists "c:viewtek")(set viewer "c:viewtek"))
;		(if (exists "c:visage")(set viewer "c:visage"))
;		(run	viewer " data/quickguide.ilbm")
;	)
;	)
)

(set @user-level 0)

;(set Opt 3)
;(complete 0)

(copyfiles
	(source "data/installgfx.ilbm")
	(dest "t:")
	(newname "Logopic")
)

(copyfiles
	(source "data/InstallerFX.prefs")
	(dest "t:")
	(newname "Logopic.prefs")
)

(run "run InstallerFX t:logopic")

;(run "magicclip " (getsum "DoomGATE.rexx"))

(set @user-level 2)

(set ver "0.8")
(set checkdist 853170358)
(set checkfile (getsum "DoomGATE.rexx"))
(set muirexx (exists "MUIREXX:MUIREXX" (noreq)))
(set destdir (getenv "DoomGATE/DoomGATE_Location"))

(if (BITAND muirexx 1) (

(if (>= (getversion "MUIREXX:MUIREXX") 196608)
(
(message "DoomGATE "ver "\nWelcome to the DoomGATE Installation Utility\n\nDoomGATE is Emailware.\n\npcomm@inorbit.com\n\n(But we also like money, broken hardware\nand interesting posters. Send them, too :-)")
)
(
(message "DoomGATE "ver "\nWelcome to the DoomGATE Installation Utility\n\nYour MUIRexx version is too old.\n\nPlease download MUIRexx 3.0a from Aminet and install it before\nRunning this Installer.")
(CLEANUP)
(exit "Installation Cancelled" (quiet))
)
)


)
(

(if (exists "sys:utilities/MUIREXX" (noreq))
(


(if (>= (getversion "sys:utilities/MUIREXX") 196608)
(
(message "DoomGATE "ver "\nWelcome to the DoomGATE Installation Utility\n\nIt appears that MUIRexx is not correctly installed.\nIt has been found in sys:utilities/ rather than in muirexx:\nYou can fix this easily, by assigning MUIRexx: to Sys:Utilities/ then\nrunning this Installer.")
)
(
(message "DoomGATE "ver "\nWelcome to the DoomGATE Installation Utility\n\nYour MUIRexx version is too old.\n\nPlease download MUIRexx 3.0a from Aminet and install it before\nRunning this Installer.\n\n(It was also incorrectly installed, you need to add a MUIRexx: assign.")
(CLEANUP)
(exit "Installation Cancelled" (quiet))
)
)









)
(
(message "DoomGATE "ver "\nWelcome to the DoomGATE Installation Utility\n\nIt appears that MUIRexx is not installed. This is required.\nPlease download MUIRexx 3.0a from Aminet and install it before\nRunning this Installer.")
(CLEANUP)
(exit "Installation Cancelled" (quiet))
)
)

)
)

(if (= checkdist checkfile)
(
(complete 10)
)
(
(message "Your DoomGATE has been altered.\nPlease notify the author at pcomm@inorbit.com.")
(CLEANUP)
(exit "Installation Cancelled" (quiet))
)
)

(P_NEWSTUFF)

(if (= "" destdir)
(
(set destdir "sys:")
)
(
(set updateoperation
	(askbool 
		(prompt "This appears to be an update operation. Do you wish me to leave all your current settings alone ? If you select YES, everything will be left alone, and you will not get the option to install WBLoad.")
		(help "I found found old settings. If you select YES, these will be left alone. If you select NO, I'll do the standard setup thing.")
	)
)
)
)

;Get directory to install test to:
(set destdir 
	(askdir 
		(prompt "Where should DoomGATE and its DATA directory be copied ?\nA new drawer will NOT be created.") 
		(help @askdir-help)
		(default destdir)
	)
)


;Copy program files to destination.

(copyfiles
	(source "DoomGATE.info")
	(dest destdir)
	(all)
)

(complete 20)

(copyfiles
	(source "DoomGATE.rexx")
	(dest destdir)
	(all)
)

(complete 28)

(makedir (tackon destdir "data"))

(complete 30)

(copyfiles
	(source "Data")
	(dest (tackon destdir "data"))
	(all)
)	

(complete 50)

(set docsdestdir 
	(askdir 
		(prompt "Where should the DoomGATE_Docs directory be copied ?") 
		(help @askdir-help)
		(default (destdir))
	)
)

(complete 55)

(makedir (tackon destdir "DoomGATE_Docs"))

(complete 58)

(copyfiles
	(source "DoomGATE_Docs.info")
	(dest docsdestdir)
	(all)
)

(complete 63)


(copyfiles
	(source "DoomGATE_Docs")
	(dest (tackon docsdestdir "DoomGATE_Docs"))
	(all)
)

(complete 70)

(if updateoperation (
(P_QUICKGUIDE)
(CLEANUP)
(exit "Update Operation Complete. Version "ver" installed." (quiet))
)
)

(makedir "env:DoomGate")
(makedir "envarc:DoomGate")

(set doomexe	(askfile
		(prompt "Please location your Doom executable...") 
		(help @askdir-help)
		(default (destdir))
	)
)

(set doomdir	(askdir
		(prompt "Show me the directory containing your Doom executable (I know, I know)... You probably just have to press PROCEED.") 
		(help @askdir-help)
		(default (doomexe))
	)
)

(textfile 
	(dest "env:DoomGate/Doom_Executable")
	(append doomexe)
)
(textfile 
	(dest "envarc:DoomGate/Doom_Executable")
	(append doomexe)
)
(textfile 
	(dest "env:DoomGate/Doom_Directory")
	(append doomdir)
)
(textfile 
	(dest "envarc:DoomGate/Doom_Directory")
	(append doomdir)
)
(textfile 
	(dest "env:DoomGate/Buffers")
	(append "600")
)
(textfile 
	(dest "envarc:DoomGate/Buffers")
	(append "600")
)
(textfile 
	(dest "env:DoomGate/DoomGATE_Location")
	(append destdir)
)
(textfile 
	(dest "envarc:DoomGate/DoomGATE_Location")
	(append destdir)
)



(complete 90)

(set installfiles
	(askoptions
		(prompt "Which of the following optional programs should be installed ? (All Recommended) (WBLoad © 1995-97 THOR-Software inc.)")
		(help @askoptions-help)
		(choices "WBLoad")
		(default Opt)
	)
)


(if (BITAND installfiles 1)
(copylib
	(prompt "Install WBLoad ? Required for running DoomGATE not from WB. Eg. From ToolManager or CLI")
	(help @copylib-help)
	(source "WBLoad")
	(dest "c:")
	(confirm)
)	
)

(complete 100)

(P_QUICKGUIDE)
(CLEANUP)
(exit "DoomGATE is now installed.\n\nIf you have any problems or suggestions do not\nhesitate to get in touch.\n\npcomm@inorbit.com\n" (quiet))
