; $VER: MQwkID Install 1.00 (12.25.94) by Jason Gouger

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

(procedure install-exit
	(complete 100)
	(transcript "\nPlease support the ShareWare concept.\n")
	(set @default-dest MQwkID-Dir)
	(exit @app-name" is ShareWare\n\nPlease support the ShareWare concept!\n\n"
			"Registrations have been VERY slim over the past few months, "
			"and I know more than 5 of you are using MQwkID.  Please, do NOT make"
			" me cripple this door in order for Sysop's/User's to register MQwkID!")
)

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

(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 MQwkID-Dir(tackon destdir "MQwkID"))
	(set Text-Dir(tackon MQwkID-dir "Text"))
	(set Config-Dir(tackon MQwkID-dir "Config"))
)

(procedure copy-icons
	(if(= 1 install-icons) (
		(transcript "\nCopying info files...\n")
		(copyfiles
			(source source-dir) (dest MQwkID-Dir)
			(choices "Text.info" "Config.info")
			(files)
		)
	))
)

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

(procedure copy-mqwkid-prg
	(copyfiles
		(source source-dir) (dest MQwkID-Dir)
		(pattern "MQwkID")
		(files)
		(if(= 1 install-icons) (infos))
	)
)

(procedure copy-mqwkid-intro
	(transcript "\nCopying introduction files...\n")
	(copyfiles
		(source source-dir) (dest MQwkID-Dir)
		(pattern "MQwkID.txt")
		(files)
		(if(= 1 install-icons) (infos))
	)
)

(procedure copy-mqwkid-cfg
	(transcript "\nCopying configuration file...\n")
	(copyfiles
		(source (tackon source-dir "Config")) (dest Config-Dir)
		(pattern "MQwkID.CFG")
		(files)
		(if(= 1 install-icons) (infos))
	)
)

(procedure copy-mqwkid-strings
	(transcript "\nCopying strings file...\n")
	(copyfiles
		(source (tackon source-dir "Config")) (dest Config-Dir)
		(pattern "MQwkID.Str")
		(files)
		(if(= 1 install-icons) (infos))
	)
)

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

(procedure add-mqwkid-menu
	(if (askbool
		(prompt "Would you like to add the MQwkID program to a menu?")
		(help "Selecting YES to thie option will allow you to add MQwkID to "
					"a menu.  If you choose no, you must add the Door to a menu manually."))
		((set menu-file (askfile
			(prompt "Select the Menu File you would like the MQwkID added to.")
			(help "Select a valid NON COMPILED MENU FILE (#?.Menu) for the menu option "
					"to be appended.")
			(default "MEBBSNet:Menus/MessageMenu.Menu"))
		)

		(if (= 1 (exists menu-file)) (
			(set menuop "xx")
			(while (< 1 (strlen menuop))
			(set menuop
				(askstring
				(prompt "Select a valid MEBBSNet menu character that is NOT currently in "
						  "the menu file:\n'"menu-file"':")
		   	(default "")
			   (help "Choose ONE character to activate the MQwkID door.  This character "
						"will be added as a menu option to access the door.\n\nNote: This "
						"character MUST be a VALID menu character.")
			))
			(if (= 1 (strlen menuop))
				((set menu-text ("\nOption '%s':\n   Function MultiRunDoor %s\n   end" menuop (tackon MQwkID-Dir "MQwkID")))
				(set dash-txt "--------------------------------------------------")
				(if (askbool
					(prompt "Are you sure you would like to append the the following menu option "
							  "to the Menu File '"menu-file"'?\n\n\n"dash-txt menu-text "\n" dash-txt"\n\n")
					(help "Selecting YES to this option will append:\n\n"dash-txt menu-text "\n" dash-txt"\n\n"
							"to the '"menu-file"' file.\n\n"
							"Warning: If you select an incorrect menu/option you may corrupt your "
							"menu configuration file!"))
					((textfile (dest menu-file) (include menu-file) (append (cat menu-text "\n")))
						(set @execute-dir (pathonly menu-file))
						(run (cat "MEBBSNet:c/MenuCompiler " (fileonly menu-file))))
				)
			))))
		)
	))
)

(procedure ask-install-icons
	(set install-icons 0)
	(if (askbool
		(prompt "Would you like the icons installed for MQwkID?")
		(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 mqwkid-update-install
	(if(askbool
		(prompt "You currently have "@app-name" installed, would you like to "
				  "Update "@app-name"?")
		(help "If you select YES to update, only the files that have changed since the "
				"LAST version will be copied, otherwise the complete package will be "
				"installed.\n\nNote: Old Files WILL be OVERWRITTEN, "
				"so make sure you make backups of older files if desired."))
		(if(askbool
			(prompt "Updating from VERSION 0.15 to 1.00\n\nWARNING the following "
					  "files will be OVERWRITTEN:\n\n MQwkID\nMQwkID.txt\nNews.txt\n"
					  "MQwkID.guide\n\nAre you sure you would like to continue?")
			(help "If you select YES to this option, older files will be OVERWRITTEN, "
					"and the new version will be installed."))
			((transcript "\nUpdate Installation...\n")
			(complete 30) (ask-install-icons)
			(complete 40) (copy-icons)
			(complete 50) (copy-mqwkid-prg)
			(complete 60) (copy-mqwkid-intro)
			(complete 75) (copyfiles
				(source (tackon source-dir "Text")) (dest Text-Dir)
				(pattern "News.txt")
				(files)
				(if(= 1 install-icons) (infos))
			)
			(complete 90) (copy-mqwkid-doc)
			(install-exit)) 
		(install-exit)))
	((message "Renaming '"MQwkID-Dir"' to '"MQwkID-Dir"-Old'.")
	 (rename MQwkID-Dir (cat MQwkID-Dir "-Old")))
)

(procedure mqwkid-full-install
	(transcript "\nFull Installation...\n")
	(complete 15) (ask-install-icons)
	(complete 20) (set make-dir MQwkID-Dir) (make-directory)
	(complete 25) (makedir(tackon MQwkID-Dir "QwkWaiting"))
	(complete 30) (copy-icons)
	(complete 35) (copy-mqwkid-prg)
	(complete 40) (copy-mqwkid-intro)
	(complete 50) (copy-mqwkid-cfg)
	(complete 60) (copy-mqwkid-strings)
	(complete 70) (copy-mqwkid-text)
	(complete 80) (copy-mqwkid-doc)
	(complete 90) (add-mqwkid-menu)
	(install-exit)
)

(complete 00) (transcript "Installation script for " @app-name ".")
(complete 10) (select-destination-directory)
(if(exists MQwkId-Dir (noreq)) (mqwkid-update-install))
(mqwkid-full-install)
