;Installer script for GS CallerID


(set ul @user-level)
(set dest_dir
	(askdir
		(prompt "In which disk or drawer should the GS CallerID program, documentations, and other files be installed?\nA SUBDIRECTORY WILL BE CREATED.")
		(help @askdir-help)
		(default "SYS:")
		(newpath)
	)
)

(set LastChar (substr dest_dir (- (strlen dest_dir) 1) 1))
(if (And (<> LastChar ":") (<> LastChar "/"))
	(set dest_dir (cat dest_dir "/"))
)

(set InstallFiles 1)
(run "version" ">ENV:CIDMV"	"CallerID")
(if (exists ("%sCallerID/CallerID" dest_dir))
	(
		(run "version" ">ENV:CIDYV"	("\"%sCallerID/CallerID\"" dest_dir))
		(set YourVersion (getenv "CIDYV"))
	)
	(set YourVersion "GS CallerID 0.0")
)

(set VersNum (substr YourVersion 12))

(set MyVersion   (getenv "CIDMV"))
(run "Delete" "<>NIL:" "ENV:CID#?")
(if (<= MyVersion YourVersion)
	(set InstallFiles
		(AskBool
			(prompt	 "You already have\n"
						("%s" (cat YourVersion))
						("in your %s directory.\n\n" dest_dir)
						 "Do you want to over write it with\n"
						("%s" (cat MyVersion))
						 "at this time?")
			(help ("Selecting YES will replace your version with %s" (cat MyVersion)))
			(default 0)
		)
	)
)

(if (= InstallFiles 0) (exit (quiet)))


(if (< VersNum "1.3")
	(
		(user 1)
		(if (exists "S:CallerID.cfg" (quiet))
			(
				(Message	("Since you are upgrading GS CallerID %s,\n" VersNum)
							"your Black Book needs to be inspected and\n"
							"maybe updated at the same time to match\n"
							"the current data format.\n\n\n"
							"Please QUIT all copies of GS CallerID\n"
							"that you might have running at this time.\n\n\n"
							"You may then procede with the instalation.")
				(run "/DataUpdate")
			)
		)
		(user ul)
	)
)



(set WBStart
	(AskBool
		(prompt "Do you want the the GS CallerID program to start automatically when you start WorkBench?")
		(help "If you select YES, a copy of CallerID will be placed in SYS:WBStartup")
		(default 1)
	)
)






(set copycfg 1)
(if (exists "S:CallerID.cfg" (noreq))
	(
		(set copycfg
			(askbool 
				(prompt "A configuration file already exists in your S: directory. Do you want to replace it now?")
				(help "If you select YES, your existing configuration file will be deleted and replaced")
				(default 0)
			)
		)
	)
)

