;VirusCheckerII's New Installer Script
;
;$VER: Virus_CheckerII_Installer v1.01 (20.10.98) ß1998 by Alex van Niel


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Get the version and revision number of file/device/library/OS/etc
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Taken from original Installer Script of Virus_Checker and Virus_CheckerII
;
; INPUTS: Item	; Name of device/file/library/etc. "" for OS version
;
; OUTPUTS: VerN		; (long) version/revision number
;          Ver		; Version number
;          Rev		; Revision number
; NOTE: Both Ver and Rev returned as 0 if "WV_Item" does not exist
;
(procedure WhatVersion
    (
    (if (= VerN "")
        (set VerNum (getversion))		; For OS
        (set VerNum (getversion VerN)))	; For other "files"
    (set Ver (/ VerNum 65536))
    (set Rev (- VerNum (* Ver 65536)))
    )
)

(procedure P_setvcenv
	(

		(set #vcpath_env	(cat
								("setenv Virus_Checker_Path \"%s\"\n" @default-dest)
								("copy env:Virus_Checker_Path envarc: quiet\n")
							)
		)

		(textfile
			(dest "T:VCEnvSet")
			(append #vcpath_env)
		)

		(execute "T:VCEnvSet")
		(delete "T:VCEnvSet")
	)
)

	(set	#hail		(cat    "VirusCheckerII Installation Utility\n\n"
								"VirusCheckerII is ShareWare,\n"
								"please consider registering.\n\n"
								"VirusCheckerII is (c)1997/1998 by Alex van Niel\n"
								"Virus_Checker is (c)1990/1995 by John Veldthuis\n"
						)
	)
	(set    #fullinstall	"Full Install")
	(set	#update		"Update")
	(set	#where_vc	(cat	"First, please select the directory to put Virus_CheckerII in.\n\n"
								"The Installer will create a drawer called \'Virus_CheckerII\' "
								"where all the files are put into. You don't need to make "
								"one yourself."
						)
	)
	(set	#whatinstall	(cat	"Would you like to install VirusCheckerII fully "
								"or do you want to update a currently installed version?"
						)
	)
	(set	#installhelp    (cat	"Full Install, installs the complete program, "
									"update, installs only the files that are new or not "
									"yet present.\n"
									"Libraries, the latest brainfile and the main executable "
									"are good examples of files that would possibly be copied "
									"if they have been changed since the last release."
							)
    )
	(set	#allfiles		"Copying all files from distribution archive")
	(set	#copyallfiles	(cat	"The Installer is about to copy all the files from the "
									"distribution archive to \"%s\". It will not check "
                					"the versions of the files, so beware.\n\n"
									"If you already have installed, VirusCheckerII and want "
									"to update it, please press abort, start the installer again and choose "
									"update instead."
							)
	)
	(set	#none			"None")
	(set	#bestplace		(cat	"The best place to have VirusCheckerII started from is from the User-startup "
									"that way it can monitor the system as early as possible and allowable. "
									"You can also choose WBStartup for easy acces and still a pretty good safety "
									"Choose User-Startup if you want to have the installer add a line to your "
									"User-Startup, else choose WBStartup and the installer will copy a special "
									"icon to the WBStartup drawer, or None if you aren't sure yet and want to decide later."
							)
	)
	(set	#vcrunfrom		(cat	"To have VirusCheckerII start as early as possible, choose User-Startup "
									"and the installer will add a line to your User-Startup. VirusCheckerII will then "
									"automatically startup when you boot your system.\n\n"
									"To have VirusCheckerII start from your WBStartup, choose the related button. "
									"The installer will copy a special icon to the WBStartup and VirusCheckerII will "
									"be started when your workbench is launched.\n\n"
									"If you aren\'t sure when you want VirusCheckerII to be started, just press None "
									"that way you can choose later."
							)
	)
	(set	#vcrunchoose	"Please choose how/when you want VirusCheckerII to be started...")
    (set	#adddat			"The installer needs to add the following line to your \s:User-Startup\ file\n\n%s")

    (set	#copyvcbrain	"Copying VirusChecker.brain")
    (set	#copyxfdlib		"Copying xfdmaster.library")
    (set	#copybguilib	"Copying bgui.library")
    (set	#copyxfddecrs	"Copying XFD external decrunchers, please choose which ones to install")
	(set    #copyxvslib		"Copying Xvs.Library")

	(set	#copyinglibs	"The installer is about to install the libraries supplied with this archive into LIBS:, ")

    (set	#copyvcproject	"Copying and Adjusting VirusChecker startup Icon")
	(set	#adjtooltype	"Adjusting ToolType")
	(set	#makevcdir      "Creating VirusCheckerII drawer")
	(set	#skip			"Skip this part")
	(set	#proceed		"Proceed")
	(set	#proceedhelp	(cat	"Press \'Proceed\' to install the part, or press skip if you don't want "
									"to install that particular part but do want to continue installing "
									"Virus_CheckerII. You could also press Abort Install to stop the complete "
									"installation."
							)
	)
	(set	#upd-guide		"Updating Guide")
	(set	#upd-main		"Updating Virus_CheckerII")
	(set	#upd-brain		"Updating VirusChecker.brain")
	(set	#upd-xvs		"Updating Xvs.Library")
	(set	#updating		(cat	"The installer is about to update Virus_CheckerII in\n"
									"\'%s\'.\n"
									"Is this correct?\n"
									"(If you want to have Virus_CheckerII updated in another directory, "
									"then press \'No\' and you will automatically get a requester to "
									"choose the correct drawer)\n"
									"If you have not installed Virus_CheckerII fully before, then "
									"I recommend that you abort this installation for now and choose "
									"\'Full Install\' instead."
							)
	)
	(set	#versions		(cat
									"Currently installed versions that might be updated:\n\n"
									"Virus_CheckerII v%ld.%ld\n"
									"VirusChecker.brain v%ld.%ld\n"
									"VirusChecker.guide v%ld.%ld\n"
									"Xvs.Library v%ld.%ld\n\n"
									"Versions in archive:\n"
									"Virus_CheckerII v%ld.%ld\n"
									"VirusChecker.brain v%ld.%ld\n"
									"VirusChecker.guide v%ld.%ld\n"
									"Xvs.Library v%ld.%ld\n"
									"(Files that have version 0.0 are in fact not installed)"
							)
	)
    (set	#install_dir	"Please specify where VirusCheckerII should be installed\n(A drawer will be created here)")
	(set	#update_dir		"Please specify path of already installed VirusCheckerII")

    (set	#needtoreset	(cat	"Virus_CheckerII is an Anti Virus utility which is worked upon almost "
									"24hrs a day. Though, problems might rise in spite of this. Most of these "
									"problems however are caused by not or half reading the documentation. "
									"A lot of problems can be solved or even prevented by reading the documenation. "
									"I therefore recommend that you read the documentation from front to back. It "
									"might happen that some problems are not solved even then, if so, feel free to "
									"contact me. How can be found in the documentation.\n\n"
									"I personally recommend that you also reset your computer now so that Virus_CheckerII "
									"can start properly."
                       )
    )

	(set	#yes			"Yes")
	(set	#no				"No")

(welcome)
(message #hail)

(set	#dofull	(askbool	(default 1)
							(prompt #whatinstall)
							(help #installhelp)
							(choices #fullinstall #update)
				)
)

(if #dofull

	(
		(complete	0)
		(message #where_vc)
		(set	#vcpath		(askdir	(prompt #install_dir)
									(help @askdir-help)
									(default @default-dest)
							)
		)

		(set    @default-dest	(tackon #vcpath "Virus_CheckerII"))

		(P_setvcenv)

		(	;copying all the files from the distribution
			(message	(#copyallfiles	@default-dest))
			(copyfiles	(prompt	#allfiles)
						(source	"")
						(dest	@default-dest)
						(all)
						(infos)
						(optional nofail askuser )
			)

			(complete	45)

			(set	#user	(askbool	(default 1)
										(prompt #copyinglibs)
										(help #proceedhelp)
										(choices #proceed #skip)
							)
			)

			(if #user

				(
					(complete	50)

					(copylib (prompt #copyxfdlib)
						(help @copylib-help)
						(source "libs/xfdmaster.library")
						(dest "LIBS:")
						(optional nofail askuser)
					)

					(complete	60)

					(copylib (prompt #copybguilib)
						(help @copylib-help)
						(source "libs/bgui.library")
						(dest "LIBS:")
						(optional nofail askuser)
					)

					(complete	70)

		            (copyfiles (prompt #copyxfddecrs)
						(help @copyfiles-help)
						(source "libs/xfd")
						(dest "LIBS:xfd")
						(all)
						(optional nofail askuser)
						(confirm)
        		    )

					(complete 80)

					(copylib (prompt #copyxvslib)
						(help @copylib-help)
						(source "libs/Xvs.library")
						(dest "LIBS:")
						(optional nofail askuser)
					)


				)

			)
        )

		(complete	90)

		(
			(message	#vcrunfrom)
			(set	#vc-startup	(askchoice
									(prompt #vcrunchoose)
									(help #bestplace)
									(default 0)
									(choices "User-Startup" "WBStartup" #none)
								)
			)
			(if (= #vc-startup 0)
				(
					(set	#vc-cmd	(tackon @default-dest "Virus_CheckerII"))
					(startup @app-name	(prompt (#adddat #vc-cmd))
										(help @startup-help)
										(command #vc-cmd)
					)
					(copylib (prompt #copyvcbrain)
						(help @copylib-help)
						(source "VirusChecker.brain")
						(dest "L:")
						(optional nofail askuser)
					)

				)
			)

			(if (= #vc-startup 1)
				(
					(copyfiles	(prompt #copyvcproject)
								(help @copylib-help)
								(source "VC_II_Project.info")
								(dest "SYS:WBStartup/")
								(newname "Virus_CheckerII.info")
								(optional nofail askuser)
					)

					(set #vcprojecttool (tackon @default-dest "Virus_CheckerII"))
					(tooltype
						(prompt #adjtooltype)
						(dest "SYS:WBStartup/Virus_CheckerII")
						(setdefaulttool #vcprojecttool)
					)
				)

			)
			(if (= #vc-startup 2)
			)

			(complete	100)

		)

	)	;then statement

	(	;else statement

		(complete	0)

		(if (= (exists "ENV:Virus_Checker_Path" (noreq)) 1)

			(set @default-dest (getenv "Virus_Checker_Path"))

			(
				(set	#updpath	(askdir	(prompt #update_dir)
											(help @askdir-help)
											(default @default-dest)
									)
				)
				(set	@default-dest	#updpath)
			)
		)

		(set	#userupd	(askbool	(default 1)
										(prompt	(#updating	@default-dest))
										(help	#upddirhelp)
										(choices	#yes	#no)
							)
		)

		(if		(=	#userupd	0)
			(
				(set	#updpath	(askdir	(prompt #update_dir)
											(help @askdir-help)
											(default @default-dest)
									)
				)
				(set	@default-dest	#updpath)
			)
		)

		(complete	10)

		(if (= (exists "L:VirusChecker.brain" (noreq)) 1)
			(
				(set	VerN	"L:VirusChecker.brain")
				(WhatVersion)
				(set	#brainver	Ver)
				(set	#brainrev	Rev)
			)

			(
				(set	VerN	(tackon	@default-dest	"VirusChecker.brain"))
				(WhatVersion)
				(set	#brainver	Ver)
				(set	#brainrev	Rev)
			)
		)

		(set	VerN	(tackon	@default-dest	"Virus_CheckerII"))
		(WhatVersion)
		(set	#mainver	Ver)
		(set	#mainrev	Rev)

		(set	VerN	(tackon	@default-dest	"Virus_Checker.guide"))
		(WhatVersion)
		(set	#guidever	Ver)
		(set	#guiderev	Rev)


		(set	VerN	"Virus_CheckerII")
		(WhatVersion)
		(set	#main2ver	Ver)
		(set	#main2rev	Rev)

		(set	VerN	"VirusChecker.brain")
		(WhatVersion)
		(set	#brain2ver	Ver)
		(set	#brain2rev	Rev)

		(set	VerN	"Virus_Checker.guide")
		(WhatVersion)
		(set	#guide2ver	Ver)
		(set	#guide2rev	Rev)


		(set	VerN	"Libs:Xvs.Library")
		(WhatVersion)
		(set	#xvsver	Ver)
		(set	#xvsrev	Rev)

		(set	VerN	"Libs/Xvs.Library")
		(WhatVersion)
		(set	#xvs2ver	Ver)
		(set	#xvs2rev	Rev)

		(message	(#versions	#mainver	#mainrev	#brainver	#brainrev	#guidever	#guiderev	#xvsver	#xvsrev	#main2ver	#main2rev	#brain2ver	#brain2rev	#guide2ver	#guide2rev	#xvs2ver	#xvs2rev))

		(copylib (prompt #upd-xvs)
			(help @copylib-help)
			(source "libs/Xvs.library")
			(dest "LIBS:")
			(optional nofail askuser)
		)

		(copylib	(prompt #upd-guide)
					(help @copylib-help)
					(source "Virus_Checker.guide")
					(dest @default-dest)
					(optional nofail askuser)
		)

		(complete	30)

		(copylib	(prompt #upd-main)
					(help @copylib-help)
					(source "Virus_CheckerII")
					(dest @default-dest)
					(optional nofail askuser)
		)
		(complete	50)

		(if (= (exists "L:VirusChecker.brain" (noreq)) 1)
			(
				(copylib (prompt #upd-brain)
					(help @copylib-help)
					(source "VirusChecker.brain")
					(dest "L:")
					(optional nofail askuser)
				)
				(copylib (prompt #upd-brain)
					(help @copylib-help)
					(source "VirusChecker.brain")
					(dest @default-dest)
					(optional nofail askuser)
				)
			)

			(
				(copylib (prompt #upd-brain)
					(help @copylib-help)
					(source "VirusChecker.brain")
					(dest @default-dest)
					(optional nofail askuser)
				)
			)
		)

		(P_setvcenv)

		(complete	100)

	)
)

(if (= #vc-startup 2)
	(exit)
	(exit	#needtoreset)
)
