; Installer installation script for the arc-handler
;$VER:Install 37.7 (17.7.94)

(set @default-dest "")

(set handler "L/arc-handler")
(set flusharc "C/FlushARC")
(set default-archivename "Archives")
(set default-tempdir "T:")
(set mountlist-header "S/MountList-header")
(set temp-dosdriver "T:ARC")
(set dosdriver-icon "ARC.info")

;================================================================================
; English strings

(set #bad-kick
  (cat "You must have Kickstart 2.04 or higher installed to use the ARCHandler!")
)

(set #welcome
  (cat "\nARCHandler installation\n\n\n"
             "This script installs ARCHandler 1.0a\n"
             "on your Amiga.\n\n\n\n"
             "ARCHandler © 1994 Rafael D'Halleweyn\n"
             "All rights reserved")
)

(set #copying-handler "Copying the arc-handler to your L: drawer.")

(set #copying-handler-help
  (cat "For the ARCHandler to work the arc-handler has to be copied "
       "to the L: directory. All FileSystems and handlers reside in "
       "this directory.\n\n")
)

(set #flusharc-dest "Where do you want to install the FlushARC command?")

(set #flusharc-dest-help
  (cat "The FlushARC command allows you to manually flush the buffers "
       "of the arc-handler.\n\n")
)

(set #ask-archivename "Enter the name for the ARC volume:")

(set #ask-archivename-help
  (cat "The ARC volume name is the name that will appear under the icon "
       "in the Workbench window.\n\n")
)

(set #ask-lhacommand "Please select the path to the LhA command:")

(set #ask-lhacommand-help
  (cat "For the ARCHandler to work correctly it has to known where "
       "it can find the LhA command. If you want to use a resident "
       "LhA (=faster ARCHandler) use an empty 'Current Drawer' field "
       "and make sure LhA is resident.\n\n")
)

(set #ask-tempdir "Please select a drawer to store temporary files:")

(set #ask-tempdir-help
  (cat "For the ARCHandler to work correctly it has to have a place to store "
       "its temporary files. All the files that are extracted from the "
       "archives are placed in this drawer. If you have lots of RAM you "
       "should use a drawer on the Ram Disk, otherwise use a drawer on "
       "disk.\n\n")
)

(set #make-mountlist "Adding ARC to DEVS:MountList.")

(set #make-mountlist-help
  (cat "For the (Workbench 2.04) Mount command to be able to mount "
       "FileSystems and Handlers, it has to know certain things about "
       "these handlers. These things are described in DEVS:MountList.\n\n")
)

(set #make-dosdriver-help
  (cat "For the (Workbench 2.1 and up) Mount command to be able to mount "
       "File Systems and Handlers, it has to know certain things about "
       "these handlers. These things are described by files in the "
       "SYS:Storage/DOSDrivers/ and DEVS:DOSDrivers/ drawers.\n\n")
)

(set #startup
  (cat "Always mount ARC: on start-up?")
)

(set #startup-help
  (cat "This will add the line 'Mount ARC:' to your S:User-Startup, so "
       "that ARC: is always mounted.")
)

(set #dosdriver-dest
  (cat "Always mount ARC: on start-up?")
)

(set #dosdriver-dest-help
  (cat "This will place the DOSDriver in the DEVS:DOSDrivers/ drawer, "
       "otherwise it's placed in the SYS:Storage/DOSDrivers/ drawer.")
)

;================================================================================
; make sure we are running under a 2.04 ROM

(if (< (/ (getversion) 65536) 37)
  (
    (abort #bad-kick)
  )
)

;================================================================================
;

(complete 0)

(message #welcome)

(welcome)

(copylib
  (prompt "\n" #copying-handler)
  (help #copying-handler-help @copylib-help)
  (source handler)
  (dest "L:")
  (confirm)
)

(complete 25)

(set flusharc-dest
  (askdir
    (prompt #flusharc-dest)
    (help #flusharc-dest-help @askdir-help)
    (default "C:")
  )
)

(copylib
  (prompt "\nCopying the FlushARC command to your " flusharc-dest " drawer.")
  (help @copylib-help)
  (source flusharc)
  (dest flusharc-dest)
  (confirm)
)

(complete 50)

; now comes the tricky bit, we're going to make the MountList (2.04)
; or the DOSDriver Mount script (2.1 and higher).

(set old_level @user-level)
(user 2)

(set archivename
  (askstring
    (prompt "\n" #ask-archivename)
    (help #ask-archivename-help @askstring-help)
    (default default-archivename)
  )
)

(complete 60)

(user 0)
(run "Execute S/WhichLhA"
  (safe)
)
(user 2)
(set default-lhacommand (getenv "lhapath"))

(set lhacommand
  (askfile
    (prompt #ask-lhacommand)
    (help #ask-lhacommand-help @askfile-help)
    (default default-lhacommand)
  )
)

(complete 70)

(set tempdir
  (askdir
    (prompt #ask-tempdir)
    (help #ask-tempdir-help @askdir-help)
    (default default-tempdir)
    (disk)
  )
)

(complete 80)

(set startup-msg
  (cat
    "\"NAME='"
    archivename
    "' LHA='"
    lhacommand
    "' TEMPDIR='"
    tempdir
    "' BUFFERS=2\""
  )
)

(complete 90)

(if (< (/ (getversion "LIBS:version.library") 65536) 38)
  (

; Workbench 2.04

; Make DOSDriver
    (textfile
      (dest temp-dosdriver)
      (include mountlist-header)
      (append
        (cat
          "Handler		= L:arc-handler\n"
          "Startup		= "
            startup-msg
            "\n"
          "Mount		= 1\n"
          "StackSize	= 4096\n"
          "GlobVec		= -1\n")
        (safe)
      )
    )

; Now transform DOSDriver to MountList entry.

    (if (< old_level 2)
      (user 0)
      (user 2)
    )

    (run "C/MountListEntry ARC: " temp-dosdriver
      (prompt "\n" #make-mountlist)
      (help #make-mountlist-help)
      (confirm)
    )

    (complete 95)
    (user 2)

    (startup
      "ARCHandler"
      (prompt #startup)
      (help #startup-help @startup-help)
      (command "Mount >NIL: ARC:")
    )

  )
  (

; Make DOSDriver
    (textfile
      (dest temp-dosdriver)
      (include mountlist-header)
      (append
        (cat
          "Handler		= L:arc-handler\n"
          "StackSize	= 4096\n"
          "GlobVec		= -1\n"
          "\n"
          "/*\n"
          "** The Startup and Mount fields are in the tool types of the icon.\n"
          "*/\n")
        (safe)
      )
    )

; move DOSDriver to SYS:Storage/DOSDriver and add an icon with the
; right tooltypes.
    (set dosdriver-dest
      (if (askbool
            (prompt "\n" #dosdriver-dest)
            (help #dosdriver-dest-help)
            (default 0)
            (choices "Yes" "No")
          )
        "DEVS:DOSDrivers/"
        "SYS:Storage/DOSDrivers/"
      ))

    (if (< old_level 2)
      (user 0)
      (user 2)
    )

    (if (askbool
          (prompt "\n" "Adding ARC to the " dosdriver-dest " drawer")
          (help #make-dosdriver-help)
          (default 1)
          (choices "Proceed" "Skip This Part")
        )
      (

        (copyfiles
          (source temp-dosdriver)
          (dest dosdriver-dest))
        (complete 94)
        (copyfiles
          (source dosdriver-icon)
          (dest dosdriver-dest))
        (complete 98)
        (tooltype
          (dest (cat dosdriver-dest "ARC"))
          (setdefaulttool "C:Mount")
          (noposition)
          (setstack 4096)
          (settooltype "STARUP" startup-msg)
          (settooltype "MOUNT" "1")
          (settooltype "WINDOW"))
        (protect (cat dosdriver-dest "ARC") 2)
      )
    )

  )
)

(delete temp-dosdriver
  (safe)
)

(complete 100)
(exit)
