; EGS-ImageFX (Spectrum Bundle) Installer Utility
;
; For EGS-ImageFX release 1.6
;
; Written by Thomas Krehbiel (3/24/94)


(

   ; script variables...

   (set programname "EGS-ImageFX")           ; name of program
   (set drawername "EGS-ImageFX")            ; name of drawer to make for program
   (set assignname "EGSImageFX")             ; assign to make for program
   (set diskname1 "ImageFX_Disk1:")          ; install disk name
   (set diskname2 "ImageFX_Disk2:")          ; second install disk name
   (set bytesreq "1.5MB")                    ; HD space required

   ; system information...

   (set osver (/ (getversion) 65536))        ; os version
   (set initialdir @default-dest)            ; defaults to biggest drive

   ; Ask where to install it...
   (set wheredir
      (askdir
         (prompt "Select where you would like to install the " programname
                 " software.  A drawer called `" drawername
                 "' will be created for you. "
                 "(About " bytesreq
                 " is required for complete installation.)")
         (help "The " drawername
               " drawer will be installed in the directory of your choice. ")
         (default initialdir)
      )
   )

   (set wheredir (tackon wheredir drawername))

   (message programname " will be installed in " wheredir)

   (makedir wheredir (infos))
   (set @default-dest wheredir)

   ; See if there are any CPU-dependant modules on the first disk.
   ; If there are, we ask which ones the user wants to install.

   (set arecpumods
      (+ (exists (tackon diskname1 "Modules000.lha"))
         (exists (tackon diskname1 "Modules030.lha"))
        ;(exists (tackon diskname1 "Modules040.lha"))
      )
   )

   (if (<> 0 arecpumods)
      (
         (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 specific processors. "
                     "You may choose to install only the modules optimized for "
                     "the processor in your machine to save hard drive space.")
               (choices
                  "Install All Versions"
                  "Versions For 68000 Or 68010 Only"
                  "Versions For 68020, 68030, 68040 Only"
               )
               (default 0)
            )
         )
      )
      ; else
      (
         (set cpu 0)
      )
   )

   ; Make sure we add a trailing slash or colon
   (set destdir (tackon wheredir " "))

   (copyfiles
      (prompt "")
      (help "")
      (source diskname1)
      (dest "RAM:")
      (choices "unlz")
   )

   ; DISK 1

   (complete 0)

   (working "Installing Program...")
   (run ("RAM:unlz -a -m -x x %sProgram.lha %s" diskname1 destdir))

   (complete 20)

   (working "Installing Modules...")
   (run ("RAM:unlz -a -m -x x %sModules.lha %s" diskname1 destdir))
   (if (exists (tackon diskname1 "Modules000.lha"))
      (
         (if (= 0 cpu)
            (
               (run ("RAM:unlz -a -m -x x %sModules000.lha %s" diskname1 destdir))
            )
            ; else
            (if (= 1 cpu)
               (
                  (run ("RAM:unlz -a -m -x x %sModules000.lha %s" diskname1 destdir))
               )
            )
         )
      )
   )
   (if (exists (tackon diskname1 "Modules030.lha"))
      (
         (if (= 0 cpu)
            (
               (run ("RAM:unlz -a -m -x x %sModules030.lha %s" diskname1 destdir))
            )
            ; else
            (if (= 2 cpu)
               (
                  (run ("RAM:unlz -a -m -x x %sModules030.lha %s" diskname1 destdir))
               )
            )
         )
      )
   )
   ;(if (exists (tackon diskname1 "Modules040.lha"))
   ;   (
   ;      (if (= 0 cpu)
   ;         (
   ;            (run ("RAM:unlz -a -m -x x %sModules040.lha %s" diskname1 destdir))
   ;         )
   ;         ; else
   ;         (if (= 3 cpu)
   ;            (
   ;               (run ("RAM:unlz -a -m -x x %sModules040.lha %s" diskname1 destdir))
   ;            )
   ;         )
   ;      )
   ;   )
   ;)

   (complete 40)

   (copyfiles
      (prompt "")
      (help "")
      (source diskname1)
      (choices "Readme" "Readme.info")
      (dest wheredir)
   )

   ; DISK 2

   (complete 45)

   (if (exists (tackon diskname2 "Libs.lha"))
      (
         (run ("RAM:unlz -a -m -x x %sLibs.lha RAM:" diskname2))
         (if (exists "RAM:libs/iffparse.library")
            (
               (copylib
                  (prompt "")
                  (help @copylib-help)
                  (source "RAM:Libs/iffparse.library")
                  (dest "LIBS:")
               )
            )
         )
         (if (exists "RAM:libs/amigaguide.library")
            (
               (copylib
                  (prompt "")
                  (help @copylib-help)
                  (source "RAM:Libs/amigaguide.library")
                  (dest "LIBS:")
               )
            )
         )
         (if (exists "RAM:libs/dctv.library")
            (
               (copylib
                  (prompt "")
                  (help @copylib-help)
                  (source "RAM:Libs/dctv.library")
                  (dest "LIBS:")
               )
            )
         )
         (if (exists "RAM:libs/req.library")
            (
               (copylib
                  (prompt "")
                  (help @copylib-help)
                  (source "RAM:Libs/req.library")
                  (dest "LIBS:")
               )
            )
         )

      )
   )

   (complete 50)

   (if (<= osver 35)
      (
         (if (exists (tackon diskname2 "Icons13.lha"))
            (
               (working "Installing Icons For Workbench 1.3...")
               (run ("RAM:unlz -a -m -x x %sIcons13.lha %s" diskname2 destdir))
            )
         )
      )
      ; else
      (
         (if (exists (tackon diskname2 "Icons20.lha"))
            (
               (working "Installing Icons For Workbench 2.0...")
               (run ("RAM:unlz -a -m -x x %sIcons20.lha %s" diskname2 destdir))
            )
         )
      )
   )

   (complete 55)

   (if (exists (tackon diskname2 "Help.lha"))
      (
         (working "Installing Help Files...")
         (run ("RAM:unlz -a -m -x x %sHelp.lha %s" diskname2 destdir))
      )
   )

   (complete 60)

   (if (exists (tackon diskname2 "Hooks.lha"))
      (
         (working "Installing Hook Programs...")
         (run ("RAM:unlz -a -m -x x %sHooks.lha %s" diskname2 destdir))
         (if (exists (tackon diskname2 "Hooks000.lha"))
            (
               (if (= 0 cpu)
                  (
                     (run ("RAM:unlz -a -m -x x %sHooks000.lha %s" diskname2 destdir))
                  )
                  ; else
                  (if (= 1 cpu)
                     (
                        (run ("RAM:unlz -a -m -x x %sHooks000.lha %s" diskname2 destdir))
                     )
                  )
               )
            )
         )
         (if (exists (tackon diskname2 "Hooks030.lha"))
            (
               (if (= 0 cpu)
                  (
                     (run ("RAM:unlz -a -m -x x %sHooks030.lha %s" diskname2 destdir))
                  )
                  ; else
                  (if (= 2 cpu)
                     (
                        (run ("RAM:unlz -a -m -x x %sHooks030.lha %s" diskname2 destdir))
                     )
                  )
               )
            )
         )
         ;(if (exists (tackon diskname2 "Hooks040.lha"))
         ;   (
         ;      (if (= 0 cpu)
         ;         (
         ;            (run ("RAM:unlz -a -m -x x %sHooks040.lha %s" diskname2 destdir))
         ;         )
         ;         ; else
         ;         (if (= 3 cpu)
         ;            (
         ;               (run ("RAM:unlz -a -m -x x %sHooks040.lha %s" diskname2 destdir))
         ;            )
         ;         )
         ;      )
         ;   )
         ;)
      )
   )

   (complete 70)

   (if (exists (tackon diskname2 "Magic.lha"))
      (
         (working "Installing MAGIC Files...")
         (run ("RAM:unlz -a -m -x x %sMagic.lha %s" diskname2 destdir))

         ; ask if user wants to put the MagicServer in his WBStartup
         (if (>= 36 osver)
            (
               (if
                  (askbool
                     (prompt "Do you want the MAGIC server copied to your "
                             "WBStartup drawer so it will be run automatically "
                             "when your computer boots?")
                     (help "The MAGIC server is required to share 24-bit "
                           "image data between applications.")
                  )
                  (
                     (copyfiles
                        (prompt "")
                        (help "")
                        (source (tackon destdir "MAGIC"))
                        (choices "MagicServer" "MagicServer.info")
                     )
                  )
               )
            )
         )

      )
   )


   (complete 75)

   (if (exists (tackon diskname2 "Matrix.lha"))
      (
         (working "Installing Matrix Files...")
         (run ("RAM:unlz -a -m -x x %sMatrix.lha %s" diskname2 destdir))
      )
   )

   (complete 80)

   (if (exists (tackon diskname2 "Palettes.lha"))
      (
         (working "Installing Palette Files...")
         (run ("RAM:unlz -a -m -x x %sPalette.lha %s" diskname2 destdir))
      )
   )

   (complete 85)

   (if (exists (tackon diskname2 "Rexx.lha"))
      (
         (working "Installing Sample Arexx Programs...")
         (run ("RAM:unlz -a -m -x x %sRexx.lha %s" diskname2 destdir))
      )
   )

   (complete 90)

   (if (exists (tackon diskname2 "Transform.lha"))
      (
         (working "Installing Color Transform Files...")
         (run ("RAM:unlz -a -m -x x %sTransform.lha %s" diskname2 destdir))
      )
   )

   (complete 95)

   (if (exists (tackon diskname2 "Viewtek.lha"))
      (
         (working "Installing Viewtek Picture/Animation Viewer...")
         (run ("RAM:unlz -a -m -x x %sViewtek.lha %s" diskname2 destdir))
      )
   )

   (complete 99)

   (run "Delete RAM:unlz QUIET")

   (makeassign assignname wheredir)

   (onerror
      (message
         "Cannot update startup sequence.  You will need to "
         "add the following command manually: "
         "'Assign %s: \"%s\"'" assignname wheredir
      )
   )

   (startup programname
      (prompt
         "Do you want to add an " assignname
         ": assign to your startup sequence?"
      )
      (help @startup-help)
      (command
         "Assign " assignname
         ": \"" @default-dest "\""
      )
   )

   (complete 100)

   ; Installation complete!
)
