; $VER: Digita Wordworth Fonts Installer Script 5/1/96
; By Mark Jackson
; English Language
;
; Copyright (C) Digita International

;------------------------------------------------------

;----------
; Variables
;----------

(set #Install1 "FontsInstall-1")
(set #Install2 "FontsInstall-2")
(set #Install3 "FontsInstall-3")

(set #Disk1 "WwOutlines-1")
(set #Disk2 "WwOutlines-2")
(set #Disk3 "WwOutlines-3")
(set #Disk4 "WwOutlines-4")
(set #Disk5 "WwOutlines-5")

(set #RamTools "RAM:Tools")


;-------------------
; String definitions
;-------------------

(set #InsertDiskMsg (cat "\nPlease insert the disk labelled\n\n\""))

(set #DiskHelp
	(cat "\n    If you know that the correct disk is in the drive, but you still cannot proceed, "
		"then the name of the disk is incorrect.\n"
		"    Ensure that the disk name is not preceded by 'copy_of_', or blank spaces before or after the disk name.\n\n\n" @askdisk-help
	)
)

(set #BlankDiskWarning
	(cat "\nPlease insert a 'blank' disk in the internal\n"
		"disk drive and click \"Proceed\" when ready."
		"\n\nWARNING: This procedure will destroy all information "
		"that may already be on the disk."
	)
)

(set #FloppyWarningHelp
	(cat 	"\nThis procedure uses the 'Format' command to "
		"wipe and prepare the disk in the internal disk drive."
		"\n\nWrite-protect your master disk before making a "
		"backup copy and keep it in a safe place."
		"\n\nEnsure the blank disk you insert to be formatted "
		"is write-enabled before clicking the \"Proceed\" button."
	)
)

(set #FormatWorkingMsgQuick "Please wait...\n\nQuick Formatting a disk.")

(set #FormatWorkingMsgSlow "Please wait...\n\nSlow Formatting a disk.")

(set #FormatError
	(cat 	"\nAn error occured when trying to format this disk.\n\n"
		"Please ensure that the disk is in the disk drive "
		"before you click the \"Proceed\" button or "
		"put another disk in the drive and try again."
	)
)

(set #FormatCompleteMsg1
	(cat " created.\n\nPlease take out the disk "
		"in the internal disk drive and label it \""
	)
)

(set #FormatCompleteMsg2
	(cat "\", then click the \"Proceed\" button.")
)

(set #DestChoicePrompt "\n\nWhere do you have Wordworth installed?")

(set #FloppyChoiceMsg "On floppy disks")
(set #HardDiskChoiceMsg "On a hard disk")

(set #DestChoiceHelp
	(cat "\nSelect the radio button \"On a hard disk\" to "
		"install the fonts onto your hard disk.\n\n"
		"Select the radio button \"On floppy disks\" to "
		"install the fonts onto a set of floppy disks.\n\n\n"
	)
)

(set #InstallOutlinesWorkingMsg
	(cat "\n\nPlease wait... Installing fonts")
)

(set #WwNotInstalledHDMsg
	(cat "\n\nWordworth does not seem to be installed on your hard-disk.\n\nClick "
		"\"Proceed\" to Exit.")
)

(set #WwNotInstalledFDMsg
	(cat "\n\nWordworth does not seem to be installed on your system.\n\n"
		"You must turn on your Amiga with the 'Wordworth' disk in the internal "
		"disk-drive and boot from this disk before running this installation.\n\n"
		"Click \"Proceed\" to Exit.")
)

(set #WwNotInstalledHelp
	(cat "\n    The installer could not find Wordworth installed on your system. "
		"You must install Wordworth first, before running this installation."
		"\n\nIf you have Wordworth installed on "
		"floppy-disks then you must boot your Amiga from the 'Wordworth' disk "
		"before running this installation, if you have Wordworth installed on a "
		"hard-disk then you must boot from the hard-disk before running this installation.")
)

(set #ArchiveAbortMsg1 "\n\nThere was a problem when trying to dearchive \n\n\"")

(set @default-dest "")


;--------------------------------
; Procedures...
;--------------------------------

(Procedure @UnpackFiles
	(
		(working (cat "\n\nPlease wait... Unarchiving File:\n\n\"" (fileonly #UnpackFile) "\"\n\nto the destination:\n\n\"" #UnpackDest "\""))

		(set #ArchiveError 0)
		(set #RunLhx (cat "Lhx -I -m e \"" #UnpackFile "\" \"" #UnpackDest "\""))

		(set #ArchiveError (run #RunLhx))
		(if (> #ArchiveError 0)
			(
				(set #ArchiveAbortMsg (cat #ArchiveAbortMsg1 (fileonly #UnpackFile) "\""))
				(abort #ArchiveAbortMsg)
			)
		)
	)
)


(Procedure @FormatDisk
	(
		(working #FormatWorkingMsgQuick)

		(set #FormatName (cat "\"" #FormatDiskName "\""))

		(set #FormatCheck
			(run ("Format drive=df0: name=%s FFS QUICK NOICONS" #FormatName))
		)

		(if (OR (> #FormatCheck 0) (< #FormatCheck 0))
			(
				(working #FormatWorkingMsgSlow)

				(set #FormatCheck
					(run ("Format drive=df0: name=%s FFS NOICONS" #FormatName))
				)

				(if (OR (> #FormatCheck 0) (< #FormatCheck 0))
					(set #NoError 1)
					(set #NoError 0)
				)
			)
			(set #NoError 0)
		)
	)
)


(Procedure @GetFontsDest
	(
		(if (NOT (exists "ENV:Wordworth/WwFonts"))
			(
				(if (= #DestinationType 0)
					(message #WwNotInstalledHDMsg (help #WwNotInstalledHelp))
					(message #WwNotInstalledFDMsg (help #WwNotInstalledHelp))
				)
				(exit)
			)
			(;else
				(set #DestPath (tackon (getenv "Wordworth/WwFonts") "Intellifont/"))
			)
		)
	)
)


(Procedure @InstallToHardDisk
	(
		(@GetFontsDest)

		(askdisk
			(prompt (cat #InsertDiskMsg #Install1 "\""))
			(dest #Install1)
			(help #DiskHelp)
		)

		(foreach (cat #Install1 ":Archive/") "#?.lha"
	        	(
				(set #UnpackFile (cat #Install1 ":Archive/" @each-name))
				(set #UnpackDest #DestPath)
				(@UnpackFiles)
	        	)
		)

		(askdisk
			(prompt (cat #InsertDiskMsg #Install2 "\""))
			(dest #Install2)
			(help #DiskHelp)
		)

		(foreach (cat #Install2 ":Archive/") "#?.lha"
	        	(
				(set #UnpackFile (cat #Install2 ":Archive/" @each-name))
				(set #UnpackDest #DestPath)
				(@UnpackFiles)
	        	)
		)

		(askdisk
			(prompt (cat #InsertDiskMsg #Install3 "\""))
			(dest #Install3)
			(help #DiskHelp)
		)

		(foreach (cat #Install3 ":Archive/") "#?.lha"
	        	(
				(set #UnpackFile (cat #Install3 ":Archive/" @each-name))
				(set #UnpackDest #DestPath)
				(@UnpackFiles)
	        	)
		)

; Now install the fonts!

		(set #RunInstallOutlines (cat "\"" (tackon #RamTools "InstallOutlines") "\" \"" #DestPath "\""))
		
		(working #InstallOutlinesWorkingMsg)
		(run #RunInstallOutlines)
		(set @default-dest #DestPath)
	)
)



(Procedure @InstallToFloppy
	(
		(@GetFontsDest)

		;// Format first disk

		(message #BlankDiskWarning (help #FloppyWarningHelp))

		(set #NoError 1)
		(while (= #NoError 1)
			(
				(run "Wait 4")  ; Wait a bit for disk access to stop

				(set #NoError 1)
				(set #FormatDiskName #Disk1)
				(@FormatDisk)
				(if (= #NoError 1)
					(message #FormatError (help #FormatErrorHelp))
				)
        		)
		)

		(message (cat #FormatDiskName #FormatCompleteMsg1 #FormatDiskName  #FormatCompleteMsg2))

		(askdisk
			(prompt (cat #InsertDiskMsg #Install1 "\""))
			(dest #Install1)
			(help #DiskHelp)
		)

		(copyfiles
			(source (cat #Install1 ":Archive/"))
			(dest "Ram:Archive")
			(pattern ("~(Wistata.lha)"))
			(optional "force")
		)

		(askdisk
			(prompt (cat #InsertDiskMsg #Disk1 "\""))
			(dest #Disk1)
			(help #DiskHelp)
		)

		(foreach "Ram:Archive/" "#?.lha"
	        	(
				(set #UnpackFile (cat "Ram:Archive/" @each-name))
				(set #UnpackDest (cat #Disk1 ":"))
				(@UnpackFiles)
	        	)
		)

		(run "delete Ram:Archive/#?.lha")

		;// Format second disk

		(message #BlankDiskWarning (help #FloppyWarningHelp))

		(set #NoError 1)
		(while (= #NoError 1)
			(
				(run "Wait 4")  ; Wait a bit for disk access to stop

				(set #NoError 1)
				(set #FormatDiskName #Disk2)
				(@FormatDisk)
				(if (= #NoError 1)
					(message #FormatError (help #FormatErrorHelp))
				)
        		)
		)

		(message (cat #FormatDiskName #FormatCompleteMsg1 #FormatDiskName  #FormatCompleteMsg2))

		(askdisk
			(prompt (cat #InsertDiskMsg #Install1 "\""))
			(dest #Install1)
			(help #DiskHelp)
		)

		(copyfiles
			(source (cat #Install1 ":Archive/"))
			(dest "Ram:Archive")
			(pattern ("Wistata.lha"))
			(optional "force")
		)

		(askdisk
			(prompt (cat #InsertDiskMsg #Disk2 "\""))
			(dest #Disk2)
			(help #DiskHelp)
		)

		(foreach "Ram:Archive/" "#?.lha"
	        	(
				(set #UnpackFile (cat "Ram:Archive/" @each-name))
				(set #UnpackDest (cat #Disk2 ":"))
				(@UnpackFiles)
	        	)
		)

		(run "delete Ram:Archive/#?.lha")

		(askdisk
			(prompt (cat #InsertDiskMsg #Install2 "\""))
			(dest #Install2)
			(help #DiskHelp)
		)

		(copyfiles
			(source (cat #Install2 ":Archive/"))
			(dest "Ram:Archive")
			(pattern ("(Katharina.lha|Lucida-Bold.lha|Lucida-BoldItalic.lha|Lucida.lha|NewBrunswick.lha|NewBrunswick_Bold.lha|NewBrunswick_BoldItal.lha|NewBrunswick_Italic.lha|NewCenSchBolIta.lha|NovareseBk.lha|NovareseBkIt.lha)"))
			(optional "force")
		)

		(askdisk
			(prompt (cat #InsertDiskMsg #Disk2 "\""))
			(dest #Disk2)
			(help #DiskHelp)
		)

		(foreach "Ram:Archive/" "#?.lha"
	        	(
				(set #UnpackFile (cat "Ram:Archive/" @each-name))
				(set #UnpackDest (cat #Disk2 ":"))
				(@UnpackFiles)
	        	)
		)

		(run "delete Ram:Archive/#?.lha")

		;// Format third disk

		(message #BlankDiskWarning (help #FloppyWarningHelp))

		(set #NoError 1)
		(while (= #NoError 1)
			(
				(run "Wait 4")  ; Wait a bit for disk access to stop

				(set #NoError 1)
				(set #FormatDiskName #Disk3)
				(@FormatDisk)
				(if (= #NoError 1)
					(message #FormatError (help #FormatErrorHelp))
				)
        		)
		)

		(message (cat #FormatDiskName #FormatCompleteMsg1 #FormatDiskName  #FormatCompleteMsg2))

		(askdisk
			(prompt (cat #InsertDiskMsg #Install2 "\""))
			(dest #Install2)
			(help #DiskHelp)
		)

		(copyfiles
			(source (cat #Install2 ":Archive/"))
			(dest "Ram:Archive")
			(pattern ("~(Katharina.lha|Lucida-Bold.lha|Lucida-BoldItalic.lha|Lucida.lha|NewBrunswick.lha|NewBrunswick_Bold.lha|NewBrunswick_BoldItal.lha|NewBrunswick_Italic.lha|NewCenSchBolIta.lha|NovareseBk.lha|NovareseBkIt.lha)"))
			(optional "force")
		)

		(askdisk
			(prompt (cat #InsertDiskMsg #Disk3 "\""))
			(dest #Disk3)
			(help #DiskHelp)
		)

		(foreach "Ram:Archive/" "#?.lha"
	        	(
				(set #UnpackFile (cat "Ram:Archive/" @each-name))
				(set #UnpackDest (cat #Disk3 ":"))
				(@UnpackFiles)
	        	)
		)

		(run "delete Ram:Archive/#?.lha")

		(askdisk
			(prompt (cat #InsertDiskMsg #Install3 "\""))
			(dest #Install3)
			(help #DiskHelp)
		)

		(copyfiles
			(source (cat #Install3 ":Archive/"))
			(dest "Ram:Archive")
			(pattern ("Caligula.lha"))
			(optional "force")
		)

		(askdisk
			(prompt (cat #InsertDiskMsg #Disk3 "\""))
			(dest #Disk3)
			(help #DiskHelp)
		)

		(foreach "Ram:Archive/" "#?.lha"
	        	(
				(set #UnpackFile (cat "Ram:Archive/" @each-name))
				(set #UnpackDest (cat #Disk3 ":"))
				(@UnpackFiles)
	        	)
		)

		(run "delete Ram:Archive/#?.lha")

		;// Format fourth disk

		(message #BlankDiskWarning (help #FloppyWarningHelp))

		(set #NoError 1)
		(while (= #NoError 1)
			(
				(run "Wait 4")  ; Wait a bit for disk access to stop

				(set #NoError 1)
				(set #FormatDiskName #Disk4)
				(@FormatDisk)
				(if (= #NoError 1)
					(message #FormatError (help #FormatErrorHelp))
				)
        		)
		)

		(message (cat #FormatDiskName #FormatCompleteMsg1 #FormatDiskName  #FormatCompleteMsg2))

		(askdisk
			(prompt (cat #InsertDiskMsg #Install3 "\""))
			(dest #Install3)
			(help #DiskHelp)
		)

		(copyfiles
			(source (cat #Install3 ":Archive/"))
			(dest "Ram:Archive")
			(pattern ("(Bangkok.lha|Baskerville.lha|Baskerville_Bold.lha|Baskerville_BoldItal.lha|Baskerville_Italic.lha|Bodoni.lha|Bodoni_Bold.lha|Bodoni_BoldItalic.lha|Bodoni_Italic.lha|Chicagolaser.lha|CochinCond.lha|Dijon.lha)"))
			(optional "force")
		)

		(askdisk
			(prompt (cat #InsertDiskMsg #Disk4 "\""))
			(dest #Disk4)
			(help #DiskHelp)
		)

		(foreach "Ram:Archive/" "#?.lha"
	        	(
				(set #UnpackFile (cat "Ram:Archive/" @each-name))
				(set #UnpackDest (cat #Disk4 ":"))
				(@UnpackFiles)
	        	)
		)

		(run "delete Ram:Archive/#?.lha")

		;// Format fifth disk

		(message #BlankDiskWarning (help #FloppyWarningHelp))

		(set #NoError 1)
		(while (= #NoError 1)
			(
				(run "Wait 4")  ; Wait a bit for disk access to stop

				(set #NoError 1)
				(set #FormatDiskName #Disk5)
				(@FormatDisk)
				(if (= #NoError 1)
					(message #FormatError (help #FormatErrorHelp))
				)
        		)
		)

		(message (cat #FormatDiskName #FormatCompleteMsg1 #FormatDiskName  #FormatCompleteMsg2))

		(askdisk
			(prompt (cat #InsertDiskMsg #Install3 "\""))
			(dest #Install3)
			(help #DiskHelp)
		)

		(copyfiles
			(source (cat #Install3 ":Archive/"))
			(dest "Ram:Archive")
			(pattern ("~(Caligula.lha|Bangkok.lha|Baskerville.lha|Baskerville_Bold.lha|Baskerville_BoldItal.lha|Baskerville_Italic.lha|Bodoni.lha|Bodoni_Bold.lha|Bodoni_BoldItalic.lha|Bodoni_Italic.lha|Chicagolaser.lha|CochinCond.lha|Dijon.lha)"))
			(optional "force")
		)

		(askdisk
			(prompt (cat #InsertDiskMsg #Disk5 "\""))
			(dest #Disk5)
			(help #DiskHelp)
		)

		(foreach "Ram:Archive/" "#?.lha"
	        	(
				(set #UnpackFile (cat "Ram:Archive/" @each-name))
				(set #UnpackDest (cat #Disk5 ":"))
				(@UnpackFiles)
	        	)
		)

		(run "delete Ram:Archive/#?.lha")

; Now install the fonts

		(askdisk
			(prompt (cat #InsertDiskMsg #Disk1 "\""))
			(dest #Disk1)
			(help #DiskHelp)
		)

		(set #RunInstallOutlines (cat "\"" (tackon #RamTools "InstallOutlines") "\" \"" #Disk1 ":\""))
		
		(working #InstallOutlinesWorkingMsg)
		(run #RunInstallOutlines)

		(askdisk
			(prompt (cat #InsertDiskMsg #Disk2 "\""))
			(dest #Disk2)
			(help #DiskHelp)
		)

		(set #RunInstallOutlines (cat "\"" (tackon #RamTools "InstallOutlines") "\" \"" #Disk2 ":\""))
		
		(working #InstallOutlinesWorkingMsg)
		(run #RunInstallOutlines)

		(askdisk
			(prompt (cat #InsertDiskMsg #Disk3 "\""))
			(dest #Disk3)
			(help #DiskHelp)
		)

		(set #RunInstallOutlines (cat "\"" (tackon #RamTools "InstallOutlines") "\" \"" #Disk3 ":\""))
		
		(working #InstallOutlinesWorkingMsg)
		(run #RunInstallOutlines)

		(askdisk
			(prompt (cat #InsertDiskMsg #Disk4 "\""))
			(dest #Disk4)
			(help #DiskHelp)
		)

		(set #RunInstallOutlines (cat "\"" (tackon #RamTools "InstallOutlines") "\" \"" #Disk4 ":\""))
		
		(working #InstallOutlinesWorkingMsg)
		(run #RunInstallOutlines)

		(askdisk
			(prompt (cat #InsertDiskMsg #Disk5 "\""))
			(dest #Disk5)
			(help #DiskHelp)
		)

		(set #RunInstallOutlines (cat "\"" (tackon #RamTools "InstallOutlines") "\" \"" #Disk5 ":\""))
		
		(working #InstallOutlinesWorkingMsg)
		(run #RunInstallOutlines)

		(set @default-dest "")
	)
)



;--------------------------------
; Start here!
;--------------------------------


	(askdisk
		(prompt (cat #InsertDiskMsg #Install1 "\""))
		(dest #Install1)
		(help #DiskHelp)
	)

	(run (cat "resident " #Install1 ":Utils/Format"))
	(run (cat "resident " #Install1 ":Utils/lhx"))
	(run (cat "resident " #Install1 ":Utils/Wait"))
	(run (cat "resident " #Install1 ":Utils/Delete"))

	(if (NOT (exists #RamTools))
		(makedir #RamTools (safe))
	)

	(copyfiles
		(source (cat #Install1 ":Utils"))
		(dest #RamTools)
		(pattern "InstallOutlines")
		(optional "force")
		(nogauge)
	)


	;// Floppy or HD ?
	(set #FullPath (expandpath "sys:"))

	(if (= #FullPath "Wordworth5:")
		(set #DiskDefault 1)
		(set #DiskDefault 0)
	)

	(set #DestinationType
		(askchoice
			(prompt #DestChoicePrompt)
			(choices #HardDiskChoiceMsg #FloppyChoiceMsg)
			(help #DestChoiceHelp)
			(default #DiskDefault)
		)
	)

	(if (= #DestinationType 0)
		(@InstallToHardDisk)
		(@InstallToFloppy)
	)

	(run "delete Ram:Archive all force")
	(run (cat "delete " #RamTools "all force"))

	(run "resident Format Remove")
	(run "resident lhx Remove")
	(run "resident Wait Remove")
	(run "resident Delete Remove")


(exit)