;;
;;  $Filename: HDInstall $
;;  $Id: HDInstall,v 3.12 1993/09/17 16:38:10 $
;;  $Date: 1993/09/17 16:38:10 $
;;  $Revision: 3.12 $
;;

(set is_update 0)
(set @user-level 1)	; force to use average mode
(complete 0)

(set FW_dest
	(askdir
		(prompt "In which disk or drawer should the Final Writer "
					"drawer be created in?")
		(help "The installation utility will create a drawer named "
			"\"FinalWriter\" in this directory.  All \"Final Writer\" "
			"files will be placed inside that directory. \n\n"
			" Tip for advanced users:\n "
			"  \"Final Writer\" may be moved to another directory as long as "
			" the sub-directories:\n"
			"   FWFiles, FWFonts, FWLibs, FWThes, and FWSpell\n"
			" are moved (as subdirectories) to the program's new location")
		(default @default-dest)
	)
)

; Check if this is an update
; the FWLibs directory is a tell-tale sign
; that FW is already installed here
(if (exists (tackon FW_dest "FWLibs"))
	(set is_update 1)
	(	(if (exists (tackon FW_dest "FinalWriter"))
			(set is_update 1)
			(makedir (tackon FW_dest "FinalWriter") (infos))
		)
		(set FW_dest (tackon FW_dest "FinalWriter"))
	)
)

(set @default-dest FW_dest)
(set disk_space (getdiskspace FW_dest))


; If first time install ask user if he wants a complete
; or a minimal installation. The minimal installation
; will not install the eps clip art or the extra fonts.
(if (NOT is_update)
	(
		(set install_all
			(askbool
				(prompt "Do you wish to do a \"Complete\" or \"Minimal\" "
					"installation of Final Writer? The complete installation "
					"will require approximately 9.5 megabytes of free disk "
					"space. The minimal installation will require approximately "
					"2.5 megabytes of free disk space.")

				(help "Choosing \"Complete\" will install all of the files that "
					"are included in the Final Writer disk set. This will require "
					"approximately 9.5 megabytes of free disk space. If \"Minimal\" "
					"is choosen, then the ARexx Macros, EPS Clip Art, and Extra Fonts "
					"will not be installed. The minimal installation will require "
					"approximately 2.5 megabytes of free disk space.")

				(choices "Complete" "Minimal")

				(default 1)
			)
		)

		(if install_all
			(set disk_space_needed 9794048)	; 9.34 Megs
			(set disk_space_needed 2810183)	; 2.68 Megs
		)
	)
)


(if (AND (< disk_space disk_space_needed) (NOT is_update))
	(
		(set answer1
			(askbool
				(prompt "There may not be enough room available on "
					"this drive to install \"Final Writer\".  Do you "
					"wish to continue?")
				(help "Final Writer needs approximately 9.5 megabytes of "
					"disk space for a complete installation or 2.5 megabytes "
					"for a minimal installation. If Final Writer is already "
					"installed on this partition, you may wish to continue. "
					"Otherwise, press ABORT or NO now and either free some "
					"space on this partition or select a different partition "
					"for the installation.")
			)
		)
		(if (NOT answer1)
			(abort "Final Writer installation cancelled. Not enough disk "
					"space on Volume \""
					(getdevice @default-dest)
					"\"."
			)
		)
	)
)

; Allow updating user to select what they want updated
(if is_update
	(set install_options
		(askoptions
			(prompt "What parts would you like to update")
			(help @askoptions-help)
			(choices
				"Final Writer Program"
				"ARexx Macros"
				"System Data Files"
				"System Libraries"
				"System Fonts"
				"Speller & Hyphenation"
				"Thesaurus"
				"EPS Clip Art"
				"Extra Fonts")
			(default 13)		; default to Program, Files, Libs
		)
	)
	
	; First time install
	(if install_all
		(set install_options 511)  ; hex 1FF - all nine options on
		(set install_options 125)	; hex 07D - Macros, EPS, and Extra fonts off
	)
)

