; Opus_Patch565-566
; Installer script to update Directory Opus Magellan version 5.65 to 5.66
;
; Directory Opus Update Version $VER: Opus_Patch565-566  (03.11.97)

; COPYRIGHT ©1997 GP SOFTWARE, AUSTRALIA


(complete 0)

(procedure clear_assigns

	(makeassign "DOPNEW")
	(makeassign "PCH")
	(makeassign "DOPOLD")
)

(procedure signal_opus

	(set #Sigs (tackon #SRC "dopusmsg"))
	(if (exists #Sigs (noreq))
		(run (cat #Sigs " DOPUS.1 \"command set notify off\""))
	)
)

(procedure make_newfiles ; (#EXT) requires #EXT to be set before call

		(working "Updating modules/configopus.module")
		(run (cat (tackon #SRC "spatch") " -oDOPNEW:modules/configopus.module -pPCH:configopus."#EXT" DOPOLD:modules/configopus.module"))
		(working "Updating modules/diskinfo.module")
		(run (cat (tackon #SRC "spatch") " -oDOPNEW:modules/diskinfo.module -pPCH:diskinfo."#EXT" DOPOLD:modules/diskinfo.module"))
		(working "Updating modules/icon.module")
		(run (cat (tackon #SRC "spatch") " -oDOPNEW:modules/icon.module -pPCH:icon."#EXT" DOPOLD:modules/icon.module"))
		(working "Updating modules/ftp.module")
		(run (cat (tackon #SRC "spatch") " -oDOPNEW:modules/ftp.module -pPCH:ftp."#EXT" DOPOLD:modules/ftp.module"))
		(working "Updating modules/join.module")
		(run (cat (tackon #SRC "spatch") " -oDOPNEW:modules/join.module -pPCH:join."#EXT" DOPOLD:modules/join.module"))
		(working "Updating modules/play.module")
		(run (cat (tackon #SRC "spatch") " -oDOPNEW:modules/play.module -pPCH:play."#EXT" DOPOLD:modules/play.module"))
		(working "Updating modules/read.module")
		(run (cat (tackon #SRC "spatch") " -oDOPNEW:modules/read.module -pPCH:read."#EXT" DOPOLD:modules/read.module"))

		(working "Updating libs/dopus5.library")
		(run (cat (tackon #SRC "spatch") " -oDOPNEW:libs/dopus5.library -pPCH:dopuslib."#EXT" DOPOLD:libs/dopus5.library"))
		(working "Updating DirectoryOpus")
		(run (cat (tackon #SRC "spatch") " -oDOPNEW:DirectoryOpus -pPCH:dopus."#EXT" DOPOLD:DirectoryOpus"))

)


(procedure wrong_version

	(message #Title_msg
		"Sorry, you have the wrong version of DirectoryOpus.\n\n"
		"This upgrade will NOT WORK for your version.\n"

		#README

		"Your Opus version is "#dop_ver"."#dop_rev".\n"
		"and the library is "#lib_ver"."#lib_rev"\n")

	(exit "Installation terminated!")

)

(procedure anyone_home

	(message #Title_msg
		"Sorry, cannot find DirectoryOpus on you system!\n\n"
		#README)
		
	(exit "Installation terminated!")

)

(procedure wrong_dopus

		
	(message #Title_msg
		"Sorry, you have the wrong version of DirectoryOpus.\n\n"
		"This upgrade will NOT WORK for your version.\n\n"

		#README

		"Your Opus version is "#dop_ver"."#dop_rev".\n")

	(exit "Instalation terminated!")
)


(procedure get_ext
; work out which library version, should be enough
; 

	(set #lib_ver 0)

	(if (exists #DOPUSLIB (noreq))
		(
		(set #Vernum (getversion #DOPUSLIB))
		(set #lib_ver (/ #Vernum 65536))
		(set #lib_rev (- #Vernum (* #lib_ver 65536) ) )
	
		(if	(AND (= #lib_ver 62 ) (= #lib_rev 9 ))
			(
			(set #EXT "pch66")
			(set #PATCHNAME "Opus6566Patch.lha")
			)
		)
		)
		(anyone_home)

	)

	(if	(OR(= #lib_ver 0) (= #lib_rev 0 ))
		(wrong_version)
	)
)

;
; start
;

(
(onerror clear_assigns)


(set #OLD_OPUS "DOpus5:")
(set #FINAL "DOpus5:")
(set @default-dest #FINAL)

(set #NEW_OPUS "ram:OP566")
(set #PCH_TMP "ram:OPPCHTMP")
(set #SRC "ram:PCH566")
(set #WANTVER 65)

(set #DOPUSPROG (tackon #OLD_OPUS "DirectoryOpus"))
(set #DOPUSLIB (tackon #OLD_OPUS "libs/dopus5.library"))

(set #README "Please read the ReadMe acompanying this archive or contact GPSoftware for details of upgrades\n\n")

(clear_assigns)
(signal_opus)


(makeassign "DOPOLD" #OLD_OPUS)
(makedir #NEW_OPUS)

(makeassign "DOPNEW"  #NEW_OPUS)
(makedir "DOPNEW:modules")

(makedir "DOPNEW:c")
(makedir "DOPNEW:help")
(makedir "DOPNEW:libs")

(makedir #PCH_TMP)
(makeassign "PCH" #PCH_TMP)


; main procedure


	(set #Title_msg "Directory Opus Magellan Update Patch.\n\n")

	(message #Title_msg
		"This procedure will update your existing version of"
		" Directory Opus Magellan 5.65 to version  5.66.\n\n"
		"When finished, you will need to reboot your Amiga."
		)

	(if (exists #DOPUSPROG (noreq))
		(
		(set #Vernum (getversion #DOPUSPROG))
		(set #Dop_ver (/ #Vernum 65536))
		(set #Dop_rev (- #Vernum (* #Dop_ver 65536) ) )
		);else
		(anyone_home)
	)


	(if	(AND (= #dop_ver 5 ) (= #dop_rev #WANTVER ))
		(get_ext)
		(wrong_dopus) ;else

	)
 
	(if (exists (tackon #SRC #PATCHNAME))
		(
		(working "Unarchiving patch files...")
		(run (cat (tackon #SRC "lhex") " >NIL: <NIL: -qfw=PCH: x " (tackon #SRC #PATCHNAME)))

		(make_newfiles)
	
		(copyfiles (source "DOPNEW:") (dest #FINAL) (all) (optional force))
		(copyfiles (source (tackon #SRC "ReadMe_Magellan566")) (dest #FINAL) (infos))

	
		;
		; tidyup
		;

		(clear_assigns)
		(run (cat "C:Delete " #PCH_TMP " all"))
		(run (cat "C:Delete " #NEW_OPUS " all"))
	
		); else
		(message #Title_msg
			"Woops! Cannot find the patch archive\n"
			 "Required archive: "#PATCHNAME".\n\n"
		)
		
	)

(clear_assigns)
)
