; ImageFX 2.1a Extras Patch Install Script
;
; Written by Thomas Krehbiel
;
; Copyright © 1995 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 "2.1a")                     ; version number
   (set programname ("ImageFX Extras %s" versionname)) ; name of program
   (set diskname1 "ImageFX_Disk1:")             ; install disk name
   (set diskname2 "ImageFX_Disk2:")             ; second install disk name
   (set diskname3 "ImageFX_Disk3:")             ; third install disk name
   (set diskname4 "ImageFX_Disk4:")             ; fourth install disk name
   (set pdiskname1 "")                          ; patch install disk name
   (set pdiskname2 "")                          ; patch install disk 2 name

   (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 "ImageFX")
      (
         (set initialdir (getassign "ImageFX"))
      )
      ; else
      (
         (if (getassign "ImageFX2")
            (
               (set initialdir (getassign "ImageFX2"))
               ; if we found ImageFX2:, assume user wants to keep ImageFX2:
               (set assignname "ImageFX2")
            )
         )
      )
   )

   ;-------------------
   ; Warn user.
   (message "These 'extras' were either not created by Nova Design, Inc., "
            "or are based on software not created or supported by Nova Design.  "
            "Because of this, Nova Design cannot provide technical support for these extras.  "
            "They are provided for your amusement only; use them at your own risk.  "
            "If you do not want to install them, click `Abort Install' now.")


   (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 extras in "
                       "this directory will be updated to version " versionname ".  All of your "
                       "preferences will be preserved.  NOTE:  You will need your original ImageFX 2.0 "
                       "disks to apply this update.")
               (help @askdir-help)
               (default initialdir)
            )
         )

         ;-------------------
         ; Make sure it's a valid ImageFX
         (set checkvar 0)
         (set checkvar (+ checkvar (exists (tackon wheredir "Modules/Sys/Scale"))))
         (set checkvar (+ checkvar (exists (tackon wheredir "Hooks/Sys/PaintFX"))))
         (if (= 0 checkvar)
            (
               (message "`" wheredir "' does not appear to contain a copy of ImageFX 2.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)

   ;-------------------
   ; Ask which versions of modules the user wants to install.
   ;(set cpu
   ;   (askchoice
   ;      (prompt "Select which versions of hooks and modules you would "
   ;              "like to install:")
   ;      (help "Some ImageFX hooks and modules (such as the JPEG modules) "
   ;            "have alternate versions optimized for faster processors. "
   ;            "You may choose to install only the modules optimized for "
   ;            "the processor in your machine to save hard drive space.")
   ;      (choices
   ;         "For Any Processor"
   ;         "For 68000 Or 68010"
   ;         "For 68020 Or 68030, No Floating Point"
   ;         "For 68020 Or 68030, With Floating Point"
   ;         "For 68040, With Floating Point"
   ;      )
   ;      (default 0)
   ;   )
   ;)

   ;-------------------
   ; Ask which components to install
   (set todo
      (askoptions
         (prompt "Select the " versionname " Extras you would like to install "
                 "(Extras that are installed from previous versions of ImageFX "
                 "will be updated automatically):")
         (help "Check the boxes to indicate which extras you would like "
               "installed on your system.")
         (choices
            "CyberGraphics Render Module"
            "JSTREAM Loader & Saver Modules"
         )
      )
   )

   (set mask_cyber   1)
   (set mask_jstream 2)

   ;================================================================
   ; PATCH EXISTING FILES
   ;================================================================

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

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

   (askdisk
      (prompt "Please insert ImageFX 2.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 diskname1)
      (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 "PatchesX"))
   (makedir patchdir)

   (if (= 0 (exists (tackon pdiskname1 "PatchesX.lha")))
      (
         (set pdiskname2 "IFX_20to21a_Disk2:")  ; patch install disk 2 name
         (askdisk
            (prompt "Please insert ImageFX Patch Disk 2 in any drive.")
            (help "")
            (dest (substr pdiskname2 0 (- (strlen pdiskname2) 1)))
            (assigns)
         )
      )
   )

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

   ;================================================================
   ; DISK 4
   ;================================================================

   ; only patch postscript if it's there already
   (if (exists (tackon wheredir "Modules/Loaders/PostScript"))
      (

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

         ; copy hooks.lha to ram for speed
         (copyfiles
            (prompt "")
            (help "")
            (source diskname4)
            (dest tempdir)
            (choices "Extras1.lha")
         )

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

         (set pf_name "Modules/Loaders/PostScript") (DoPatch)

         (delete (tackon tempdir "Extras1.lha"))
         (run ("delete %s all quiet" (tackon tempdir "Modules")))

      )
   )

   ;================================================================
   ; INSTALL NEW FILES
   ;================================================================

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

   (if (BITAND mask_cyber todo)
      (
         (copyfiles
            (prompt "")
            (help "")
            (source (tackon patchdir "Modules/Render"))
            (dest (tackon wheredir "Modules/Render"))
            (choices "CyberGraphics.000" "CyberGraphics.030")
         )
      )
   )

   (if (BITAND mask_jstream todo)
      (
         (copyfiles
            (prompt "")
            (help "")
            (source (tackon patchdir "Modules/Loaders"))
            (dest (tackon wheredir "Modules/Loaders"))
            (choices "JSTREAM.000" "JSTREAM.030" "JSTREAM.040")
         )
         (copyfiles
            (prompt "")
            (help "")
            (source (tackon patchdir "Modules/Savers"))
            (dest (tackon wheredir "Modules/Savers"))
            (choices "JSTREAM.000" "JSTREAM.030" "JSTREAM.040")
         )
         (copyfiles
            (prompt "")
            (help "")
            (source (tackon patchdir "Help"))
            (dest (tackon wheredir "Help"))
            (choices "JStream.guide" "JStream.guide.info")
         )
      )
   )

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

   ; Installation complete!
)

; Revision History:
;
;  14.04.95 tek   Created for Beta 2 release.
;  07.11.95 tek   Updated for 2.0 -> 2.1a patch operation.


