; $VER: Install_AWeb_APL (15 March 2003)
; Description: Installer script for AWeb

(set cpu (database "cpu"))
(set cpu020 (and (<> cpu "68000") (<> cpu "68010")))
(set v39 (>= (/ (getversion "exec.library" (resident)) 65536) 39))

(set awn (getversion "AWeb"))
(set awv (/ awn 65536))
(set awr (- awn (* awv 65536)))

; all strings used in this installer script
(set #need39 "This program requires OS 3.0 or later to function.")
(set #needcpu "This archive was designed for the 68020 processor, please download the correct version for your CPU.")
(set #nohelp "No help available.")
(set #welcome
   (cat "\n\nAWeb APL is a fast, multithreaded WWW browser for AmigaOS and MorphOS.\n\n"
        "AWeb APL runs with a wide variety of TCP-stacks, including Genesis and Miami.\n\n"
      ("\n\nThis installation procedure will install the AWeb-APL browser version %ld.%ld on your system.\n" awv awr)
   )
)
(set #classact
   (cat "IMPORTANT\n\n"
        "This AWeb APL needs the ClassAct GUI package or ReAction to run.\n"
        "The ClassAct package is not included in the APL archive, but is freely available "
        "from Aminet.\n\n"
        "The ReAction package is included as part of the AmigaOS in version 3.5 and above."
   )
)

(set #destdir-prompt "Please select the directory where you want AWeb APL installed.\n(If you do not accept the default, a directory 'AWeb' will be created there.)")
(set #destdir-help "A directory for AWeb will be created here. By accepting the default directory, most of the files don't have to be copied.")
(set #installing "Installing ")
(set #languages-prompt "Please select which language catalog(s) you want to install")
(set #memory-prompt "Is your Amiga equipped with more than 2MB of memory?")
(set #memory-help "AWeb runs on a 2MB Amiga, but needs a special setup on such a machine. If you click the 'only 2MB' button, the appropriate settings will be installed.\n\nYou can always change the settings after installation.")
(set #fonts-prompt "Do you want to install the \"times.font\" and \"courier.font\" sizes 30 and 36?")
(set #fonts-help 
   (cat "In order to provide AWeb with a consistent set of fonts, four fonts are included "
      "in this archive, times/30, times/36, courier/30 and courier/36.\n\n"
      "Because AWeb uses these fonts by default, page headers might look really awful "
      " if you don't install these fonts. It is highly recommended that you install them."
   )   
)
(set #fixfonts-prompt "The FixFonts utility will be run to make the newly added fonts available.")
(set #fixfonts-help
   (cat "The FixFonts utility is needed to make the newly added fonts available to the system.\n\n"
      "If you intend to use the fonts from this archive, you are strongly encouraged to "
      "run FixFonts now.\n\n"
      "Note that running this program may take a while."
   )
)

(set #readme "Displaying the version notes readme...")
(set #makeasgn "Making AWeb_APL assignment to S:User-Startup")
(set #bye 
   (cat "In case you need help configuring or using AWeb APL, pressing the HELP key "
        "when AWeb is active will bring up the documentation.\n\n\n"
        "Please check the _Plugins_  drawer included in this archive for setting up internal image decoders."
   )
)

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

(complete 0)

(if (not v39)
   (abort #need39)
)
(if (not (>= cpu "68020"))
    (abort #needcpu)
)

(message #welcome)

(run "run >NIL: SYS:Utilities/MultiView Docs/AWeb.iff" (prompt #welcome))

(set @source-dir (pathonly @icon))

(set defdir
   (askdir
      (prompt #destdir-prompt)
      (help #destdir-help)
      (default @source-dir)
   )
)
(set @default-dest defdir)

(set nocopy (= @source-dir @default-dest))

(message #classact)

(if (not nocopy)
    (
    (set @default-dest (tackon @default-dest "AWeb_APL"))
    
       (set update-aweb (exists @default-dest))
    
    (if (not update-aweb)
        (makedir @default-dest 
            (prompt #creating-dir @default-dest) 
               (infos)
        )
       )
      (complete 10)

      (copyfiles
         (source "")
         (dest @default-dest)
         (choices "AWeb" "AWebCfg" "AWebJS")
         (prompt #installing "AWeb")
         (infos)
      )
      (complete 20)
    (copyfiles
     (source "")
     (dest @default-dest)
     (choices "Storage")
     (prompt #installing "AWeb")
     (infos)
    )
    (complete 25)
    (copyfiles
         (source "")
          (dest @default-dest)
         (choices "aweblib")
          (prompt #installing "AWeb")
    )
      (complete 30)

      (set cache-dir (tackon @default-dest "Cache"))
      (if (not (exists cache-dir))
         (
            (makedir cache-dir
               (prompt #creating-dir cache-dir)
               (infos)
            )
         )
      )
      (complete 40)

    (copyfiles
         (source "")
          (dest @default-dest)
         (choices "ReadMe" "Docs" "Icons" "Images" "Install_Animation" "Install_Buttons")
          (prompt #installing "AWeb")
          (infos)
    )
      (complete 50)
      
      (set languages
         (askoptions
            (choices "English" "etina (Czech)" "Dansk" "Deutsch" "Espaol"
               "Franais" "Greek" "slenska" "Italiano" "Nederlands" "Norsk"
               "Polski" "Portugus" "Russian" "Srpski" "Suomi" "Svenska" "Trke")
            (prompt #languages-prompt)
            (help @askoptions-help)
            (default 1)
         )
      )

      ; If any language calalogs are selected, copy them.

      (if (bitand languages 65534)
         (
            (set catdir (tackon @default-dest "Catalogs"))
            (if (not (exists catdir))
               (makedir catdir
                  (prompt #creating-dir catdir)
                    (infos)
               )
            )
            (set bit 2)    ; English implementation, so there is no catalog for it
            (set langnr 1)
            (while (< langnr 18)
               (if (bitand languages bit)
                  (
                     (set lang
                        ; English is never selected from this list
                        (select langnr "English" "etina" "Dansk" "Deutsch" "Espaol"
                           "Franais" "Greek" "slenska" "Italiano" "Nederlands" "Norsk"
                           "Polski" "Portugus" "Russian" "Srpski" "Suomi" "Svenska" "Trke"
                        )
                     )
                     (copyfiles
                        (source (tackon "Catalogs" lang))
                        (choices "aweb.catalog" "awebcfg.catalog")
                        (dest (tackon catdir lang))
                     )
                  )
               )
               (set bit (shiftleft bit 1))
               (set langnr (+ langnr 1))
            )
         )
      )
    )
)

(complete 60)

; Only ask if fonts should be installed in expert mode
(if
   (< @user-level 2)
   (set #fonts 1)
   (set #fonts
      (askbool
         (prompt #fonts-prompt)
         (help #fonts-help)
         (choices "Yes" "No")
         (default 1)
      )
   )
)
(if
   (> #fonts 0)
   (
      (copyfiles
         (source "Fonts")
         (dest "Fonts:")
         (choices "times" "courier")
         (prompt #installing "fonts")
      )
      (run "SYS:System/FixFonts"
         (confirm)
         (prompt #fixfonts-prompt)
         (help #fixfonts-help)
      )
   )
)

(complete 80)

(set #memory
   (askbool
      (prompt #memory-prompt)
      (help #memory-help)
      (choices "More than 2MB" "Only 2MB")
      (default 1)
  )
)
(set #ss_command
   (cat
          "Assign AWEB_APL: "
          '"'
          @default-dest
          '"'
   )
)

(startup "AWEB_APL"

    (prompt #makeasgn)

    (help @startup-help)

    (command

        (#ss_command)
    )
)

(run "run >NIL: " | #ss_command)

(if (= #memory 0)
   (
      (makedir
         (tackon @default-dest "T")
      )
      (makedir "ENVARC:AWeb_APL")
      (copyfiles
         (source "2MBsettings")
         (dest "ENVARC:AWeb_APL")
         (all)
      )
      (copyfiles
         (source "ENVARC:AWeb_APL")
         (dest "ENV:AWeb_APL")
         (all)
      )
   )
)

(complete 100)

(run "run >NIL: SYS:Utilities/MultiView ReadMe" (prompt #readme))
(run "run >NIL: SYS:Utilities/MultiView plugins.txt" (prompt #readme))

(exit #bye)