; Copy the extraction utility over and remember where it is
(copyfiles
	(source "Disk 1:lhex")
	(dest FW_dest)
)
(set DeArcher (tackon FW_dest "lhex"))
(set error 0)

; Installing Files on Disk 1?
(if (IN install_options 0 1 2 3)
	(
		; Get Disk 1
		(askdisk
			(prompt "Please insert the disk labeled \"Disk 1\"" )
			(help	"Disk 1 contains the Final Writer program, macros, libraries, "
					"and data files that will be installed onto your system." )
			(dest "Disk 1" )
		)

		; Copy the More program to the hard drive
		; so everyone is guaranteed to have it.
		(if (NOT is_update)
			(copyfiles
				(source "Disk 1:More")
				(dest FW_dest)
			)
		)

		; If installing/updating the program
		(if (IN install_options 0)
			(
				; Make installer cd into FW_dest when it executes the run statement
				(set @execute-dir FW_dest)

				; copy the Final Writer program over if the program
				; icon doesn't exists copy it over too.
				( if (exists (tackon FW_dest "FinalWriter.info"))
					; This DOES NOT copy the icon, in case the user
					; has modified the tool-types
					(
						(working "Installing Final Writer program from Disk 1.")
						(set error
							(run
								("\"%s\" -f x \"Disk 1:FinalWriter.lha\" FinalWriter >NIL:" DeArcher)
							)
						)
					)
					; This DOES copy the icon
					(
						(working "Installing Final Writer program and icon from Disk 1.")
						(set error
							(run
								("\"%s\" -f x \"Disk 1:FinalWriter.lha\" >NIL:" DeArcher)
							)
						)
					)
				)
			)
		)

		(if error
			(abort ("Error installing FinalWriter Program."))
		)

		(complete 4)

		; Installing FWMacros
		(if (IN install_options 1)
			(
				; If FWMacros doesn't exist, create it.
				(if (NOT (exists (tackon FW_dest "FWMacros")))
					(
					(makedir (tackon FW_dest "FWMacros") (infos))
					)
				)

				; Make installer cd into FWMacros when it executes the run statement
				(set @execute-dir (tackon FW_dest "FWMacros"))

				; Extract the macro files
				(working "Installing ARexx Macros from Disk 1.")
				(set error
					(run
						("\"%s\" -f x \"Disk 1:FWMacros.lha\" >NIL:" DeArcher)
					)
				)

				; Abort if any errors
				(if error
					(abort ("Error installing ARexx Macros."))
				)
			)
		)

		(complete 7)

		; Installing FWFiles
		(if (IN install_options 2)
			(
				; If FWFiles doesn't exist, create it.
				(if (NOT (exists (tackon FW_dest "FWFiles")))
					(
					(makedir (tackon FW_dest "FWFiles") (infos))
					)
				)

				; Make installer cd into FWFiles when it executes the run statement
				(set @execute-dir (tackon FW_dest "FWFiles"))

				; Extract the files
				(working "Installing Data Files from Disk 1.")
				(set error
					(run
						("\"%s\" -f x \"Disk 1:FWFiles.lha\" >NIL:" DeArcher)
					)
				)

				; Abort if any errors
				(if error
					(abort ("Error installing Data Files."))
				)
			)
		)

		(complete 11)

		; Installing FWLibs
		(if (IN install_options 3)
			(
				; If FWLibs doesn't exist, create it.
				(if (NOT (exists (tackon FW_dest "FWLibs")))
					(
					(makedir (tackon FW_dest "FWLibs"))
					)
				)

				; Make installer cd into FWLibs when it executes the run statement
				(set @execute-dir (tackon FW_dest "FWLibs"))

				(working "Installing Libraries from Disk 1.")
				(set error
					(run
						("\"%s\" -f x \"Disk 1:FWLibs.lha\" >NIL:" DeArcher)
					)
				)

				; Abort if any errors
				(if error
					(abort ("Error installing Libraries."))
				)

				(run ("Avail FLUSH"))
			)
		)
	)
)

