;********************************************************************
; $VER: InstallPatch V3.00 Monday 07-Nov-94 12:53:42
;       Inovatronics, Inc.
;       Suite 209b
;       8499 Greenville Ave
;       Dallas, Texas 75231
;       USA
;********************************************************************
; History
; v3.00 based on Install-CanDo and InstallCanDo
; v1.xx & 2.xx old versions of the install script
;********************************************************************
; The required variables
;********************************************************************
(set true 1)
(set false 0)
(set not_here 0)
(set is_a_file 1)
(set is_a_dir 2)
(set newline "\n")
(set quote "\"")
(set nothing "")
(set testing true)
(set testing false)
(delopts "AskUser" "OkNoDelete" "Force")
(set cpu (database "CPU"))
(set aga (= (database "CHIPREV") "AA"))

;********************************************************************
; The common/general/english strings
;********************************************************************
(set Intro_text
	(cat
		"Welcome to the CanDo Patch installer.  This installer uses the "
		"Commodore Amiga Installer.  All of our products use this "
		"installer and we would love to get any feedback that might "
		"help improve the installation procedure." newline
	)
)

(set IsCanDoHere_text
	(cat
		"This appears to be were CanDo is installed.  Is this correct?"
	)
)

(set Unarchiving_text
	(cat
		"One moment please, unarchiving"
		newline
		newline
	)
)

(set Final_text
	(cat
		"The CanDo patch has now been successfully installed on your "
		"machine.  You are now updated to "
	)
)

(set PathPrefix "Path=")

(set FilePrefix "File(s)=")


;********************************************************************
; The error strings
;********************************************************************

(set NoCanDo_error
	(cat
		"We cannot find the CanDo: assignment.  That means that CanDo "
		"has either not been installed or incorrectly installed."
		newline
	)
)

(set NotThree_error
	(cat
		"The CanDo installed is not v3.0.  It is possible that the CanDo: "
		"assignment is pointing to the wrong program.  If so please point "
		"it at your CanDo v3.0 and then re-run the patch installer."
		newline
	)
)

(set NoNeed_error
	(cat
		"The CanDo installed is newer than this patch so we do not need to patch it."
		newline
	)
)

(set NoSupport_error
	(cat
		"We could not find these support files in Ram:.  "
		"Please reboot and try to install again."
		newline
	)
)

(set DirIsAFile_error
	(cat
		"Should be a directory but it is actually a file..."
		newline
	)
)

(set DirNotMade_error
	(cat
		"We could not create the directory..."
		newline
	)
)


;********************************************************************
; The language specific strings, overlay the pre-defined strings
;********************************************************************
(if (= @language "deutsch")
	(
		; german strings go here

		(set Intro_text
			(cat "Willkommen zum Installationsprogramm von " progname ". "
		     "Um die Installtion für Sie so einfach wie möglich zu gestalten, "
		     "benutzen wir den Commodore-Installer."
		     newline newline
			)
		)
	)
)

;********************************************************************
; Some common procedures
;********************************************************************
; where do we install the CanDo directory
(procedure find_home_dir
	(
		; if we were installed, where are we?
		(if (= testing true)
			(set CanDo_dir "Ram:")
			(set CanDo_dir (getassign "CanDo"))
		)
		
		; is CanDo assign made?
		(if (= CanDo_dir nothing)
			(abort NoCanDo_error)
		)
		
		; where are we to install?
		(set cando_dir
			(askdir
				(prompt IsCanDoHere_text)
				(help @askdir-help)
				(default cando_dir)
				(newpath)
			)
		)

		; what CanDo is to be installed?
		(run "version >env:candoversion CanDo_Patch_Install:CanDo")
		(set newcando (getenv "candoversion"))
		(set newver (+ (substr newcando 6 1) 0))
		(set newrev (+ (substr newcando 8 3) 0))
		
		; is CanDo already installed here?
		(run "version >env:candoversion CanDo:CanDo")
		(set oldcando (getenv "candoversion"))
		(set oldver (+ (substr oldcando 6 1) 0))
		(set oldrev (+ (substr oldcando 8 3) 0))
		
		; hey its not v3.0!
		(if (<> oldver 3)
			(abort NotThree_error)
		)
		
		; is the new revision greater than the installed one?
		(if (> oldrev newrev)
			(abort NoNeed_error)
		)
	)
)


; unarchive an archive, destination=path/file, archive=path
(procedure unarchive
	(
		(set destination (pathonly destination))
		(insure_dir)
		
		; create a batch file
		(textfile
			(dest "Ram:LHEX.script")
			(append
				(cat
					"Cd " quote thepath quote newline
					"Stack 20480" newline
					"Ram:LHEX -qf x " quote archive quote newline
				)
			)
		)
		
		; unarchive then
		(working Unarchiving_Text FilePrefix quote archive quote newline PathPrefix quote thepath quote)
		(execute "Ram:LHEX.script")
	)
)

; insure a directory exists, destination=path
(procedure insure_dir
	(
		(set thepath destination)
		
		; if it is a file then abort
		(if (= (exists thepath) is_a_file)
			(abort DirIsAFile_error PathPrefix quote thedir quote)
		)
		
		; if it doesn't exist make it
		(if (= (exists thepath) not_here)
			(
				(working CreateDir_text PathPrefix quote thepath quote)
				(makedir thepath (infos))
			)
		)
		
		; verify it actually is a directory
		(if (<> (exists thepath) is_a_dir)
			(abort DirNotMade_error quote thedir quote)
		)
	)
)

;********************************************************************
; The error handler
;********************************************************************
(onerror
	(delete "Ram:LHEX" (safe))
	(delete "Ram:LHEX.script" (safe))
)


; *******************************************************************
; on with the show
; *******************************************************************
(welcome intro_text)

; where are we?
(makeassign "CanDo_Patch_Install" "" (safe))

; where to install?
(find_home_dir)

; to novice mode
(user 0)

; how far have we come?
(complete 0)


; *******************************************************************
; copy LHEX to ram:
; *******************************************************************
; verify we got LHEX into ram:
(if (<> (exists "Ram:LHEX") is_a_file)
	(copyfiles
		(source "CanDo_Patch_Install:LHEX")
		(dest "Ram:")
		(files)
	)
)

; verify we got LHEX into ram:
(if (<> (exists "Ram:LHEX") is_a_file)
	(abort NoSupport_error quote "LHEX" quote)
)


; *******************************************************************
; copy readme to the destination
; *******************************************************************
(copyfiles
	(source "CanDo_Patch_Install:CanDoPatch.doc")
	(dest cando_dir)
	(files)
	(infos)
)

; how far have we come?
(complete 25)


; *******************************************************************
; delete CanDo and install new one
; *******************************************************************
(set destination (tackon cando_dir "CanDo"))
(set archive "CanDo_Patch_Install:CanDo_Stuff.lha")
(unarchive)

; how far have we come?
(complete 75)


; *******************************************************************
; Libs: CanDo.library
; *******************************************************************
(set destination "Libs:CanDo.library")
(set archive "CanDo_Patch_Install:CanDo_Libs.lha")
(unarchive)

; how far have we come?
(complete 100)


; *******************************************************************
; ok we are done then
; *******************************************************************
(delete "Ram:LHEX" (safe))
(delete "Ram:LHEX.script" (safe))
(makeassign "CanDo_Patch_Install" (safe))
(set @default-dest cando_dir)
(exit Final_text newcando)
