; $Id: Install-DeluxePaintV,v 1.7 94/08/10 15:58:27 lee Exp $
; $VER: Install-DeluxePaintV 1.7
;
; Copyright (c) 1994 Electronic Arts, Inc. All Rights Reserved.

(set app_prefix "DPaintV_")
(set app_disk1  "Install")
(set app_disk2  "Media")
(set app_disk3  "Examples")
(set app_disk4  "Extras")

(set app_volume1 (cat app_prefix app_disk1 ":"))
(set app_volume2 (cat app_prefix app_disk2 ":"))
(set app_volume3 (cat app_prefix app_disk3 ":"))
(set app_volume4 (cat app_prefix app_disk4 ":"))

(set expert_user_level 2)
(set orig_user_level @user-level)

; standard amiga error codes
(set RC_OK     0
     RC_WARN   5
     RC_ERROR 10
     RC_FATAL 20
     )

; program install options
(set INSTF_DPAINT  1
     INSTF_DPLAYER 2)


;
; determine AmigaDos version and revision numbers
;
(set AmigaDos_Number   (getversion))
(set AmigaDos_Version  (/ AmigaDos_Number 65536))
(set AmigaDos_Revision (- AmigaDos_Number (* AmigaDos_Version 65536)))

;
; set up some message strings
;
(set format_msg
   (cat
      "Please insert an unused write-enabled floppy disk in drive "
      "DF0 before clicking on the \"Proceed\" button. This will be "
      "your destination disk.\n\n"

      "When prompted for a source disk (i.e. \"DPaintV_Install\"), "
      "place the source disk in any drive other than DF0\n\n"
   )
)

(set format_help
   (cat
      format_msg

      "Warning all data on the write-enabled floppy you provide "
      "will be erased!\n\n"

      "Please make sure that all your original DeluxePaintV "
      "source disks are write-protected before proceeding!!"
   )
)


; --------------------------------------------------------------------
; format_disk:
;   standard floppy format procedure.
;   if an error occurs during the format, a message will be put up
;   and the user re-prompted.
;
; inputs:
;   <DstDiskName> : The name to use when formatting the disk.
;
; outputs:
;   <fmt_error>  will be set to 0 if disk was formatted successfully,
;                or some value <= RC_WARN if the user cancelled the format.
;
(procedure format_disk
   (run "echo >ram:newline <nil: \"\"")
   (run ("assign \"%s\" remove" (cat DstDisName ":")))
   (user expert_user_level)
   (set fmt_error RC_FATAL)
   (until (<= fmt_error RC_WARN)
     ((set fmt_error
           (run  ("sys:system/format DRIVE DF0: NAME \"%s\" FFS NOICONS >NIL: <ram:newline" DstDiskName)
                 (help format_help)
                 (prompt (cat ("Creating disk \"%s\"...\n\n" DstDiskName) format_msg))
                 (confirm)
                 )
            )
       (transcript "format_result = " fmt_error)
       (if (> fmt_error RC_WARN)
           (message ("Error formatting disk \"%s\"" DstDiskName)))
       
       ))
    (user orig_user_level)
    (delete ram:newline)
)



; --------------------------------------------------------------------
(procedure setup_floppy_install
  (user expert_user_level)
  (message "The complete floppy disk installation requires 4 "
           "unused disks. Please have your disks ready.\n\n"
 
           "Warning: this install procedure assumes that you have "
           "at least two disk drives."
           )
  (user orig_user_level)
)

; --------------------------------------------------------------------
(procedure setup_hd_install
   (message 
      "\nYour copy of DeluxePaintV will be installed in a new drawer named "
      "\"DPaintV\". You will be asked where on your hard drive (or "
      "storage device) you want this drawer created.")

   (set app_locate
      (askdir
         (prompt "Please indicate where you want the DPaintV drawer "
                 "to be located.")
         (help @askdir-help)
         (default @default-dest)
         ))


   (set app_path (tackon app_locate "DPaintV"))
   (makedir app_path (infos))
)



