; Install-Script for Ax 1.0

(set #bad-kick
   (cat "\n\nSorry! You must have Workbench 2.04 or"
        "\nhigher to to use this package."
        "\n\nAborting Installation!"))


(set #no-classact
   (cat "\nHmmm!  You don't seem to have the ClassAct 2.0"
        "\nGUI system installed.  You can obtain the"
        "\nlatest ClassAct classes via ftp on the"
        "\nInternet at: \n\n ftp.warped.com/pub/amiga/classact/"
        "\n\nDo you wish to continue installation?"))

(set #Help-ContInstall
   (cat "\nThis package requires ClassAct 2.0, which does not"
        "\nappear to be installed on your system.  Select"
        "\n'Continue' to intall the program anyway, or select"
        "\n'Abort' to end the installation."))

; ---------------------------------------------------------------------------

; ************* PLEASE COPY THIS PROCEDURE ALONG WITH THE STRINGS IT USES
; ************* TO THE INSTALLER SCRIPT OF YOUR CLASSACT APPLICATION.
; ************* IT WILL TAKE CARE OF INSTALLING THE CLASSACT CLASSES YOU
; ************* PROVIDED WITH YOUR APPLICATION TO THE USER'S SYSTEM.

; ClassAct installation procedure V 1.5 (12.5.96) by Osma Ahvenlampi

; percentage of the size of included ClassAct classes versus the whole
; distribution (ie. total "complete" percentage after ClassAct is installed)
(set classact-complete 90)

