; Installation script for DeluxeMusic 2.0
; $VER: Install-DMusic 0.6 (28-4-93)

; Tell user that the installer will be creating a drawer for the program.
; Also the program will be installing some libraries (under 1.3 only).

; Things that go in DMusic Drawer:
;  DMusic.info
;  DMusic
;  DMPlayer.info
;  DMPlayer
;  Samples.info (disk 2)
;  Samples/#? (disk 2)
;  Scores.info (disk 2)
;  Scores/#? (disk 2)
; Things that go in system places (*** only if doesn't exist):
;  Rexx/#?
;  Fonts/Duet
;  Fonts/GuitarFret
;  Fonts/DMusic
;  Libs/camd.library ***
;  Libs/realtime.library ***
;  Libs/iffparse.library  *** 1.3 only
;  Libs/gadtools13.library *** 1.3 only
;  Libs/asl13.library *** 1.3 only
;  Devs/Midi/checkpoint (optional)
;  Devs/Midi/OneStopMusicShop (optional)

; some 'constants'

(set app_volume_name_1 "DeluxeMusic2.0")
(set app_volume_name_2 "Samples")
(set app_volume_1 "DeluxeMusic2.0:")
(set app_volume_2 "Samples:")
(set orig_user_level @user-level)

; determine version of OS

(set os13 (<= (/ (getversion) 65536) 35))

; ask user if this is a floppy or harddisk installation
; switch user level to EXPERT do this

(user 2)

(set inst_mode
	(askbool
		(prompt
			"DeluxeMusic 2.0 must be registered before use. This can be done "
			"at the same time that the program is installed on a hard drive "
			"(or other storage device), or can be performed on a copy of the "
			"DeluxeMusic 2.0 floppy disk. Which form of installation do you "
			"want performed?"
		)
		(help
			"Click on \"Hard Drive\" to install DeluxeMusic 2.0 to a hard drive.\n"
			"Click on \"Floppy Disk\" to register the program on this floppy disk."
		)
		(choices "Hard Drive" "Floppy Disk")
	)
)

; switch user level back

(user orig_user_level)

(complete 5)

; SUBROUTINES

(procedure ask_register
	(
		; switch use mode (again)

		(user 2)

		(set user_ok 0)

		(while (not user_ok)

			(
				(set user_name "")

				(while (= user_name "")
					(
						(set user_name
							(askstring
								(prompt
									"As part of the registration process, please answer the "
									"following questions:\n\nWhat is your name?"
								)
								(help @askstring-help)
							)
						)

						(if (patmatch "# " user_name) (set user_name ""))
					)
				)

				(set user_org
					(askstring
						(prompt "What is the name of your organization (if any)?")
						(help @askstring-help)
					)
				)

				(set reg_number "")

				(while (= reg_number "")
					(
						(set reg_number
							(askstring
								(prompt
									"What is the registration number on your "
									"original DeluxeMusic 2.0 registration card?"
								)
								(help @askstring-help)
							)
						)

						(if (patmatch "# " reg_number)
							(set reg_number "")
						)
					)
				)

				(set user_ok
					(askbool
						(prompt
							(cat
								"Is this information correct?\n\n"
								user_name "\n"
								user_org "\n"
								reg_number
							)
						)
						(help
							"Click \"Yes\" if the information is correct.\n"
							"Click \"No\" to re-enter the registration information."
						)
					)
				)
			)
		)

		; switch user level back

		(user orig_user_level)
	)
)

(procedure do_register
	(
		(set user_ok 0)

		(run
			(cat "\"" (tackon app_volume "DeluxeMusic/c/register") "\" \""
				app_xpath "\" \"" user_name "\" \"" user_org "\" " reg_number
			)
		)

		; switch use mode (again)

		(user 2)

		(set regstatus (getenv "REGSTATUS"))

		(if (= regstatus "OK")
			(
				(set regstatus "PROCESSED")
				(set user_ok 1)
			)
		)

		(if (= regstatus "BADSER")
			(
				(set reg_times (+ reg_times 1))

				(if (= reg_times 3)
					(abort
						"Please try to install the program when you find your "
						"registration number."
					)
					(message
						"Your registration information seems to be wrong. "
						"Please re-enter the information."
					)
				)

				(set regstatus "PROCESSED")
			)
		)

		(if (= regstatus "BADFILE")
			(abort
				"Unable to register you copy of DeluxeMusic because "
				"a disk-related error occured."
			)
		)		

		(if (= regstatus "MEMORY")
			(abort
				"Unable to register you copy of DeluxeMusic because "
				"there was not enough memory to perform the operation."
			)
		)		

		(if (= regstatus "REGTWICE")
			(
				(message
					"This copy of DeluxeMusic is already registered!"
				)
				(set user_ok 1)
				(set regstatus "PROCESSED")
			)
		)		

		(if (<> regstatus "PROCESSED")
			(abort
				"Unable to run the registration program."
			)
		)

		; switch user level back

		(user orig_user_level)
	)			
)

(procedure install_midi
	(

	; if user has One-Stop Music Shop or Checkpoint, install driver
	; (maybe we should write a check-for-board program?) [no time for that...]

	; switch use mode (again)

		(user 2)

		(set card_bits
			(askoptions
				(prompt
					"DeluxeMusic 2.0 can support MIDI output to plug-in serial cards.\n\n"
					"Please indicate which boards are installed in your system (if any) "
					"that you want to use with this program."
				)
				(help
					"     DeluxeMusic 2.0 can send MIDI output to serial ports other than "
					"the internal serial port. These other ports are on plug-in "
					"cards that install inside an Amiga 2000/3000/4000 or other Amigas "
					"with internal plug-in-card slots.\n"
					"     Support is provided for only two plug-in cards at this time. "
					"The first is the Checkpoint Serial Solution card, which has two ports. "
					"(Note: Checkpoint in no longer in business.) The second card is "
					"a card from Blue Ribbon SoundWorks which also has two ports. One port "
					"is connected to an E-Mu Proteus SoundEngine, while the second port "
					"can be used as a regular serial port for output to external MIDI devices.\n\n"
					@askoptions-help
				)
				(choices "Checkpoint Serial Solution" "One-Stop Music Shop")
				(default 0)
			)
		)


	; switch user level back

		(user orig_user_level)

		(if card_bits
			(
				(set smp_path (tackon app_volume_1 "DeluxeMusic/c/setmidiports"))

				(set smp_help
					(cat
						"Access to third-party serial cards is controlled "
						"by the information stored in an enviroment "
						"variable. Your system has not been configured "
						"properly to use enviroment variables. This will be "
						"done by creating an ENV: and ENVARC: assignment (if "
						"needed)."
					)
				)

				(set envarc_path (getassign "ENVARC" "a"))
				(set env_path (getassign "ENV" "a"))

				(if (or (= envarc_path "") (= env_path ""))
					(
						(set env_answer
							(askbool
								(prompt "Your system is not set-up for using "
										"enviroment variables, which is required "
										"to use serial cards with Deluxe Music. "
										"Do you want to add enviroment variables to "
										"your system?"
								)
								(help smp_help)
								(default 1)
							)
						)

						(if (= env_answer 0)

							(set card_bits 0)	; user decides against it

							(					; user decides he likes the idea
								(set env_com "")

								(if (= envarc_path "")
									(
										(makedir "SYS:env-archive")
										(makedir "SYS:env-archive/sys")
										(makeassign "ENVARC" "SYS:env-archive")
										(set env_com (cat env_com "assign ENVARC: SYS:env-archive\n"))
									)
								)

								(if (= env_path "")
									(
										(makedir "RAM:ENV")
										(makedir "RAM:ENV/sys")
										(makeassign "ENV" "RAM:ENV")
										(set env_com (cat env_com "makedir RAM:ENV\nassign ENV: RAM:ENV\n"))
									)
								)

								(startup "-- Deluxe Music --"
									(prompt "Your enviroment variable enviroment needs to be "
											"set-up each time your system is booted. This "
											"requires modifying your \"user-startup\" file."
									)
									(help smp_help)
									(command (cat env_com "copy ENVARC: ENV: all"))
								)
							)
						)
					)
				)
			)
		)

	;	Template: NAME,UNIT,IN,OUT,COMMENT,XMIT,RECV,INTERNAL/S,REMOVE/S,SAVE/S

		(if (bitand card_bits 1)
			(
				(copyfiles
					(source (tackon app_volume_1 "DeluxeMusic/DEVS/midi"))
					(dest "DEVS:midi")
	 				(choices "checkpoint")
				)

				(run 
					(cat "\"" smp_path "\" INTERNAL SAVE")
				)

				(run 
					(cat "\"" smp_path "\" checkpoint 0 comment \"Checkpoint Unit 0\" SAVE")
				)

				(run 
					(cat "\"" smp_path "\" checkpoint 1 comment \"Checkpoint Unit 1\" SAVE")
				)
			)
		)

		(if (bitand card_bits 2)
			(
				(copyfiles
					(source (tackon app_volume_1 "DeluxeMusic/DEVS/midi"))
					(dest "DEVS:midi")
	 				(choices "OneStopMusicShop")
				)

				(run 
					(cat "\"" smp_path "\" INTERNAL SAVE")
				)

				(run 
					(cat "\"" smp_path "\" OneStopMusicShop 0 comment \"Music Shop SoundEngine\" SAVE")
				)

				(run 
					(cat "\"" smp_path "\" OneStopMusicShop 1 comment \"Music Shop Serial Port\" SAVE")
				)
			)
		)
	)
)

; handle floppy-based 'installation'

(if (not inst_mode)
	(
		(set @default-dest "")

		; switch use mode (again)

		(user 2)

		(message
			"\nYou should only perform a floppy installation from a copy of "
			"your DeluxeMusic 2.0 program disk. If you have not made a "
			"copy of the disk, please select Abort Install and make a copy. "
			"Be sure to rename the copy of the disk as \"DeluxeMusic2.0\". "
			"Then, open the disk icon for the copy and double click on the "
			"Install-DeluxeMusic icon found there. If you ARE installing "
			"from a copy, select Proceed."
		)

		; switch user level back

		(user orig_user_level)

		(complete 50)

		(set app_volume (pathonly @icon))
		(set app_xpath (tackon app_volume "DeluxeMusic/DMusic"))

		(set reg_times 0)
		(set user_ok 0)

		(while (not user_ok)
			(
				(ask_register)

				(do_register)
			)
		)

	; if user has One-Stop Music Shop or Checkpoint, install driver

		(install_midi)

		(complete 100)

		(exit)
	)
)

(complete 10)

; tell average/expert user what we'll be doing

(message
   "\nYour copy of DeluxeMusic 2.0 will be installed in a new drawer named "
   "\"DeluxeMusic\". You will be asked where on your hard drive "
    "(or other storage device) you want this drawer created. In addition, "
   "some libraries, fonts and ARexx scripts will be installed in the "
   "usual places."
)

(set reg_times 0)
(set user_ok 0)

(while (not user_ok) (ask_register))

; ask user where to put the drawer

(set app_locate
   (askdir
      (prompt "Please indicate where you want the DeluxeMusic drawer "
            "to be located.")
      (help @askdir-help)
      (default @default-dest)
   )
)

; make the main drawer

(set app_path (tackon app_locate "DeluxeMusic"))

(makedir app_path (infos))

(set @default-dest app_path)

(complete 15)

; copy local files on disk 1 to drawer

(askdisk
   (prompt "Please insert the disk labeled \"DeluxeMusic 2.0\".")
   (help @askdisk-help)
   (dest app_volume_name_1)
)

(copyfiles
   (source (tackon app_volume_1 "DeluxeMusic"))
   (dest app_path)
   (choices "DMusic" "DMPlayer" "Late_Notes" "Samples" "Scores")
   (infos)
)

(tooltype
   (dest (tackon app_path "DMusic"))
   (settooltype "SAMPLEPATH" "Samples")
)

(complete 25)

(set app_volume app_volume_1)
(set app_xpath (tackon app_path "DMusic"))

(set xxx_temp 0)
(set user_ok 0)

(while (not user_ok)
	(
		(if xxx_temp (ask_register))

		(set xxx_temp 1)

		(do_register)
	)
)

(complete 30)

(copylib
   (prompt "Copying \"camd\" utility library.")
   (help "You will need some version of \"camd.library\" for "
        "DeluxeMusic to work. A higher version number indicates a "
        "newer version.")
   (source (tackon app_volume_1 "DeluxeMusic/LIBS/camd.library"))
   (dest "LIBS:")
   (confirm)
)

(complete 35)

(copylib
   (prompt "Copying \"realtime\" utility library.")
   (help "You will need some version of \"realtime.library\" for "
        "DeluxeMusic to work. A higher version number indicates a "
        "newer version.")
   (source (tackon app_volume_1 "DeluxeMusic/LIBS/realtime.library"))
   (dest "LIBS:")
   (confirm)
)

(complete 40)

(if os13
   (copylib
      (prompt "Copying \"gadtools13\" utility library.")
      (help "You will need some version of \"gadtools13.library\" for "
           "DeluxeMusic to work. A higher version number indicates a "
           "newer version.")
      (source (tackon app_volume_1 "DeluxeMusic/LIBS/gadtools13.library"))
      (dest "LIBS:")
      (confirm)
   )
)

(complete 45)

(if os13
   (copylib
      (prompt "Copying \"asl13\" utility library.")
      (help "You will need some version of \"asl13.library\" for "
           "DeluxeMusic to work. A higher version number indicates a "
           "newer version.")
      (source (tackon app_volume_1 "DeluxeMusic/LIBS/asl13.library"))
      (dest "LIBS:")
      (confirm)
   )
)

(complete 50)

(if os13
	(copylib
   		(prompt "Copying \"iffparse\" utility library.")
		(help "You will need some version of \"iffparse.library\" for "
        	"DeluxeMusic to work. A higher version number indicates a "
	        "newer version.")
		(source (tackon app_volume_1 "DeluxeMusic/LIBS/iffparse.library"))
   		(dest "LIBS:")
   		(confirm)
	)
)

(complete 55)

(if (getassign "REXX" "a")
   (copyfiles
      (source (tackon app_volume_1 "DeluxeMusic/REXX"))
      (dest "REXX:")
      (all)
   )
)

(complete 60)

;  Fonts/Duet
(copyfiles
   (source (tackon app_volume_1 "DeluxeMusic/FONTS"))
   (dest "FONTS:")
   (choices "Duet")
   (fonts)
)

;  Fonts/GuitarFret
(if (not (exists "FONTS:GuitarFret"))
   (copyfiles
      (source (tackon app_volume_1 "DeluxeMusic/FONTS"))
      (dest "FONTS:")
      (choices "GuitarFret")
      (fonts)
   )
)

;  Fonts/DMusic
(if (not (exists "FONTS:DMusic"))
   (copyfiles
      (source (tackon app_volume_1 "DeluxeMusic/FONTS"))
      (dest "FONTS:")
      (choices "DMusic")
      (fonts)
   )
)

(complete 70)

; if user has One-Stop Music Shop or Checkpoint, install driver

(install_midi)

(complete 85)

(set examples
	(askoptions
		(prompt
			"Which of these files do you want to install from the "
			"examples disk?"
		)
		(choices "Samples" "Scores")
		(help @askoptions-help)
		(default 3)
	)
)

(if (not examples) (exit))

; copy local files on disk 2 to drawer

(askdisk
   (prompt "Please insert the disk labeled \"Samples\".")
   (help @askdisk-help)
   (dest app_volume_name_2)
)

(if (bitand examples 1)
	(copyfiles
		(source app_volume_2)
		(dest app_path)
		(choices "Samples")
		(infos)
	)
)

(if (bitand examples 2)
	(copyfiles
		(source app_volume_2)
		(dest app_path)
		(choices "Scores")
	)
)

(complete 100)