; --------------------------------------------------------------------
; copy_volume1 
;    copies files from <app_volume1> into the user's preselected 
;    destination directory. If we're doing a <hd_install> this procedure
;    assumes <app_path> has already been set.  If we're doing a 
;    floppy install, the files will be copied to the newly formatted
;    'DPaintV' disk.
;
;    if either dpaint or dplayer are installed and catalogs directory
;    will be created. This assumes that app_volume1 contains an empty
;    catalogs directory and that the user will be prompted for language
;    installation later.
;
(procedure copy_volume1
  (complete 5)
  (set program_options 
      (askoptions
         (prompt "Which applications do you wish to install?")
         (choices "DPaint" "DPlayer")
         (help  "  DPaint  -- installs DPaint and its support files\n"
                "  DPlayer -- installs DPaint Player Utility\n\n"
                @askoptions-help)
         )
      )
  (if (not hd_install)
      ((set DstDiskName "DPaintV")
       (set app_path    (cat DstDiskName ":"))
       (if program_options
           ((format_disk) 
            (if fmt_error (set program_options 0))))))
  (if (bitand INSTF_DPAINT program_options)
      (copyfiles
         (prompt "Copying DPaint and its support files...")
         (source app_volume1)
         (dest   app_path)
         (choices "DPaint" "Libs" "Fonts")
         (help @copyfiles-help)
         (infos)
         (fonts)
         ))
  (complete 10)
  (if (bitand INSTF_DPLAYER program_options)
      (copyfiles
         (prompt "Copying DPlayer...")
         (source app_volume1)
         (dest   app_path)
         (choices "DPlayer")
         (infos)
         (help @copyfiles-help)
         ))
  (set @default-dest app_path)
)

; --------------------------------------------------------------------
(procedure copy_dir
  (copyfiles 
      (prompt  ("Copying \"%s\"..." app_dir))
      (source  app_volume)
      (dest    app_path)
      (choices app_dir)
      (help    @copyfiles-help)
      (infos)
      (fonts)
      (optional)
      )
)

; --------------------------------------------------------------------
; copy_volume2 
;    copies files from <app_volume2> into the user's preselected 
;    destination directory. If we're doing a <hd_install> this procedure
;    assumes <app_path> has already been set.  If we're doing a 
;    floppy install, the files will be copied to the newly formatted
;    <app_disk2> disk.
;
(procedure copy_volume2
  (complete 15)
  (set options 
      (askoptions 
          (prompt "Which of the following directories do you wish to install?")
          (choices "Media" "Textures" "Patterns" "Brush" "Move" "Colours")
          (help "  Media    -- sample media types (chalk,oil,etc..)\n"
                "  Textures -- sample paper textures\n"
                "  Patterns -- sample fill patterns\n"
                "  Brush    -- sample brushes\n"
                "  Move     -- sample move templates\n"
                "  Colours  -- sample colours/palettes\n"
                "\n"
                @askoptions-help)
          )
      )
  (if options
      (if (not hd_install)
          ((set DstDiskName app_disk2)
           (set app_path (cat DstDiskName ":"))
           (format_disk)
           (if fmt_error (set options 0)))))
  (set app_volume app_volume2)
  (if (bitand 1 options)
      ((set app_dir "Media") (copy_dir)))
  (complete 20)
  (if (bitand 2 options)
      ((set app_dir "Textures") (copy_dir)))
  (complete 25)
  (if (bitand 4 options)
      ((set app_dir "Patterns") (copy_dir)))
  (complete 30)
  (if (bitand 8 options)
      ((set app_dir "Brush") (copy_dir)))
  (complete 35)
  (if (bitand 16 options)
      ((set app_dir "Move") (copy_dir)))
  (complete 40)
  (if (bitand 32 options)
      ((set app_dir "Colours") (copy_dir)))
)