(if (= copycfg 1)
	(

;----------------------- Select Modem Type ----------------------------------
	
		(set modemtype
			(askchoice
				(prompt "Which modem do you have?")
				(help "Simply select the modem that matches what you are using\n"
				      "on with your computer. If you don't see your modem in the\n"
						"list, select \"Not Listed\" and the gerneic config file\n"
						"will be used.")
				(choices "Not Listed" "Motorola" "Supra" "US Robotics" "Zoom")
			)
		)
		
		(set cfg_file 
			(cat "CFG/" (select modemtype	"Generic"
													"Motorola"
													"Supra"
													"USR"
													"Zoom")
			)
		)
		

;----------------------- Get Serial Card Name -------------------------------
	
		(set serialtype
			(askchoice
				(prompt "Which serial card are you using with your modem?")
				(help	"Select the serial card you are using with your modem.\n"
						"If it is not listed, you can eigher select the Amiga Internal\n"
						"Not Listed. If you select Not Listed, you will have the\n"
						"oppertunity to enter the name of the serial device driver.\n")
				(choices "Not Listed" "Amiga Internal" "GVP I/O" "MultiFace II"
							"Squirrel")
				(default 1)
			)
		)
		
		(if (= serialtype 0)
			(set serialdevice
				(askstring
					(prompt	"Since your serial card is not listed, you need\n"
								"to enter the serial device driver name in manualy.\n"
								"\n"
								"Please take the time to send this information back\n"
								"to me so I can update this installer. Check the\n"
								"Guide file for information on contacting me. Thanks!\n"
								"\n"
								"Enter the name of your serial device driver.\n")
					(help	"Enter the name of your serial device driver.\n"
							"This is usualy found in your DEVS: directory and\n"
							"should be described in the manual for your serial card.\n"
							"The Amiga internal serial port driver is serial.device\n"
							"and is used as the default\n")
					(default "serial.device")
				)
			)
			(set serialdevice
				(select serialtype	"serial.device"
											"serial.device"
											"gvpser.device"
											"duart.device"
											"squirrelserial.device")
			)
		)
		
		(if (= serialdevice "")
			(set serialdevice "serial.device")
		)
		

;----------------------- Get Serial Unit ---------------------------------
	
		(if (<> serialdevice "serial.device")
			(set serialunit
				(askchoice
					(prompt ("What unit on %s is your modem connected?" serialdevice))
					(help	"What unit is your modem connected to?\n"
							"\n"
							"That should be simple enough don't you think?")
					(choices	"Unit 0" "Unit 1" "Unit 2" "Unit 3" "Unit 4"
								"Unit 5" "Unit 6" "Unit 7" "Unit 8" "Unit 9")
				)
			)
			(set serialunit 0)
		)



;----------------------- Select A Text Editor -------------------------------
	
		(set ted
			(askfile
				(prompt "Select the text editor you would like to use when modifying the configuration file.\n\nBy default C:ED is used")
				(help @askfile-help)
				(default "C:ED")
			)
		)
		(if (= (fileonly ted) "")
			(set ted "C:ED")
		)
		(set texteditor (cat ted " %s"))



		(set flags
			(askoptions 
				(prompt "Which of these options would you like activated?")
				(help	"This is your opportunity to configure some of the options "
						"that are available in GS CallerID. Just check off the things "
						"that interest you. You can laways change these settings "
						"at a later time if you want.")
				(choices	"Display time in title bar"
							"Display date in title bar"
							"Open the serial port in SHARED mode")
				(default 0)
			)
		)



;----------------------- Build the CFG file ---------------------------------
	
		(textfile
			(prompt "Building configuration file S:CallerID.cfg...")
			(help @textfile-help)
			(dest "S:CallerID.cfg")
			(include cfg_file)
			(append ("DEVICE = %s\n" serialdevice))
			(append ("UNIT = %d\n" serialunit))
			(append ("EDITOR = %s\n" texteditor))
			(append ("PATH = %s\n" (cat dest_dir "CallerID/")))
			(if (bitand flags 1) (append "SHOWTIME = 1\n"))
      	(if (bitand flags 2) (append "SHOWDATE = 1\n"))
			(if (bitand flags 4) (append "SHARED = 1\n"))
		)
	)
)


;----------------------- Build Some ARexx Scripts ---------------------------
;
; Only if the user is Average or Expert since it requires some feed back


(if (> ul 0)
	(
		(set MakeScripts
			(AskBool
				(prompt	"GS CallerID can be used on the same\n"
							"modem as some of your other programs\n"
							"such as your terminal program or internet\n"
							"programs.\n\n"
							"Some ARexx scripts can be created to automatically\n"
							"release the serial port, start your program, then\n"
							"wait for your program to exit. At that point,\n"
							"GS CallerID will be given control of the port again.\n\n"
							"Would you like to create some of these scripts now?")
				(help	"Selecting YES will let you create some ARexx scripts for "
						"starting programs that share the modem with GS CallerID.\n\n"
						"You will be able to select the files you want to start "
						"with each script.")
				(default 0)
			)
		)
		(if (= MakeScripts 1)
			(
				(set path "SYS:")
				(run ("MakeDir %sCallerID" dest_dir))
				(run ("MakeDir %sCallerID/ARexx" dest_dir))
				(set filename "blablabla")
				(while (> (strlen filename) 0)
					(
						(set file
							(askfile
								(prompt	"Select a program to create a launch script for.\n\n"
											"Enter a blank line to stop creating scripts.")
								(help	"This is a quick and simple way to create ARexx scripts that "
										"can help you share the modem with GS CallerID and other "
										"programs.\n\n"
										"You simply locate the program(s) you want to create scripts "
										"for. The scripts will be automatically created.\n\n"
										"When you have created all of the scripts you need, you "
										"simply click PROCEDE with no file name selected.")
								(default path)
							)
						)
						(set filename (fileonly file))
						(set path (pathonly file))
						(if (> (strlen filename) 0)
							(
								(textfile
									(prompt "Building configuration file S:CallerID.cfg...")
									(help @textfile-help)
									(dest ("%sCallerID/ARexx/%s.cid" dest_dir filename))
									(append ("/* Script to launch %s */\n\n" filename))
									(append "options results\n")
									(append "address CID\n")
									(append "Serial Close\n\n")
									(append ("shell command '%s'\n\n\n" file))
									(append "/* Just in case the program we just started releases the command line\n")
									(append "** before it exits, we should wait 10 seconds to give\n")
									(append "** it time to get a hold of the serial port.\n")
									(append "** This way, even if GS CallerID trys to open the port now,\n")
									(append "** it won't be able to. (unless it is in shared mode)\n")
									(append "*/\n")
									(append "shell command 'Wait 10'\n\n")
									(append "address CID\n")
									(append "Serial Open\n")
									(append "Serial Reset\n")
								)
							)
						)
					)
				)
			)
		)
	)
)



	
;----------------------- Start Copying Files --------------------------------
	


