; $VER: LineID Install 1.00 (01.15.94) by Jason Gouger

(set source-dir (pathonly (expandpath @icon)))

(procedure install-exit
	(complete 100)
	(set @default-dest LineID-Dir)
	(exit "Note: UserID significantly increases the speed of LineID.  Please see the documentation for more information.")
)

(procedure select-destination-directory
	(set destdir
		(askdir
			(prompt "In which drawer should "@app-name" be installed?") 
			(help "You should install "@app-name" in the Doors Path defined in the MEBBSNet configuration.")
			(default "DOORS:")
		   (newpath)
		)
	)
	(set LineID-Dir(tackon destdir "LineID"))
)

(procedure copy-LineID-text
	(set Text-Dir(tackon LineID-dir "Text"))
	(transcript "\nCopying LineID.[txt] files...\n")
	(makedir(Text-Dir))
	(copyfiles
		(source (tackon source-dir "Text")) (dest Text-Dir)
		(pattern "LineID.#?")
		(files)
		(if(= 1 install-icons) (infos))
	)
)

(procedure copy-LineID-prg
	(copyfiles
		(source source-dir) (dest LineID-Dir)
		(pattern "LineID")
		(files)
	)
)

(procedure copy-LineID-doc
	(transcript "\nCopying documentation...\n")
	(copyfiles
		(source source-dir) (dest LineID-Dir)
		(pattern "LineID.guide")
		(files)
		(if(= 1 install-icons) (infos))
	)
	(if ((exists "SYS:Utilities/MultiView")) 
		(tooltype(
			(dest (tackon LineID-Dir "LineID.guide"))
			(setdefaulttool "SYS:Utilities/MultiView")
		))
		(tooltype(
			(dest (tackon LineID-Dir "LineID.guide"))
			(setdefaulttool "SYS:Utilities/AmigaGuide")
		))
	)
)

(procedure add-LineID-logon
	(if (askbool
		(prompt "Would you like the "@app-name" door appended to your Logon.[txt] file(s)?")
		(help "Selecting YES to this option will append the "@app-name" Door call to the "
            "end of your Logon.[txt] file(s). followed by a 'Press return'."))
		((set logon-txt-dir
			(askdir
				(prompt "In which drawer are the LogOn.[txt] file(s) located?") 
				(help "Select the directory in which the MEBBSNet text files are stored.")
				(default "MEBBSNet:Txt")
			   (newpath)
			)
		)

		(if (= 2 (exists logon-txt-dir))
			((set logon-text "\n~v!DOOR/")
			(set logon-text (cat logon-text LineID-Dir))
			(set logon-text (cat logon-text "/LineID#\n\n~vc\n"))

			(if (askbool
				(prompt "Are you sure you would like to have the following appended to "
						  "your LogOn.[txt] file(s)?\n\n"logon-text)
				(help "Selecting YES to this option will ALTER your LogOn.[txt] file(s) "
						"so that "@app-name" will be executed upon logon."))
				((foreach logon-txt-dir "(LogOn.txt|LogOn.gr#?)"
					((set source-name (tackon logon-txt-dir @each-name))
					(textfile 
						(dest source-name) 
						(include source-name)
						(append logon-text)
						(prompt "Are you sure you would like to have the following appended to "
								  "the '"source-name"' file?\n\n"logon-text)
						(help "Selecting YES to this option will ALTER the '"source-name"' file "
								"so that "@app-name" will be executed upon logon.")
						(confirm "Expert") 
					))
				))
			)
		))
	))
)

(procedure make-LineID-dir
	(if(= 0 install-icons) (makedir(LineID-Dir)))
	(if(= 1 install-icons) (makedir(LineID-Dir) (infos)))
)

(procedure ask-install-icons
	(set install-icons 0)
	(if (askbool
		(prompt "Would you like the icons installed for "@app-name"?")
		(help "Selecting YES to this option will create the respective icons so that "
				"the directory and documentation may be accessed through WorkBench."))
		((set install-icons 1))
	)
)

(procedure LineID-full-install
	(transcript "\nFull Installation...\n")
	(complete 20) (ask-install-icons)
	(complete 30) (make-LineID-dir)
	(complete 50) (copy-LineID-prg)
	(complete 70) (copy-LineID-text)
	(complete 80) (copy-LineID-doc)
	(complete 90) (add-LineID-logon)
	(install-exit)
)

(complete 00) (transcript "Installation script for " @app-name ".")
(complete 10) (select-destination-directory)
(LineID-full-install)