(complete 14)

; Installing System Data Files/Libraries/Fonts
(if (IN install_options 4 5)
	(
		; Get Disk 2
		(askdisk
			(prompt "Please insert the disk labeled \"Disk 2\"")
			(help	"Disk 2 contains the Final Writer system fonts, speller, and "
					"hyphenation files that will be installed onto your system." )
			(dest "Disk 2")
		)

		; Installing FWFonts
		(if (IN install_options 4)
			(
				; If FWFonts doesn't exist, create it.
				(if (NOT (exists (tackon FW_dest "FWFonts")))
					(
					(makedir (tackon FW_dest "FWFonts") (infos))
					)
				)

				; Make installer cd into FWFonts when it executes the run statement
				(set @execute-dir (tackon FW_dest "FWFonts"))

				(working "Installing System Fonts from Disk 2.")
				(set error
					(run
						("\"%s\" -f x \"Disk 2:FWFonts.lha\" >NIL:" DeArcher)
					)
				)

				; Abort if any errors
				(if error
					(abort ("Error installing System Fonts."))
				)
			)
		)

		(complete 19)

		; Instaling FWSpell
		(if (IN install_options 5)
			(
				; If FWSpell doesn't exist, create it.
				(if (NOT (exists (tackon FW_dest "FWSpell")))
					(
					(makedir (tackon FW_dest "FWSpell"))
					)
				)

				; Preserve the user dictionary as userdict.eng.save
				(if (exists (tackon FW_dest "FWSpell/userdict.eng"))
					(
						(set restore_UD 1)
						(copyfiles
							(source (tackon FW_dest "FWSpell/userdict.eng"))
							(dest (tackon FW_dest "FWSpell"))
							(newname "userdict.eng.save")
						)
					)
					(set restore_UD 0)
				)

				; Make installer cd into FWSpell when it executes the run statement
				(set @execute-dir (tackon FW_dest "FWSpell"))

				(working "Installing Speller & Hyphenation Files from Disk 2.")
				(set error
					(run
						("\"%s\" -f x \"Disk 2:FWSpell.lha\" >NIL:" DeArcher)
					)
				)

				(if restore_UD
					(
						(copyfiles
							(source (tackon FW_dest "FWSpell/userdict.eng.save"))
							(dest (tackon FW_dest "FWSpell"))
							(newname "userdict.eng")
						)
						(delete (tackon FW_dest "FWSpell/userdict.eng.save"))
					)
				)

				; Abort if any errors
				(if error
					(abort ("Error installing Speller Files."))
				)
			)
		)
	)
)

(complete 29)

(if (IN install_options 6 7)
	(
		; Get Disk 3
		(askdisk
			(prompt "Please insert the disk labeled \"Disk 3\"")
			(help	"Disk 3 contains Final Writer thesaurus files and "
					"EPS Clip Art that will be installed onto your system.")
			(dest "Disk 3")
		)

		; Instaling FWThes
		(if (IN install_options 6)
			(
				; If FWThes doesn't exist, create it.
				(if (NOT (exists (tackon FW_dest "FWThes")))
					(
					(makedir (tackon FW_dest "FWThes"))
					)
				)

				; Make installer cd into FWThes when it executes the run statement
				(set @execute-dir (tackon FW_dest "FWThes"))

				(working "Installing Thesaurus Files from Disk 3.")
				(set error
					(run
						("\"%s\" -f x \"Disk 3:FWThes.lha\" >NIL:" DeArcher)
					)
				)

				; Abort if any errors
				(if error
					(abort ("Error installing Thesaurus Files."))
				)
			)
		)

		(complete 32)

		; Installing EPS Clip Art <cc> <fed> <maps> <metro1>
		(if (IN install_options 7)
			(
				; If FWClipArt doesn't exist, create it.
				(if (NOT (exists (tackon FW_dest "FWClipArt")))
					(
					(makedir (tackon FW_dest "FWClipArt"))
					)
				)

				; Make installer cd into FWClipArt when it executes the run statement
				(set @execute-dir (tackon FW_dest "FWClipArt"))

				(working "Installing EPS Clip Art from Disk 3.")

				(set error
					(run
						("\"%s\" -f x \"Disk 3:cc.lha\" >NIL:" DeArcher)
					)
				)

				; Abort if any errors
				(if error
					(abort ("Error installing EPS Clip Art."))
				)

				(complete 35)

				(set error
					(run
						("\"%s\" -f x \"Disk 3:fed.lha\" >NIL:" DeArcher)
					)
				)

				; Abort if any errors
				(if error
					(abort ("Error installing EPS Clip Art."))
				)

				(complete 37)

				(set error
					(run
						("\"%s\" -f x \"Disk 3:maps.lha\" >NIL:" DeArcher)
					)
				)

				; Abort if any errors
				(if error
					(abort ("Error installing EPS Clip Art."))
				)

				(complete 40)

				(set error
					(run
						("\"%s\" -f x \"Disk 3:metro1.lha\" >NIL:" DeArcher)
					)
				)

				; Abort if any errors
				(if error
					(abort ("Error installing EPS Clip Art."))
				)
			)
		)
	)
)