; ClassAct installer scripts
(set #classdest-prompt "Please select the directory where you want the ClassAct classes installed.\n(See help for details)")
(set #classdest-help (cat "ClassAct is a GUI toolkit consisting of shared BOOPSI classes.\n\nSome programs require some or all of the ClassAct classes installed on your system. "
    (if v39 (cat "OS 3.0 has a standard directory for BOOPSI classes, the SYS:Classes directory. It is recommended that you install ClassAct there.")
            (cat "OS 2.0 does not have a standard place for disk resident BOOPSI classes. On OS 3.0 these classes are stored in the SYS:Classes directory. It is recommended that you create this directory and install ClassAct there.\nThis directory must be added in the LIBS: assign. This can be done by placing the command\nAssign >NIL: LIBS: SYS:Classes ADD\nto User-Startup. This installer will do this for you.")
        )
    )
)
(set #classes-020 "Do you want to use the OS 3.0, 020 optimised version of ClassAct?")
(set #help-020 "Some ClassAct libraries have versions optimised for use on 020 or better equipped OS 3.0 or later machines. If your Amiga is such equipped, you should install these. The 68000/2.0 versions will also work, but are slightly slower.")
(set #noclasses-message "The directory you selected for your ClassAct classes is not a part of the LIBS: assign.\n\nIt is necessary to add this assign so that the classes will be found properly.")
(set #creating-dir "Creating directory ")
(set #usbackup-prompt "User-Startup will now be backed up.")
(set #usbackup-help "This installer will next make a modification in User-Startup. Before doing this the old User-Startup will be backed up to S:User-Startup.old")
(set #adding-1 "Adding ")
(set #adding-2 " to LIBS: assign\n")
(set #adding-help "This is necessary so that the custom classes can be found.")
(set #junod-button "It seems you have a late Commodore 'V42' button.gadget installed on your system.\n\nClassAct's button.gadget is far more capable than this gadget, and we recommend that you replace it. The ClassAct button.gadget is backwards compatible to the Commodore gadget. Do you wish to back up the Commodore gadget and replace it with the ClassAct version?")
(set #junod-backed "The Commodore 'V42' button.gadget has been backed up with the name button.gadget.v42.\n\nThe ClassAct button.gadget will be installed in its place.")
(set #junod-kept "The Commodore 'V42' button.gadget was not replaced with the more capable ClassAct version.\n\nPrograms depending on the availability of ClassAct-only features will be likely to work wrong.")
(set #caprefs-message "CAPrefs is a small utility that sets some user preferences for ClassAct applications. These include the bevel style (Thin/Gadtools/Xen), window backfills, and group label details.\n\nPlease use the ClassAct GUI prefs editor to alter the default settings provided. ClassAct prefs will be installed in your system Prefs drawer.\n\n")
(set #caprefs-startup-1 "Adding the command\n\n")
(set #caprefs-startup-2 "\n\nTo your s:User-Startup.")

(procedure install-classact
; call this procedure to copy the classes included in the Classes directory
; in your distribution dir.
     (if (exists "Classes") ; The archive contains a ClassAct library update.
     (
          (set comp-dest  (/ (* classact-complete 2) 10))
          (set comp-libs  (/ (* classact-complete 3) 10))
          (set comp-dirs  (/ (* classact-complete 4) 10))
          (set comp-junod (/ (* classact-complete 5) 10))
          (set comp-020   (/ (* classact-complete 6) 10))
          (set comp-gad   (/ (* classact-complete 7) 10))
          (set comp-im    (/ (* classact-complete 8) 10))
          (set comp-prefs (/ (* classact-complete 9) 10))

          ; has the user installed ClassAct in CLASSACT: ?
          (set @classact-dest (getassign "CLASSACT" "A"))
          (if (= @classact-dest "") (set @classact-dest "SYS:Classes"))

          ; is ClassAct already in SYS:Classes ?
          (if (or (not (exists (tackon @classact-dest "Gadgets/layout.gadget") (noreq)))
                  (= @user-level 2))
              ; no, ask where it should be placed
              (set @classact-dest
                  (askdir
                      (prompt #classdest-prompt)
                      (help #classdest-help)
                      (default @classact-dest)
                      (newpath)
                  )
              )
          )

          (complete comp-dest)

          (if (<> (run (cat "C/CheckAssign LIBS: " @classact-dest)) 0)
              (
                  (message #noclasses-message)
                  (if (not (exists @classact-dest))
                       (makedir @classact-dest (prompt (cat #creating-dir @classact-dest)))
                   )
                  (set @addassign (cat "Assign >NIL: LIBS: " @classact-dest " ADD\n"))
                  (startup "CLASSACT"
                    (command @addassign)
                      (prompt (cat #adding-1 @classact-dest #adding-2))
                      (help #adding-help)
                  )
                  (run (@addassign))
              )
          )

          (complete comp-libs)

          (set @classact-gadgets (tackon @classact-dest "Gadgets"))
          (set @classact-images (tackon @classact-dest "Images"))

          (if (not (exists @classact-gadgets (noreq)))
              (makedir @classact-images
                  (prompt (cat #creating-dir @classact-gadgets))
              )
          )

          (if (not (exists @classact-images (noreq)))
              (makedir @classact-images
                  (prompt (cat #creating-dir @classact-images))
              )
          )

          (complete comp-dirs)

          (if (exists "SYS:Classes/Gadgets/button.gadget")
              (if (< 41 (/ (getversion "SYS:Classes/Gadgets/button.gadget") 65536))
                  (if (askbool (prompt #junod-button) (help @askbool-help) (default 1))
                      (
                          (rename "SYS:Classes/Gadgets/button.gadget" "SYS:Classes/Gadgets/button.gadget.v42")
                          (message #junod-backed)
                      )
                      (message #junod-kept)
                  )
              )
          )

          (complete comp-junod)

          (if (exists "Classes/Gadgets/layout.gadget.020")
               (set classes-020 (askbool (prompt #classes-020) (help #help-020) (default (and cpu020 v39))))
               (set classes-020 0)
          )

          (complete comp-020)

          (foreach "Classes/Gadgets" "#?.gadget"
               (
                    (set thislib (tackon "Classes/Gadgets" @each-name))
                    (if (and classes-020 (exists (cat thislib ".020")))
                         (set thislib (cat thislib ".020"))
                    )
                   (copylib (source thislib)
                       (dest @classact-gadgets)
                       (newname @each-name)
                       (prompt (cat #installing @each-name))
                       (help #classdest-help)
                       (optional "force" "askuser")
                   )
              )
          )

          (complete comp-gad)

          (foreach "Classes/Images" "#?.image"
               (
                    (set thislib (tackon "Classes/Images" @each-name))
                    (if (and classes-020 (exists (cat thislib ".020")))
                         (set thislib (cat thislib ".020"))
                    )
                   (copylib (source thislib)
                       (dest @classact-images)
                       (newname @each-name)
                       (prompt (cat #installing @each-name))
                       (help #classdest-help)
                       (optional "force" "askuser")
                   )
              )
          )

          (complete comp-im)

          (foreach "Classes" "#?.class"
               (
                    (set thislib (tackon "Classes" @each-name))
                    (if (and classes-020 (exists (cat thislib ".020")))
                         (set thislib (cat thislib ".020"))
                    )
                   (copylib (source thislib)
                       (dest @classact-dest)
                       (newname @each-name)
                       (prompt (cat #installing @each-name))
                       (help #classdest-help)
                       (optional "force" "askuser")
                   )
              )
          )
     )
     )
     (if (exists "Prefs/ClassAct") ; The archive contains ClassAct prefs tools
     (
          (message #caprefs-message)

          (copylib (source "Prefs/CAPrefs")
               (dest "C:")
               (prompt (cat #installing "CAPrefs"))
          )
          (copylib (source "Prefs/ClassAct")
               (dest "SYS:Prefs")
               (prompt (cat #installing "ClassAct Prefs"))
               (infos)
          )

          (complete comp-prefs)

          (if (not (exists "ENVARC:ClassAct" (noreq)))
               (
                    (makedir "ENVARC:ClassAct"
                         (prompt (cat #creating-dir "ENVARC:ClassAct"))
                    )
                    (textfile (dest "ENVARC:ClassAct/ClassAct")
                         (append "")
                    )
               )
          )

          (set caprefs-cmd "C:CAPrefs >NIL:\n")

          (startup "CAPREFS"
               (prompt (cat #caprefs-startup-1 caprefs-cmd #caprefs-startup-2))
               (help #caprefs-message)
               (command caprefs-cmd)
          )
     )
     )

     (complete classact-complete)
)

; ************** END OF CLASSACT INSTALL PROCEDURE. COPY THE BLOCK ABOVE
; ************** TO YOUR CLASSACT APPLICATION INSTALLER.

; ---------------------------------------------------------------------------

(complete 0)

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

; determine cpu type
(set cpu (database "cpu"))

(set defcpu
     (if (OR (= cpu "68000") (= cpu "68010"))
          (set defcpu 0)
          (set defcpu 1)
     )
)

; ------------------------------
; Check if ClassAct 2.0 installed
; ------------------------------

(if (< (getversion "libs:window.class") (* 41 65536))
   (set ContInstall
             (askbool
                (prompt #no-classact)
                (help #Help-ContInstall)
                (default 0)
                (choices "Continue Installation" "Abort Installation")
             )
   )
)

(if (= ContInstall 1)
        (abort "\nInstallation Aborted!")
)

(set @default-dest
     (askdir
          (prompt "In which directory would you like Ax installed? (A directory will be created there.)")
          (help @askdir-help)
          (default @default-dest)
     )
)

(set maindir (tackon @default-dest "Ax"))

(set axver
     (askchoice
          (prompt "Which executable type of Ax would you like installed?")
          (help @askchoice-help)
          (choices "68000" "68030+")
          (default defcpu)
     )
)

(set rexxdir
     (askdir
          (prompt "In which directory would you like Ax's ARexx scripts installed?")
          (help @askdir-help)
          (default (tackon maindir "Rexx"))
          (newpath)
     )
)

(set helpdir
     (askdir
          (prompt "In which directory would you like Ax's AmigaGuide documentation installed?")
          (help @askdir-help)
          (default maindir)
          (newpath)
     )
)

(select axver
     (copyfiles
          (prompt "Copying main executable (Ax)...")
          (help @copyfiles-help)
          (source "Ax")
          (dest maindir)
          (infos)
          (optional "nofail")
     )

     (copyfiles
          (prompt "Copying main executable (Ax030)...")
          (help @copyfiles-help)
          (source "Ax030")
          (dest maindir)
          (infos)
          (newname "Ax")
          (optional "nofail")
     )
)

(copyfiles
     (prompt "Copying UpdateDB utility...")
     (help @copyfiles-help)
     (source "UpdateDB")
     (dest maindir)
     (optional "nofail")
)

(complete 25)

(copyfiles
     (prompt "Copying AmigaGuide documentation...")
     (help @copyfiles-help)
     (source "Docs/Ax.guide")
     (dest helpdir)
     (infos)
     (optional "nofail")
)

; .guide file uses AmigaGuide instead of MultiView for OS <= V38
(set ver (/ (getversion) 65536))

(if (<= ver 38)
     (tooltype
          (dest (tackon helpdir "Ax.guide"))
          (setdefaulttool "AmigaGuide")
     )
)

(complete 30)

(copyfiles
     (prompt "Copying ARexx scripts...")
     (help @copyfiles-help)
     (source "Rexx")
     (dest rexxdir)
     (confirm)
     (pattern "#?.ax")
     (infos)
     (optional "nofail")
)

(complete 50)

(install-classact)

(complete 100)

(exit)