; --------------------------------------------------------------------
; copy_volume3 
;    copies files from <app_volume3> into the user's preselected 
;    destination directory. If we're doing a <hd_install> this procedure
;    assumes <app_path> has already been set.  If we're doing a 
;    floppy install, the files will be copied to the newly formatted
;    <app_disk3> disk.
;
(procedure copy_volume3
  (complete 45)
  (set options 
      (askoptions 
          (prompt "Which of the following directories do you wish to install?")
          (choices "Picture" "Anim" "Animbrush" "Karafonts")
          (help "  Picture   -- sample pictures\n"
                "  Anim      -- sample animations\n"
                "  AnimBrush -- sample animbrushes\n"
                "  Karafonts -- sample colour fonts\n"
                "\n"
                @askoptions-help)
          )
      )
  (if options
      (if (not hd_install)
          ((set DstDiskName app_disk3)
           (set app_path (cat DstDiskName ":"))
           (format_disk)
           (if fmt_error (set options 0)))))
  (set app_volume app_volume3)
  (if (bitand 1 options)
      ((set app_dir "Picture") (copy_dir)))
  (complete 50)
  (if (bitand 2 options)
      ((set app_dir "Anim") (copy_dir)))
  (complete 55)
  (if (bitand 4 options)
      ((set app_dir "Animbrush") (copy_dir)))
  (complete 60)
  (if (bitand 8 options)
      ((set app_dir "Karafonts") (copy_dir)))
)

; --------------------------------------------------------------------
; do_register
;   asks the user if he/she wishs to run and register their
;   copy of dpaint now. if the answer is yes, launches the program...
;
(procedure do_register
  (working "Running DeluxePaintV...")
  (run ("run >NIL: <NIL: \"%s\"" (tackon @default-dest "DPaint"))
       (prompt "Do you wish to register your copy of DeluxePaintV now?")
       (help "DeluxePaintV must be registered when using it for the first "
             "time. If you select \"Proceed\", the installer will run DeluxePaintV "
             "so it can ask you for your registration information now. Please "
             "have your registration card ready. If you select \"Skip This Part\", you may "
             "run and register the program at your earliest convenience."
             )
       (confirm)
       )
)

; --------------------------------------------------------------------
; update_asl:
;   updates asl.library to v38; asks expert users for confirmation.
;
;                             WARNING
;   The installer WILL COPY the supplied library over the user's
;   current library WITHOUT REGARD to the current library's version
;   number!!! This procedure should NOT be called if the library
;   version is v38 or better.
; 
(procedure update_asl
  (working "Checking \"asl.library\" version number...")
  (copylib (prompt "Updating \"asl.library\"...")
           (help "You will need \"asl.library\" version 38 (or better) for "
                 "DeluxePaintV to work properly. The library should only "
                 "be updated if its version number is less than the "
                 "minimum version number required by DeluxePaintV.\n\n"
                 @copylib-help
                 )
           (source (tackon app_volume4 "v38_libs/asl.library"))
           (dest "libs:")
           (confirm))
)


; --------------------------------------------------------------------
; copy_volume4
;    copies files from <app_volume4> into the user's preselected 
;    destination directory. If we're doing a <hd_install> this procedure
;    assumes <app_path> has already been set.  If we're doing a 
;    floppy install, the files will be copied to the newly formatted
;    <app_disk4> disk.
;
;    Updates the asl.library if necessary.
;
(procedure copy_volume4
  (complete 65)
  (set options 
      (askoptions 
          (prompt "Which of the following directories do you wish to install?")
          (choices "Gallery" "Macros" "AGA_Art" "Icons")
          (help  "  Gallery -- gallery art work\n"
                 "  Macros  -- sample arexx macros\n"
                 "  AGA_Art -- sample AGA art work\n"
                 "  Icons   -- sample icon files\n"
                 "\n"
                 @askoptions-help)
          )
      )
  (if options
      (if (not hd_install)
          ((set DstDiskName app_disk4)
           (set app_path (cat DstDiskName ":"))
           (format_disk)
           (if fmt_error (set options 0)))))
  (set app_volume app_volume4)
  (complete 70)
  (if (bitand 1 options)
      ((set app_dir "Gallery") (copy_dir)))
  (complete 75)
  (if (bitand 2 options)
      ((set app_dir "Macros") (copy_dir)))
  (complete 80)
  (if (bitand 4 options)
      ((set app_dir "AGA_Art") (copy_dir)))
  (complete 85)
  (if (bitand 8 options)
      ((set app_dir "Icons") (copy_dir)))
  (complete 90)

  (set asl_version (/ (getversion "libs:asl.library") 65535))
  (transcript "asl_version = " asl_version)
  (if (< asl_version 38)
      (update_asl))
  
)

