; ImageFX Install Utility
;
; For ImageFX release 1.51 (Cover Disk)
;
; Written by Thomas Krehbiel, 23.03.95
;

(

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

   ; script variables...

   (set programname "ImageFX 1.51")          ; name of program
   (set drawername "ImageFX_1.51")           ; name of drawer to make for program
   (set assignname "ImageFX")                ; assign to make for program
   (set diskname1 "ImageFX:")                ; install disk name
   (set diskname2 "ImageFX_Disk2:")          ; second install disk name
   (set bytesreq "3.0MB")                    ; HD space required

   ; system information...

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

   ; script options

   (set pickhardware 0)

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

   ;-------------------
   ; Ask where to install it...
   (set wheredir
      (askdir
         (prompt "Select a directory where you would like to install the " programname
                 " software.  "
                 "(Note:  About " bytesreq " of free space is required for "
                 "complete installation.)")
         (help @askdir-help)
         (default initialdir)
      )
   )

   ;---------------------------
   ; Create ImageFX directory.

   ; Ask expert user the name of the drawer to create
   (if (> @user-level 1)
      (set drawername
         (askstring
            (prompt "This installation will create a drawer named `" drawername
                    "' for the ImageFX software.  If you would like to change "
                    "the name of this drawer, type the new name below.")
            (help @askstring-help)
            (default drawername)
         )
      )
   )
   (set wheredir (tackon wheredir drawername))
   (message programname " will be installed in a new drawer called `" wheredir "'.  If this is correct, click `Proceed'.")

   (if pickhardware
      (

         ;-------------------
         ; Ask which hardware components to install
         (set hardware
            (askoptions
               (prompt "Select the display drivers you would like to install:")
               (help "Check the boxes to indicate which display adaptors you have "
                     "installed on your system.")
               (choices
                  "DCTV"
                  "EGS-Compatible"
                  "Firecracker"
                  "HAM-E"
                  "IV-24"
                  "OpalVision"
                  "Picasso"
                  "Retina"
                  "SAGE (DMI)"
               )
            )
         )
         (set hardware2
            (askoptions
               (prompt "Select the hardware drivers you would like to install:")
               (help "Check the boxes to indicate which peripherals you have "
                     "installed on your system.")
               (choices
                  "Epson Scanner"
                  "JX-100 Scanner"
                  "FrameGrabber"
                  "FrameGrabber 256"
                  "VLAB"
                  "Primera Printer"
               )
            )
         )

         (set mask_dctv    1)
         (set mask_egs     2)
         (set mask_fc24    4)
         (set mask_hame    8)
         (set mask_iv24    16)
         (set mask_opal    32)
         (set mask_pic     64)
         (set mask_ret     128)
         (set mask_sage    256)

         (set mask_epson   1)
         (set mask_jx100   2)
         (set mask_fg      4)
         (set mask_fg256   8)
         (set mask_vlab    16)
         (set mask_prim    32)

      )
   )

   ;-------------------
   ; Create destination directory if it doesn't already exist.
   ;(onerror
   ;   (abort "Cannot create directory `%ls'.  (There may be a file "
   ;          "already there with the same name.)" wheredir)
   ;)
   (makedir wheredir (infos))

   (set @default-dest wheredir)

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

   (complete 0)

   (working "Installing ImageFX Program...")

   (copyfiles
      (prompt "")
      (help @copyfiles-help)
      (source diskname1)
      (dest wheredir)
      (choices
         "ImageFX"
         "ImageFX.info"
         "Default.presets"
      )

   )

   ;================================================================
   ; DISK 2
   ;================================================================

   (complete 50)

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

   (working "Uncompressing ImageFX Files...")

   (set err
      (run ("%slhex >CON:0/0//60/lhex/AUTO -a -f -w=%s x %sImagefx.lha" diskname2 wheredir diskname2))
   )
   (if err
      (
         (message "LHEX failed, error code " err)
         (abort)
      )
   )

   (complete 90)

   (working "Checking For Required Libraries...")

   (copylib
      (prompt "Iffparse.library is required to load and save many "
              "file formats.")
      (help @copylib-help)
      (source (tackon wheredir "libs/iffparse.library"))
      (dest "LIBS:")
      (confirm)
   )

   (copylib
      (prompt "Amigaguide.library is required to use the online "
              "help features of ImageFX.")
      (help @copylib-help)
      (source (tackon wheredir "libs/amigaguide.library"))
      (dest "LIBS:")
      (confirm)
   )

   (copylib
      (prompt "DCTV.library is required for loading DCTV "
              "images.")
      (help @copylib-help)
      (source (tackon wheredir "libs/dctv.library"))
      (dest "LIBS:")
      (confirm)
   )

   (if (< osver 36)
      (
         (copylib
            (prompt "Req.library is required under Workbench 1.3 for "
                    "the CineMorph morphing tool.")
            (help @copylib-help)
            (source (tackon wheredir "libs/req.library"))
            (dest "LIBS:")
            (confirm)
         )
      )
   )

   (if pickhardware
      (

         (if (= 0 (BITAND mask_dctv hardware))
            (
               (delete (tackon wheredir "modules/preview/DCTV"))
               (delete (tackon wheredir "modules/render/DCTV"))
            )
         )
         (if (= 0 (BITAND mask_egs hardware))
            (
               (delete (tackon wheredir "modules/render/EGS"))
            )
         )
         (if (= 0 (BITAND mask_fc24 hardware))
            (
               (delete (tackon wheredir "modules/preview/Firecracker"))
               (delete (tackon wheredir "modules/render/Firecracker"))
            )
         )
         (if (= 0 (BITAND mask_hame hardware))
            (
               (delete (tackon wheredir "modules/preview/HAME"))
               (delete (tackon wheredir "modules/render/HAME"))
            )
         )
         (if (= 0 (BITAND mask_iv24 hardware))
            (
               (delete (tackon wheredir "modules/preview/IV24"))
               (delete (tackon wheredir "modules/render/IV24"))
               (delete (tackon wheredir "modules/scanner/IVFG"))
            )
         )
         (if (= 0 (BITAND mask_opal hardware))
            (
               (delete (tackon wheredir "modules/preview/OpalVision"))
               (delete (tackon wheredir "modules/render/OpalVision"))
            )
         )
         (if (= 0 (BITAND mask_pic hardware))
            (
               (delete (tackon wheredir "modules/render/Picasso"))
            )
         )
         (if (= 0 (BITAND mask_ret hardware))
            (
               (delete (tackon wheredir "modules/preview/RetinaWB"))
               (delete (tackon wheredir "modules/render/Retina"))
            )
         )
         (if (= 0 (BITAND mask_sage hardware))
            (
               (delete (tackon wheredir "modules/render/SAGE"))
            )
         )
         (if (= 0 (BITAND mask_epson hardware2))
            (
               (delete (tackon wheredir "modules/scanner/Epson"))
            )
         )
         (if (= 0 (BITAND mask_jx100 hardware2))
            (
               (delete (tackon wheredir "modules/scanner/JX100"))
            )
         )
         (if (= 0 (BITAND mask_fg hardware2))
            (
               (delete (tackon wheredir "modules/scanner/FrameGrabber"))
            )
         )
         (if (= 0 (BITAND mask_fg256 hardware2))
            (
               (delete (tackon wheredir "modules/scanner/FrameGrabber256"))
            )
         )
         (if (= 0 (BITAND mask_vlab hardware2))
            (
               (delete (tackon wheredir "modules/scanner/VLAB"))
            )
         )
         (if (= 0 (BITAND mask_prim hardware2))
            (
               (delete (tackon wheredir "modules/printer/Primera"))
            )
         )

         (if (= 0 (BITAND mask_fc24 hardware))
            (
               (delete (tackon wheredir "hooks/GrabFC"))
            )
         )

      )
   )


   ;================================================================
   ; Miscellaneous stuff
   ;================================================================

   (complete 95)

   (working "Setting Up ImageFX Configuration...")

   (if (>= osver 36)
      (
         (copyfiles
            (prompt "If you want the MAGIC utility automatically "
                    "started each time you reboot, select `Proceed "
                    "With Copy'.  Otherwise select `Skip This Part' "
                    "to run the MAGIC utility manually.")
            (help @copyfiles-help)
            (source (tackon wheredir "MAGIC/MagicServer"))
            (dest "SYS:WBStartup")
            (confirm)
         )
      )
   )

   (if (> @user-level 1)
      (
         (set theassign
            (askstring
               (prompt "Select an Assign name for the ImageFX drawer: "
                       "(Do NOT include a trailing colon (:)!)")
               (help @askstring-help)
               (default assignname)
            )
         )
      )
      ; else
      (
         (set theassign assignname)
      )
   )

   (makeassign theassign wheredir)

   (tooltype
      (prompt "")
      (help "")
      (dest (tackon wheredir "ImageFX"))
      (settooltype "ASSIGN" ("%ls:" theassign))
   )
   (tooltype
      (prompt "")
      (help "")
      (dest (tackon wheredir "Cinemorph"))
      (setdefaulttool ("%ls:ImageFX" theassign))
   )
   (tooltype
      (prompt "")
      (help "")
      (dest (tackon wheredir "IMP"))
      (setdefaulttool ("%ls:ImageFX" theassign))
   )
   (tooltype
      (prompt "")
      (help "")
      (dest (tackon wheredir "ImageFX_WB"))
      (setdefaulttool ("%ls:ImageFX" theassign))
   )
   (tooltype
      (prompt "")
      (help "")
      (dest (tackon wheredir "Icons/Buffer"))
      (setdefaulttool ("%ls:ImageFX" theassign))
   )
   (tooltype
      (prompt "")
      (help "")
      (dest (tackon wheredir "Icons/Brush"))
      (setdefaulttool ("%ls:ImageFX" theassign))
   )
   (tooltype
      (prompt "")
      (help "")
      (dest (tackon wheredir "Icons/Rendered"))
      (setdefaulttool ("%ls:ImageFX" theassign))
   )
   (tooltype
      (prompt "")
      (help "")
      (dest (tackon wheredir "Icons/Palette"))
      (setdefaulttool ("%ls:ImageFX" theassign))
   )

   (if (>= osver 39)
      (
         (tooltype
            (prompt "")
            (help "")
            (dest (tackon wheredir "README"))
            (setdefaulttool "MultiView")
         )
      )
      ; else
      (
         (tooltype
            (prompt "")
            (help "")
            (dest (tackon wheredir "README"))
            (setdefaulttool "More")
         )
      )
   )

   (set runrexxmast 0)
   (if (>= osver 36)
      (

         (set norexxmast (run "sys:rexxc/tcc"))

         (if norexxmast
            (
               ; Ask expert user if he wants to run RexxMast
               (set runrexxmast 1)
               (if (> @user-level 1)
                  (set runrexxmast
                     (askbool
                        (prompt "The RexxMast server software is not currently running.  "
                                "Would you like to start RexxMast automatically at each reboot?" )
                        (help "ImageFX requires the RexxMast software to be running before you "
                              "can use any Arexx programs.")
                        (default 1)
                     )
                  )
               )
            )
         )

      )
   )

   (if runrexxmast
      (
         (set cmds
            ("Assign %ls: \"%ls\"\nIf NOT EXISTS ENV:ImageFX\n  Makedir ENV:ImageFX\nEndIf\nSetEnv ImageFX/JPEG_Smoothing ON\nRexxMast >NIL: <NIL:"
               theassign @default-dest (tackon @default-dest "Help"))
         )
         (run "sys:rexxc/RexxMast")    ; run it now, too.
      )
      ; else
      (
         (set cmds
            ("Assign \"%ls:\" \"%ls\"\nIf NOT EXISTS ENV:ImageFX\n  Makedir ENV:ImageFX\nEndIf\nSetEnv ImageFX/JPEG_Smoothing ON"
               theassign @default-dest (tackon @default-dest "Help"))
         )
      )
   )

   (onerror
      (message
         "Cannot update your user-startup file (this is probably because of some "
         "non-standard modifications that were made to the file).  You will "
         "need to add the following commands to `s:user-startup' manually:\n" cmds
      )
   )

   (startup theassign
      (prompt
         "Do you want to add the following commands to your "
         "user-startup file?\n" cmds
      )
      (help @startup-help)
      (command cmds)
   )

   ; fix up amigaguide path

   (if (= 0 (exists "ENV:AmigaGuide/Path"))
      (
         (makedir "ENV:AmigaGuide")
         (textfile
            (dest "ENV:AmigaGuide/Path")
            (help "")
            (prompt "")
            (append ("\"%ls:Help\"" theassign))
         )
      )
      ; else
      (
         (textfile
            (dest "RAM:temp_ag_path")
            (help "")
            (prompt "")
            (include "ENV:AmigaGuide/Path")
            (append ("\n\"%ls:Help\"" theassign))
         )
         (copyfiles
            (prompt "")
            (help "")
            (source "RAM:temp_ag_path")
            (dest "ENV:AmigaGuide")
            (newname "Path")
         )
      )
   )
   (copyfiles
      (prompt "")
      (help "")
      (source "ENV:AmigaGuide")
      (dest "ENVARC:AmigaGuide")
      (all)
   )
   (delete "RAM:temp_ag_path")

   (complete 100)

   ; Installation complete!
)