(if WBStart
	(
		(copyfiles
			(prompt "Copying CallerID to SYS:WBStartup")
			(help @copyfile-help)
			(dest "SYS:WBStartup")
			(source "CallerID")
		)

		(if (not (exists "SYS:WBStartup/CallerID.info" (quiet)))
			(
				(copyfiles
					(prompt "About to copy the Icon file to SYS:WBStartup")
					(help @copyfile-help)
					(confirm)
					(source "/CallerID.inf1")
					(newname "CallerID.info")
					(dest "SYS:WBStartup")
				)
			)
		)
	)
)


(copyfiles
	(prompt ("About to copy files to %sCallerID" dest_dir))
	(help @copyfile-help)
	(confirm)
	(source "")
	(dest (cat dest_dir "CallerID"))
	(all)
)


(if (not (exists ("%sCallerID.info" dest_dir) (quiet)))
	(
		(copyfiles
			(prompt ("About to copy the Icon file to %s" dest_dir))
			(help @copyfile-help)
			(confirm)
			(source "/CallerID.inf2")
			(newname "CallerID.info")
			(dest dest_dir)
		)
	)
)

(set MyRexxLib   (getversion "libs/EasyRexx.library"))
(set YourRexxLib (getversion "libs:EasyRexx.library"))

(if (> MyRexxLib YourRexxLib)
	(copyfiles
		(prompt "About to copy the library files to LIBS:")
		(help @copyfile-help)
		(confirm)
		(source "libs")
		(dest "LIBS:")
		(all)
	)
)

(set MyInstaller   (getversion "Installer"))
(set YourInstaller (getversion "C:Installer"))

(if (> MyInstaller YourInstaller)
	(copyfiles
		(prompt "About to copy the new Installer to C:")
		(help @copyfile-help)
		(confirm)
		(source "Installer")
		(dest "C:")
		(all)
	)
)

(foreach ("%sCallerID/Arexx/" dest_dir) "#?.cid"
	(if (not (exists ("%sCallerID/Arexx/%s.info" dest_dir @each-name)))
		(
			(copyfiles
				(prompt ("Create an icon for the file %s" @each-name))
				(help "An icon will be created for the specified file")
				(confirm)
				(source "/CallerID.cid.inf1")
				(dest ("%sCallerID/Arexx/" dest_dir))
				(newname ("%s.info" @each-name))
			)
		)
	)
)


(if (<> @user-level 2)
	(
		(run "Delete" "<>NIL:" ("\"%sCallerID/libs\"" dest_dir) "all")
		(run "Delete" "<>NIL:" ("\"%sCallerID/Install#?\"" dest_dir) "all")
	)
)

(rexx "/KillCallerID.cid")
(run "RUN" "<>NIL:" "AmigaGuide" "CallerID.Guide")
(run "RUN" "<>NIL:" "CallerID")

(set @default-dest dest_dir)
(exit)