; --------------------------------------------------------------------
; do_exit
;   does the language installation
;   does the program registrations if requested
;   puts up regcard reminder and says thanks...
;
(procedure do_exit
  (complete 95)
  (set options 
      (askoptions 
          (prompt "Which of the language Catalogs do you wish to install?")
          (choices "Français" "Deutsch")
          (help  "Français -- installs French catalogs in DPaintV:Catalogs/Français\n\n"
                 "Deutsch  -- installs German catalogs in DPaintV:Catalogs/Deutsch\n\n"
                 @askoptions-help)
          )
      )
  (set app_volume (tackon app_volume4 "Catalogs"))
  (set app_path   (tackon @default-dest "Catalogs"))
  (if (bitand 1 options)
      ((set app_dir "Français") (copy_dir)))
  (if (bitand 2 options)
      ((set app_dir "Deutsch") (copy_dir)))

  (complete 98)
  (if hd_install
      (startup @app-name
         (prompt "\nAdd DPaintV: assignment to s:user-startup?")
         (help   "All icons written out by DeluxePaintV will default to using "
                 "DPaintV:DPaint. Adding the above assignment to your "
                 "startup file will allow these files to automatically launch "
                 "DeluxePaintV when you double-click on them.\n\n"

                 @startup-help
                 )
         (command ("Assign DPaintV: \"%s\" defer" @default-dest))
         ))

  (if hd_install
      (run ("assign DPaintV: \"%s\"" @default-dest)
           (prompt ("\nAssign DPaintV: to \"%s\" now?" @default-dest))
           (help "DeluxePaintV looks for pictures, brushes, textures "
                 "in subdirectories under the logical assignment "
                 "\"DPaintV:\" by default.\n\n"
                 "This assignment is only needed now if you plan to "
                 "run DeluxePaintV before rebooting your computer "
                 "and using your s:user-startup. "
                 )
           (confirm)))
             
  (complete 99)
  (do_register)

  (complete 100)
  (user expert_user_level)
  (message "\nPlease remember to fill out and mail in your DeluxePaintV "
           "Registration Card as soon as possible.\n\n"

           "Thank you for purchasing DeluxePaintV!"
           )
  (exit)
)


; --------------------------------------------------------------------
;                   This is the actual Install Script
; --------------------------------------------------------------------
;
; tell the user that DPaintV requires AmigaDos 2.04
;
(if (< AmigaDos_Version 37)
    (
      (abort
         "DeluxePaintV will not run under this version of AmigaDOS. "
         "DeluxePaintV requires a minimum of AmigaDOS 2.04"
         )
    )
)
;
; ask the user if this is a floppy or harddisk installation
; and set the value of <hd_install>
;
(user expert_user_level)
(set hd_install 
   (= 0
     (askchoice
           (prompt "\nSelect installation method:")
           (help
               "DeluxePaintV must be properly registered before use. The can be done "
               "at the same time that the program is installed on your hard drive "
               "(or other storage device), or can be performed on a copy of the DeluxePaintV "
               "floppy disk.\n"
               "  Select \"Hard Drive\" to install DeluxePaintV to your hard drive.\n"
               "  Select \"Floppy Disk\" to install DeluxePaintV to a floppy disk.\n"
               "\n"
               @askchoice-help
               )
           (choices "Hard Drive" "Floppy Disk")
           (default 0)
           )
      )
)
(user orig_user_level)

(if hd_install
    (setup_hd_install)
    (setup_floppy_install))

(copy_volume1)
(copy_volume2)
(copy_volume3)
(copy_volume4)
(do_exit)
