; Kuang Eleven Install Script
; Copyright Ariel Magnum 1998
; $VER: Kuang_Eleven_Installer 1.0 (23.5.98)
(complete 0)
;** Set some of the strings

(set #K11Ver "3.0 Gamma")
(set #defamircdir (getenv "Vapor/AMIRC_LASTUSEDDIR"))
(set #betanote "\n\nMake sure to read ReadMeFirst.txt in this directory.")
(set #about (cat "\n\nWelcome to the Kuang Eleven " #K11Ver " installation.\n\nThe installer will now install some system files,Kuang Eleven scripts and installation data to your AmIRC directory.\nLastly it will launch AmIRC to finalise the installation.\n\nNOTE : PLEASE SHUT DOWN ALL AMIRC WINDOWS NOW OR THE INSTALLER WILL CLOSE THEM DOWN FOR YOU LATER!" #betanote))
(set #RunAmIRC "\n\nThe Installer will now run AmIRC to finalise the Installation.\n\Final stage installation will begin automatically upon starting AmIRC.\n\nPlease focus on the AmIRC application and enter your choices for customising Kuang Eleven.\nPlease do not connect to a server or do any other mischief ;)\nLoading AmIRC may take a few seconds...")
(set #MinVer "\n\nKuang Eleven requires AmIRC version 2.x.\nYou must upgrade your AmIRC to use this version of Kuang Eleven.")
(set #deltemp "\n\nDelete temporary installation file which has been installed on your system.\n")
(set #whereAmIRC "Locate the drawer where AmIRC is Installed.\nIf you don't have AmIRC Installed,Kuang Eleven will be useless to you.")
(set #noprogfile "\n\nI am not able to find your AmIRC program file which should be :\n")
(set #backupAmIRC "\n\nWould you like to backup your entire AmIRC directory now before installing Kuang Eleven?\nThis will probably take some diskspace!")
(set #wherebackup "Where would you like to place the backup?\nA directory called AmIRC_OLD_DIR will be created here.")
(set #workbackup "Backing up AmIRC directory to\n")
(set #MovingPlugin "Discovered AmIRC's XDCC plugin and moved it to UnusedPlugins directory.\n")
(set #MovingPluginConfiguration "Discovered AmIRC's XDCC plugin configuration and moved it to UnusedPlugins directory.\n")
(set #delold "Removing Uneeded file from old installation\n")
(set #askconfig "Select your AmIRC configuration file.\nThis is by default Default.AmIRCfg\nIf it is, click proceed now,no need to select.")
(set #launchmodfier "Launching a program that will modify your AmIRC configuration for Kuang Eleven.\nYour Config file will be backed-up.\nThis takes about 20 seconds.")
(set #wheresounddir "Locate your AmIRC sounds directory")
(set #modifyamircfg "Modifying AmIRC configuration.\nThis may take a few seconds...")
(set #installhelp "Installing Kuang Eleven 3 docs")
(set #nomultiview "Unable to find SYS:Utilities/Multiview to show preview of button bar")
(set #kuangwashere 1)
(set #installaliases 0)
(set #installsounds "Would you like to install the Kuang Eleven sounds to your AmIRC sounds directory?\nSome functions of Kuang Eleven may not work corectly without them.")
(message #about (all))
(welcome)
(set AmIRCdir  (askdir (prompt #whereAmIRC)
		       (help)
     		   (default #defamircdir)
 				)
)
(set @execute-dir AmIRCdir)

;** Do perliminary tests

(set #AmiRCexec (tackon AmIRCdir "AmIRC"))
(if (< (exists #AmIRCexec) 1) (exit (cat #noprogfile #AmIRCexec) (quiet)) )
(set @default-dest AmIRCdir)
(set amircvernum (getversion #AmIRCexec))
(set amircver (/ amircvernum 65536))
(set amircrev (- amircvernum (* amircver 65536)))
(if (< amircver 2)
	(exit #MinVer (quiet))
	)

;** Backup AmIRC directory

(if (askbool (prompt #backupAmIRC) (help) (default 0))
	(
		(set #backupdir (tackon (askdir (prompt #wherebackup) (help) (default (expandpath (tackon AmIRCdir "/")))) "AmIRC_OLD_DIR"))
		(if (< (exists #backupdir) 2) (makedir #backupdir))
		(working (cat #workbackup #backupdir))
		(copyfiles
			(prompt (cat "Copying AmIRC directory to\n" #backupdir))
			(help @copyfiles-help)
			(source AmIRCdir)
			(dest #backupdir)
			(confirm)
			(all)
			(optional nofail)
		)
	)
)
;** Create directory

(set #dest (tackon AmIRCdir "Kuang11"))
(if (< (exists #dest) 2)
	(
	(set #kuangwashere 0)
	(makedir #dest)
	)
)
(set #k11dir #dest)

(complete 1)

;** Start main installation

;** Install Executables

(Working "Installing Libraries")
(foreach "InstallData" "#?.library"
	(
		(set #srcfile (tackon "Installdata" @each-name))
		(copylib
			(prompt (cat "Install Library\n" #srcfile "\nto LIBS:"))
			(help @copylib-help)
			(source #srcfile)
			(dest "LIBS:")
			(confirm)
			(optional fail)
		)
	)
)
(complete 4)

(Working "Installing Muirexx")
(set #srcfile (tackon "Installdata" "MuiRexx"))
(copylib
		(prompt "Install MUIREXX executable\nDirectory MUST be SYS:REXXC")
		(help @copylib-help)
		(source #srcfile)
		(dest "SYS:REXXC")
		(confirm)
		(optional fail)
)
(complete 5)

(set #srcfile (tackon "Installdata" "Icon.mcc"))
(copylib
		(prompt "Install MUIREXX support file Icon.mcc")
		(help @copylib-help)
		(source #srcfile)
		(dest "mui:libs/mui")
		(confirm)
		(optional fail)
)
(complete 6)

(set #srcfile (tackon "Installdata" "Kuang11Alias.AmIPlug"))
(copylib
		(prompt "Install Kuang Eleven Aliases Plugin")
		(help @copylib-help)
		(source #srcfile)
		(dest (tackon AmIRCdir "Plugins"))
		(confirm)
		(optional fail)
)
(complete 8)

(set #srcfile (tackon "Installdata" "ZED_HTTPGET"))
(copylib
		(prompt "Install Kuang Eleven httpget executable")
		(help @copylib-help)
		(source #srcfile)
		(dest "C:")
		(confirm)
		(optional fail)
)
(complete 10)

;** Install Kuang Eleven Data files if needed

(set #helpstring "Installing Kuang Eleven generic configuration")
(Working #helpstring)
(set #dest (tackon #k11dir "Config"))
(if (= (exists  #dest) 0) (copyfiles
	(prompt #helpstring)
	(help @copyfiles-help)
	(source "InstallData/Config")
	(dest #k11dir)
	(confirm)
	(optional fail)
))
(complete 11)

(set #helpstring "Installing Kuang Eleven image files")
(Working #helpstring)

(set #dest (tackon #k11dir "Images"))
(if (= (exists  #dest) 0) (makedir #dest))

(copyfiles
	(prompt #helpstring)
	(help @copyfiles-help)
	(source "InstallData/Images")
	(dest #dest)
	(confirm)
	(all)
	(optional fail)
)
(complete 12)

(set #helpstring "Installing Kuang Eleven Away Reasons file")
(Working #helpstring)

(set #dest (tackon #k11dir "AwayReasons"))
(if (= (exists  #dest) 0) (copyfiles
	(prompt #helpstring)
	(help @copyfiles-help)
	(source "InstallData/AwayReasons")
	(dest #k11dir)
	(confirm)
	(optional fail)
))
(complete 13)

(set #helpstring "Installing empty Custom_CTCP.amirx to suppress unknown CTCP commands alarms")
(Working #helpstring)

(set #dest (tackon AmIRCdir "Rexx/Custom_CTCP.amirx"))
(if (= (exists  #dest) 0) (copyfiles
	(prompt #helpstring)
	(help @copyfiles-help)
	(source "InstallData/Custom_CTCP.amirx")
	(dest (pathonly #dest))
	(confirm)
	(optional fail)
))
(complete 14)

;** Takeout the AmIRC XDCC Plugin

(working #MovingPlugin)
(if (= (exists (tackon AmIRCdir "Plugins/xdcc.amiplug")) 1)
	(
		(if (< (exists (tackon AmIRCdir "UnusedPlugins")) 2) (makedir (tackon AmIRCdir "UnusedPlugins")))
		(if (> (exists (tackon AmIRCdir "UnusedPlugins/xdcc.amiplug")) 0) (delete (tackon AmIRCdir "UnusedPlugins/xdcc.amiplug")))
		(rename (tackon AmIRCdir "Plugins/xdcc.amiplug") (tackon AmIRCdir "UnusedPlugins/xdcc.amiplug") (confirm) (prompt #MovingPlugin) (help))
	)
)
(complete 15)

(working #MovingPluginConfiguration)
(if (= (exists (tackon AmIRCdir "Plugins/XDCC_Prefs")) 1)
	(
		(if (< (exists (tackon AmIRCdir "UnusedPlugins")) 2) (makedir (tackon AmIRCdir "UnusedPlugins")))
		(if (> (exists (tackon AmIRCdir "UnusedPlugins/XDCC_Prefs")) 0) (delete (tackon AmIRCdir "UnusedPlugins/XDCC_Prefs")))
		(rename (tackon AmIRCdir "Plugins/XDCC_Prefs") (tackon AmIRCdir "UnusedPlugins/XDCC_Prefs") (confirm) (prompt #MovingPluginConfiguration) (help))
	)
)
(complete 16)


;** Install Arexx scripts

(set #dest (tackon AmIRCdir "Rexx"))
(set #helpstring "Installing Kuang Eleven AREXX scripts")
(Working #helpstring)
(if (< (exists #dest) 2) (makedir #dest) )


(if (= (getversion (tackon #dest "connected.amirx")) 0)
	(copyfiles
		(prompt #helpstring)
		(help @copyfiles-help)
		(source "Rexx")
		(dest #dest)
		(confirm)
		(all)
		(optional fail)
	)
	(
		(foreach "Rexx" "#?.amirx"
			(
				(set #srcfile (tackon "Rexx" @each-name))
				(copylib
					(prompt (cat "Install Script\n" #srcfile))
					(help @copylib-help)
					(source #srcfile)
					(dest #dest)
					(confirm)
					(optional fail)
				)
			)
		)
		(complete 30)
		(set #dest (tackon (tackon AmIRCdir "Rexx") "Pub"))
		(foreach "Rexx/Pub" "#?.amirx"
			(
				(set #srcfile (tackon "Rexx/Pub" @each-name))
				(copylib
					(prompt (cat "Install Script\n" #srcfile))
					(help @copylib-help)
					(source #srcfile)
					(dest #dest)
					(confirm)
					(optional fail)
				)
			)
		)
		(complete 40)
		(set #dest (tackon (tackon AmIRCdir "Rexx") "CTCP"))
		(foreach "Rexx/CTCP" "#?.amirx"
			(
				(set #srcfile (tackon "Rexx/CTCP" @each-name))
				(copylib
					(prompt (cat "Install Script\n" #srcfile))
					(help @copylib-help)
					(source #srcfile)
					(dest #dest)
					(confirm)
					(optional fail)
				)
			)
		)
	)
)
(complete 50)
(Working #installhelp)
(copyfiles
	(prompt #installhelp)
	(help @copyfiles-help)
	(source "Kuang_Eleven.guide")
	(dest AmIRCdir)
	(confirm)
	(all)
	(infos)
	(optional fail)
)
(complete 51)
(copyfiles
	(prompt #installhelp)
	(help @copyfiles-help)
	(source "KSMaster.guide")
	(dest AmIRCdir)
	(confirm)
	(all)
	(infos)
	(optional fail)
)
(copyfiles
	(prompt #installhelp)
	(help @copyfiles-help)
	(source "AmiHunter.guide")
	(dest AmIRCdir)
	(confirm)
	(all)
	(infos)
	(optional fail)
)
(complete 52)
(copyfiles
	(prompt #installhelp)
	(help @copyfiles-help)
	(source "ReadmeFirst.txt")
	(dest AmIRCdir)
	(confirm)
	(all)
	(infos)
	(optional fail)
)
(complete 53)
(set #multiview "run sys:utilities/multiview Installdata/Buttons.iff")
(set #installbuttons "Would you like to install the 24 Special buttons for the AmIRC buttons window(recommended)?\nThis will overwrite your first 24 buttons.")
(if (= (exists "SYS:Utilities/multiview") 1)
	(
		(set #multiviewvernum (getversion "SYS:Utilities/Multiview"))
		(set #multiviewver (/ #multiviewvernum 65536))
		(set #multiviewrev (- #multiviewvernum (* #multiviewver 65536)))
		(set #newmultiview (OR (> #multiviewver 40) (AND (= #multiviewver 40) (>= #multiviewrev 8))))
		(debug #newmultiview #multiviewver #multiviewver)
		(if #newmultiview (set #multiview (cat #multiview " PORTNAME MULTIKUANG")))
		(debug #multiview)
		(textfile (dest "T:killmultiview.rexx") (append "/**/\nAddress MULTIKUANG QUIT") (safe))
		(run #multiview (safe))
	)
	(set #installbuttons (cat #installbuttons "\n" #nomultiview))
)
(complete 55)
(set #instbut (askbool (prompt #installbuttons) (help) (default 1)))
(rexx "T:killmultiview.rexx" (safe))
(complete 75)
(set #amircfg (askfile (prompt #askconfig) (help) (default (tackon AmIRCdir "Default.AmIRCfg"))))
(if (= (exists #amircfg) 2) (set #amircfg (tackon #amircfg "Default.AmIRCfg")))
(set #newamircfg (tackon #k11dir "NewConfig"))
(copyfiles
	(source (tackon #k11dir "Config"))
	(dest #k11dir)
	(newname "Config.bak")
	(optional fail)
)

(working #modifyamircfg)

(run "SYS:System/Rexxmast >T:rexxmast" (safe))
(textfile (dest "T:Kuang_11_amirdir") (append AmIRCdir) (safe))
(textfile (dest "T:Kuang_11_amircfg") (append #amircfg) (safe))
(textfile (dest "T:Kuang_11_newamircfg") (append #newamircfg) (safe))
(textfile (dest "T:Kuang_11_installoptions") (append #instbut) (safe))
(rexx (tackon "Installdata" "install.rexx") (confirm) (prompt #launchmodfier) (help) (safe))
(complete 80)

(if (= (exists #newamircfg) 0) (exit (cat "Failed to create modified AmIRC configuration from :\n" #amircfg "\nto :\n" #newamircfg "\n\nA possible reason may be that the filenames have spaces in them.") (quiet)))
(copyfiles
	(source #amircfg)
	(dest (pathonly #amircfg))
	(newname (cat (fileonly #amircfg) ".bak"))
	(optional fail)
)
(complete 81)
(if (= (getenv "Kuang_11_rexxmast") 1) (startup "SYS:System/Rexxmast >NIL:" (prompt "The installer has found that RexxMast is not started on this system.\nWill now start it on your user-startup.") (help "RexxMast is essential to all AREXX scripts and should be run on startup\nWithout it,Kuang Eleven will not function AT ALL.\nUse this feature in the Installer to insert it to your user-startup.") (confirm)) )
(set #sounddir (getenv "Kuang_11_sounddir"))
(delete "ENV:Kuang_11_sounddir")
(delete "T:Kuang_11_amircdir")
(delete "T:Kuang_11_amircfg")
(delete "T:Kuang_11_newamircfg")
(delete "T:Kuang_11_installoptions")
(delete "ENV:Kuang_11_rexxmast")
(delete "T:rexxmast")

(delete #amircfg)
(rename #newamircfg #amircfg)

(if (askbool (prompt #installsounds) (help) (default 1))
	(
		(working "Installing sounds")
		(copyfiles
			(prompt "Installing sounds to your sounds directory")
			(help @copyfiles-help)
			(source "InstallData")
			(dest (askdir (prompt #wheresounddir) (help) (default #sounddir)))
			(confirm)
			(pattern "#?.WAV")
			(optional fail)
		)
	)
)

(complete 85)
(if (= (exists (tackon #k11dir "Aliases")) 0) (set #installaliases 1))

(if (= (getversion (tackon #k11dir "Aliases")) 0)
	(copyfiles
		(source "InstallData/Aliases")
		(dest #k11dir)
		(optional fail)
		(help @copyfiles-help)
		(prompt "Installing Kuang Eleven aliases plugin configuration")
		(confirm)
	)
	(copylib
		(prompt "Installing Kuang Eleven aliases plugin configuration")
		(help @copylib-help)
		(source "InstallData/Aliases")
		(dest #k11dir)
		(confirm)
		(optional fail)
	)
)
(complete 86)
(Working "Installing KMaster Kicks datafiles")
(set #srcdir (tackon "InstallData" "KSKicks"))
(set #dest (tackon #k11dir "KSKicks"))
(if (< (exists #dest) 2) (makedir #dest))
(foreach #srcdir "#?.ksm"
	(
		(set #srcfile (tackon #srcdir @each-name))
		(copylib
			(prompt (cat "Install Datafile\n" #srcfile))
			(help @copylib-help)
			(source #srcfile)
			(dest #dest)
			(confirm)
			(optional fail)
		)
	)
)
(complete 89)
(Working "Installing KMaster Sayings datafiles")
(set #srcdir (tackon "InstallData" "KSSay"))
(set #dest (tackon #k11dir "KSSay"))
(if (< (exists #dest) 2) (makedir #dest))
(foreach #srcdir "#?.ksm"
	(
		(set #srcfile (tackon #srcdir @each-name))
		(copylib
			(prompt (cat "Install Datafile\n" #srcfile))
			(help @copylib-help)
			(source #srcfile)
			(dest #dest)
			(confirm)
			(optional fail)
		)
	)
)
(complete 93)
(Working "Installing KMaster Greets datafiles")
(set #srcdir (tackon "InstallData" "KSGreets"))
(set #dest (tackon #k11dir "KSGreets"))
(if (< (exists #dest) 2) (makedir #dest))
(foreach #srcdir "#?.ksm"
	(
		(set #srcfile (tackon #srcdir @each-name))
		(copylib
			(prompt (cat "Install Datafile\n" #srcfile))
			(help @copylib-help)
			(source #srcfile)
			(dest #dest)
			(confirm)
			(optional fail)
		)
	)
)
(complete 96)
;** Remove obsolete Kuang Eleven files

(set #dest (tackon AmIRCdir "Kuang_Eleven"))
(working #delold #dest)
(if (> (exists #dest) 0) (delete #dest (prompt (cat #delold #dest)) (help) (confirm) (infos)))

(set #dest (tackon AmIRCdir "Rexx/kuang11pub.amirx"))
(working #delold #dest)
(if (> (exists #dest) 0) (delete #dest (prompt (cat #delold #dest)) (help) (confirm) (infos)))

(set #dest (tackon AmIRCdir "Rexx/pager.amirx"))
(working #delold #dest)
(if (> (exists #dest) 0) (delete #dest (prompt (cat #delold #dest)) (help) (confirm) (infos)))

(set #dest (tackon AmIRCdir "Rexx/custum_ctcp.amirx"))
(working #delold #dest)
(if (> (exists #dest) 0) (delete #dest (prompt (cat #delold #dest)) (help) (confirm) (infos)))

(set #dest (tackon AmIRCdir "Rexx/borg.amirx"))
(working #delold #dest)
(if (> (exists #dest) 0) (delete #dest (prompt (cat #delold #dest)) (help) (confirm) (infos)))

(set #dest (tackon AmIRCdir "Rexx/butt.amirx"))
(working #delold #dest)
(if (> (exists #dest) 0) (delete #dest (prompt (cat #delold #dest)) (help) (confirm) (infos)))

(set #dest (tackon AmIRCdir "Rexx/momma.amirx"))
(working #delold #dest)
(if (> (exists #dest) 0) (delete #dest (prompt (cat #delold #dest)) (help) (confirm) (infos)))

(set #dest (tackon AmIRCdir "Rexx/philosophy.amirx"))
(working #delold #dest)
(if (> (exists #dest) 0) (delete #dest (prompt (cat #delold #dest)) (help) (confirm) (infos)))

(set #dest (tackon AmIRCdir "Rexx/pinkybrain.amirx"))
(working #delold #dest)
(if (> (exists #dest) 0) (delete #dest (prompt (cat #delold #dest)) (help) (confirm) (infos)))

(set #dest (tackon AmIRCdir "Rexx/rin.amirx"))
(working #delold #dest)
(if (> (exists #dest) 0) (delete #dest (prompt (cat #delold #dest)) (help) (confirm) (infos)))

(set #dest (tackon AmIRCdir "Rexx/splatt.amirx"))
(working #delold #dest)
(if (> (exists #dest) 0) (delete #dest (prompt (cat #delold #dest)) (help) (confirm) (infos)))

(set #dest (tackon AmIRCdir "Rexx/kinstall.amirx"))
(working #delold #dest)
(if (> (exists #dest) 0) (delete #dest (prompt (cat #delold #dest)) (help) (confirm) (infos)))

(set #dest (tackon AmIRCdir "Rexx/say.amirx"))
(working #delold #dest)
(if (> (exists #dest) 0) (delete #dest (prompt (cat #delold #dest)) (help) (confirm) (infos)))
(complete 99)
; Finalise installation

(if (AND (= #installaliases 1) (= #kuangwashere 1))
	(
	(copyfiles
		(prompt "Installing second phase installation initiator")
		(help @copyfiles-help)
		(source "InstallData/Startup.amirx")
		(dest (tackon AmIRCdir "Rexx"))
		(optional fail)
		(confirm)
		(safe)
	)
	(set @execute-dir AmIRCdir)
	(message #RunAmIRC)
	(run "run AmIRC" (safe))
	)
)
(complete 100)
(exit)