(complete 43)

(if (IN install_options 7)
	(
		; ----------
		; Get Disk 4
		;
		(askdisk
			(prompt "Please insert the disk labeled \"Disk 4\"")
			(help	"Disk 4 contains EPS Clip Art that "
					"will be installed onto your system.")
			(dest "Disk 4")
		)

		; Installing EPS Clip Art <dms> <totem>

		; If FWClipArt doesn't exist, create it.
		(if (NOT (exists (tackon FW_dest "FWClipArt")))
			(
			(makedir (tackon FW_dest "FWClipArt"))
			)
		)

		; Make installer cd into FWClipArt when it executes the run statement
		(set @execute-dir (tackon FW_dest "FWClipArt"))

		(working "Installing EPS Clip Art from Disk 4.")
		(set error
			(run
				("\"%s\" -f x \"Disk 4:dms.lha\" >NIL:" DeArcher)
			)
		)

		; Abort if any errors
		(if error
			(abort ("Error installing EPS Clip Art."))
		)

		(complete 50)

		(set error
			(run
				("\"%s\" -f x \"Disk 4:totem.lha\" >NIL:" DeArcher)
			)
		)

		; Abort if any errors
		(if error
			(abort ("Error installing EPS Clip Art."))
		)
	)
)

(complete 57)

(if (IN install_options 7 8)
	(
		; ----------
		; Get Disk 5
		;
		(askdisk
			(prompt "Please insert the disk labeled \"Disk 5\"")
			(help	"Disk 5 contains EPS clip art and additional decorative "
					"and serif fonts that will be installed onto your system.")
			(dest "Disk 5")
		)

		; Instaling EPS Clip Art
		(if (IN install_options 7)
			(
				; Make installer cd into FWClipArt/Metro when it executes the run statement
				(set @execute-dir (tackon FW_dest "FWClipArt/Metro"))

				(working "Installing EPS Clip Art from Disk 5.")
				(set error
					(run
						("\"%s\" -f x \"Disk 5:Metro2.lha\" >NIL:" DeArcher)
					)
				)

				; Abort if any errors
				(if error
					(abort ("Error installing Decorative Fonts."))
				)
			)
		)

		(complete 62)

		; Instaling Decorative fonts
		(if (IN install_options 8)
			(
				; If FWFonts/SWOLFonts/Deco doesn't exist, create it.
				(if (NOT (exists (tackon FW_dest "FWFonts/SWOLFonts/Deco")))
					(
					(makedir (tackon FW_dest "FWFonts/SWOLFonts/Deco") (infos))
					)
				)

				; Make installer cd into Deco when it executes the run statement
				(set @execute-dir (tackon FW_dest "FWFonts/SWOLFonts/Deco"))

				(working "Installing Decorative Fonts from Disk 5.")
				(set error
					(run
						("\"%s\" -f x \"Disk 5:Deco.lha\" >NIL:" DeArcher)
					)
				)

				; Abort if any errors
				(if error
					(abort ("Error installing Decorative Fonts."))
				)
			)
		)

		(complete 66)

		; Instaling Serif1 fonts
		(if (IN install_options 8)
			(
				; If FWFonts/SWOLFonts/Serif doesn't exist, create it.
				(if (NOT (exists (tackon FW_dest "FWFonts/SWOLFonts/Serif")))
					(
					(makedir (tackon FW_dest "FWFonts/SWOLFonts/Serif") (infos))
					)
				)

				; Make installer cd into Serif when it executes the run statement
				(set @execute-dir (tackon FW_dest "FWFonts/SWOLFonts/Serif"))

				(working "Installing Serif Fonts from Disk 5.")
				(set error
					(run
						("\"%s\" -f x \"Disk 5:Serif1.lha\" >NIL:" DeArcher)
					)
				)

				; Abort if any errors
				(if error
					(abort ("Error installing Serif1 Fonts."))
				)
			)
		)
	)
)

