; ImageFX 3.1 Patch Install Script
;
; Written by Thomas Krehbiel
;
; Copyright © 1998 Nova Design, Inc.
; All Rights Reserved

(

   ;================================================================
   ; Procedure Definitions
   ;================================================================

   (procedure RunLhex
      ; pf_archive = name of archive to extract from
      ; pf_name = name of file to extract
      ; tempdir = directory to extract to
      (
	 (set pf_error
	    (run
	       ("RAM:lhex -a -f \"-w=%s\" x %s %s"
		  tempdir
		  pf_archive
		  pf_name
	       )
	    )
	 )
      )
   )

   (procedure RunPatch
      ; pf_old = old version of file
      ; pf_new = where to put new version of file
      ; pf_patch = name of patch file
      (
	 (set pf_error
	    (run
	       ("RAM:spatch \"-o%s\" \"-p%s\" \"%s\""
		  pf_new
		  pf_patch
		  pf_old
	       )
	    )
	 )
      )
   )

   (procedure DoPatch
      ; pf_name = name of file with path
      ; wheredir = where old files reside
      ; patchdir = where patches reside
      (
	 (set pf_user (tackon wheredir pf_name))
	 (set pf_old (tackon tempdir pf_name))
	 (set pf_new ("%s.new" (tackon wheredir pf_name)))
	 (set pf_patch ("%s.pch" (tackon patchdir pf_name)))
	 (if (exists pf_user)
	    (
	       ; only if it was installed
	       (working "Reading " pf_archive)
	       (RunLhex)
	       (if pf_error
		  (
		     (message "LHEX failed on `" pf_archive "'.")
		  )
	       )
	       (working "Updating " pf_name)
	       (RunPatch)
	       (if pf_error
		  (
		     (message "Patch failed on file `" pf_user "'.")
		  )
		  ; else
		  (
		     (delete pf_user)
		     (rename pf_new pf_user)
		  )
	       )
	       (delete pf_old)
	    )
	 )
      )
   )

   ;================================================================
   ; Setup
   ;================================================================

   ; script variables...

   (set versionname "3.1")			; version number
   (set programname ("ImageFX %s" versionname)) ; name of program
   (set diskname1 "ImageFX30_Disk1:")		; install disk name
   (set diskname2 "ImageFX30_Disk2:")		; second install disk name
   (set diskname3 "ImageFX30_Disk3:")		; third install disk name
   (set diskname4 "ImageFX30_Disk4:")		; fourth install disk name
   (set diskname5 "ImageFX30_Disk5:")		; fifth install disk name
   (set diskname6 "ImageFX30_Disk6:")		; sixth install disk name
   (set pdiskname1 "")				; patch install disk name

   (set patcharc "patches.lha") 		; patches with spatch

   (set tempdir "T:")

   ; system information...

   (set osver (/ (getversion) 65536))	     ; os version
   (set cputype (database "cpu"))	     ; cpu type

   ;-------------------
   ; Pick a default directory for the installation...
   (set initialdir @default-dest)	     ; defaults to biggest drive
   (if (getassign "ImageFX3")
      (
	 (set initialdir (getassign "ImageFX3"))
      )
   )

   (set tryagain 1)
   (while tryagain
      (

	 (set tryagain 0)

	 ;-------------------
	 ; Ask where to install it...
	 ;(set wheredir initialdir)
	 (set wheredir
	    (askdir
	       (prompt "Select the directory where ImageFX is currently installed.  The files in "
		       "this directory will be updated to version " versionname ".  All of your "
		       "preferences will be preserved.  NOTE:  You will need your original ImageFX 3.0 "
		       "disks to install this update (they will not be modified).")
	       (help @askdir-help)
	       (default initialdir)
	    )
	 )

	 ;-------------------
	 ; Make sure it's a valid ImageFX
	 (set checkvar 0)
	 (set checkvar (+ checkvar (exists (tackon wheredir "Modules/FX/Negative"))))
	 (if (= 0 checkvar)
	    (
	       (message "`" wheredir "' does not appear to contain a copy of ImageFX 3.0.")
	       (set tryagain 1)
	       (set initialdir wheredir)
	    )
	 )

      )
   )

   (message "The " programname " update will be installed in the drawer `" wheredir "'.  If this is correct, click `Proceed'.")

   (set @default-dest wheredir)

   ;-------------------
   ; Copy SPATCH to RAM: for speediness
   (copyfiles
      (prompt "")
      (help "")
      (source pdiskname1)
      (dest "RAM:")
      (choices "spatch")
   )

   ;================================================================
   ; DISK 1
   ;================================================================

   (askdisk
      (prompt "Please insert ImageFX 3.0 Disk 1 in any drive.")
      (help "")
      (dest (substr diskname1 0 (- (strlen diskname1) 1)))
      (assigns)
   )

   ;-------------------
   ; Copy LHEX to RAM: for speediness
   (copyfiles
      (prompt "")
      (help "")
      (source "")
      (dest "RAM:")
      (choices "lhex")
   )

   ;-------------------
   ; Begin by extracting our patch archive into the user's
   ; chosen ImageFX directory.	This will be deleted at the end.

   (working "Extracting Update Files...")

   (set patchdir (tackon wheredir "Patches"))
   (makedir patchdir)

   (run
      ("RAM:lhex >CON:0/0//80/lhex/AUTO -a -f \"-w=%s\" x %s"
	 patchdir
	 (tackon pdiskname1 patcharc)
      )
   )

   ;-------------------
   ; Patch ImageFX Executable

   (copyfiles
      (prompt "")
      (help "")
      (source diskname1)
      (dest tempdir)
      (choices "Program.lha")
   )

   (set pf_archive (tackon tempdir "Program.lha"))

   (set pf_name "ImageFX") (DoPatch)

   (delete (tackon tempdir "Program.lha"))

   ;-------------------
   ; Upgrades (just copy modules)

   (copyfiles
      (prompt "")
      (help "")
      (source (tackon patchdir "Modules/Loaders"))
      (dest (tackon wheredir "Modules/Loaders"))
      (choices "ILBM")
   )

   (copyfiles
      (prompt "")
      (help "")
      (source (tackon patchdir "Modules/Preview"))
      (dest (tackon wheredir "Modules/Preview"))
      (choices "Windowed" "WindowedCGX" "Toaster")
   )

   (copyfiles
      (prompt "")
      (help "")
      (source (tackon patchdir "Modules/Scanner"))
      (dest (tackon wheredir "Modules/Scanner"))
      (choices "Epson" "ScanJet")
   )

   (copyfiles
      (prompt "")
      (help "")
      (source (tackon patchdir "Modules/Sys"))
      (dest (tackon wheredir "Modules/Sys"))
      (choices "SetAspect" "Scale")
   )

   (copyfiles
      (prompt "")
      (help "")
      (source (tackon patchdir "Hooks"))
      (dest (tackon wheredir "Hooks"))
      (choices "IMP")
   )



   (working "Removing Update Files...")

   ; delete the patches
   (run ("delete \"%s\" all quiet" patchdir))


   ; don't need these any more
   (delete "RAM:spatch")
   (delete "RAM:lhex")


   ; Installation complete!
)

; Revision History:
;
;  16.04.98 tek   Created from old ImageFX 2.1 patch script, mucho simplified.
