;=============================================================================
; $VER: Update_CygnusEd 1.3 (18.01.99)
;=============================================================================

;=============================================================================
; Procedures
;=============================================================================
(procedure P_PatchFile #patch #orig #to
(
	(set #cmd (cat "spatch   -o" (tackon #to (fileonly #orig))
	                       " -p" #patch ".pch"
	                       " "   "CygnusEd_Pro_4:CygnusEd/" #orig
	))
	(working (cat "Updating \"" (fileonly #orig) "\""))
	(run #cmd)
))

;=============================================================================
; Start of installation script
;=============================================================================
(complete 0)

(if (< (/ @installer-version 65536) 43)
(
	(abort (cat
		"This installation script requires the Installer tool V43"
	))
))

(if (< (getversion) (* 37 65536))
	(abort (cat
		"CygnusEd Professional Release 4 requires operating system "
		"version 2.04 or higher to work."
	))
)

;=============================================================================
; Tell the user that we will only update a few files, but not perform a
; complete installation.
;=============================================================================
(message (cat
	"This program will install updated versions of certain CygnusEd Professional "
	"Release 4 distribution files (CygnusEd, MetaMac, RecoverCEDFiles, foreign "
	"language catalogs, online documentation). As such, it does not perform "
	"a complete reinstallation of CygnusEd.\n\n"
	"While you will be asked mostly the same questions as during the original "
	"installation process, this program can only work on an existing CygnusEd "
	"installation. Thus, if you haven't installed CygnusEd Professional "
	"Release 4 yet, you should do it before you run this program.\n\n"
	"Note that the update process will overwrite all files to be updated, "
	"no backup copies will be made."
))

;=============================================================================
; Ask for the installation directory
;=============================================================================
(set #not-found 1)

(while #not-found
(
	(set #default-dest (askdir
		(prompt (cat
			"Please select where CygnusEd Professional was installed."
		))
		(help @askdir-help)
		(default @default-dest)
	))

	(if (= (exists (tackon #default-dest "CED")) 1)
	(
		(set #not-found 0)
	)
	(
		(message (cat "The CygnusEd text editor program could not be "
		              "found in the drawer \"" #default-dest "\". Please "
		              "try again."
		))
	))
))

(set @default-dest #default-dest)

(complete 10)

(set #special-version 0)
(if (not (patmatch "68000|68010" (database "cpu")))
(
	(set #special-version (askbool
		(prompt (cat
			"Do you want to have a special CygnusEd version installed "
			"which is customized for your Amiga's CPU?"
		))
		(default 1)
		(help (cat
			"A special version of the editor is provided which was "
			"created for use on Amigas equipped with an MC68020 CPU "
			"or a more recent model. This version can perform a little "
			"faster than the generic version and is also a bit smaller."
		))
	))
))

(complete 20)

;=============================================================================
; Create the installation drawer unless it already exists
;=============================================================================
(if (= (exists @default-dest) 0)
(
	(makedir @default-dest (infos))
))

(complete 30)

;=============================================================================
; Install CygnusEd, utilities and documentation
;=============================================================================
(if #special-version
(
	(set #special-patch "CED.020")
	(set #special-orig "020/CED")
)
(
	(set #special-patch "CED.68k")
	(set #special-orig "CED")
))

(makeassign "CED_DEST_TEMP" @default-dest)
(P_PatchFile #special-patch #special-orig "CED_DEST_TEMP:")
(complete 50)
(P_PatchFile "MetaMac" "MetaMac" "CED_DEST_TEMP:")
(complete 60)
(P_PatchFile "RecoverCEDFiles" "RecoverCEDFiles" "CED_DEST_TEMP:")
(complete 70)
(P_PatchFile "ED" "ED" "CED_DEST_TEMP:")
(complete 80)
(makeassign "CED_DEST_TEMP")

(copyfiles
	(source	"CygnusEd_Manual.guide")
	(dest	@default-dest)
)
(complete 90)

;=============================================================================
; Install the catalogs
;=============================================================================
(if (not (= (getassign "LOCALE") ""))
(
	(copyfiles
		(source "Catalogs")
		(dest "Locale:Catalogs")
		(all)
	)
))

(complete 100)