(complete 71)

(if (IN install_options 8)
	(
		; ----------
		; Get Disk 6
		;
		(askdisk
			(prompt "Please insert the disk labeled \"Disk 6\"")
			(help	"Disk 6 contains additional serif fonts "
					"that will be installed onto your system.")
			(dest "Disk 6")
		)

		; Instaling Serif2 fonts
		(if (IN install_options 8)
			(
				; If FWFonts/SWOLFonts/Serif doesn't exist, create it.
				(if (NOT (exists (tackon FW_dest "FWFonts/SWOLFonts/Serif")))
					(
					(makedir (tackon FW_dest "FWFonts/SWOLFonts/Serif") (infos))
					)
				)

				; Make installer cd into Serif when it executes the run statement
				(set @execute-dir (tackon FW_dest "FWFonts/SWOLFonts/Serif"))

				(working "Installing Serif Fonts from Disk 6.")
				(set error
					(run
						("\"%s\" -f x \"Disk 6:Serif2.lha\" >NIL:" DeArcher)
					)
				)

				; Abort if any errors
				(if error
					(abort ("Error installing Serif2 Fonts."))
				)
			)
		)
	)
)

(complete 86)

(if (IN install_options 8)
	(
		; ----------
		; Get Disk 7
		;
		(askdisk
			(prompt "Please insert the disk labeled \"Disk 7\"")
			(help	"Disk 7 contains additional sans serif fonts "
					"that will be installed onto your system.")
			(dest "Disk 7")
		)

		; Instaling Sans serif fonts
		(if (IN install_options 8)
			(
				; If FWFonts/SWOLFonts/Sans doesn't exist, create it.
				(if (NOT (exists (tackon FW_dest "FWFonts/SWOLFonts/Sans")))
					(
					(makedir (tackon FW_dest "FWFonts/SWOLFonts/Sans") (infos))
					)
				)

				; Make installer cd into Sans when it executes the run statement
				(set @execute-dir (tackon FW_dest "FWFonts/SWOLFonts/Sans"))

				(working "Installing Sans Serif Fonts from Disk 7.")
				(set error
					(run
						("\"%s\" -f x \"Disk 7:Sans.lha\" >NIL:" DeArcher)
					)
				)

				; Abort if any errors
				(if error
					(abort ("Error installing Sans Serif Fonts."))
				)
			)
		)
	)
)

; If FWDocs doesn't exist, create it.
(if (NOT (exists (tackon FW_dest "FWDocs")))
	(
	(makedir (tackon FW_dest "FWDocs") (infos))
	)
)

; If FWTextClips doesn't exist, create it.
(if (NOT (exists (tackon FW_dest "FWTextClips")))
	(
	(makedir (tackon FW_dest "FWTextClips") (infos))
	)
)

(delete DeArcher)

(complete 100)

(exit)

