; Install script for HL Plugin 68020+/Kick 3.0
;
; $VER: HL-PLugin-install 1.1 (02.12.2001) Håkan Parting

; set some texts
(set #updatetheinstaller "This installer requires version 43.3+ of the installer program\nIt may be found on Aminet in\n/util/misc/Installer-43_3.lha")

; Check the installer version
(set vernum @installer-version)
(set ver (/ vernum 65536))
(set rev (- vernum (* ver 65536)))
(set installerver (cat ver "." rev))
(if (< installerver "43.3") (exit #updatetheinstaller) )

; 68020 is the CPU we require
(set highcpu 1)

; ** set system variables **
; CPU
(set cpu (database "cpu"))
(if (> (exists ("libs:68060.library")) 0) (set #cpu 5) )
(if (> (exists ("68060.library") (resident)) 0) (set #cpu 5) )
(if (= cpu 68000) (set #cpu 0))
(if (= cpu 68010) (set #cpu 1))
(if (= cpu 68020) (set #cpu 2))
(if (= cpu 68030) (set #cpu 3))
(if (= cpu 68040) (set #cpu 4))
(if (= cpu 68050) (set #cpu 5))

; OS-version
(set osver (/ (getversion) 65536))

; Setpatch version
(set vernum (getversion "c:setpatch"))
(set ver (/ vernum 65536))
(set rev (- vernum (* ver 65536)))
(set setpatchver (cat ver "." rev))

; Version of hl plugin in the archive
(set vernum (getversion "plugins/hotline"))
(set ver (/ vernum 65536))
(set rev (- vernum (* ver 65536)))
(set acsver (cat ver "." rev))

; set texts
(set #nonlist "HL Plugin requires the MUI-costum-class\nNList.mcc version 19+ by Gilles Masson\n\nIt must be installed before AmiComSys\nPlease, download it from Aminet:dev/mui/MCC_NList0.85.lha\nAnd install it with the included installer script\nThen try to install AmiComSys again ...")
(set #nomui "HL Plugin requires Magic User Interface (MUI) 3.8!\n\nYou can find it on Aminet:dev/gui/mui38usr.lha")
(set #wrongcpu0 "This archive does only include a version for 68020/kickstart 3.0 and\nhigher.\n\nInstallation is aborted")
(set #seldocs "Select which documentation you want to install!")
(set #readmefile (cat "ACS_HLPlugin" acsver ".readme"))
(set #stringtext "")
(set #wrongos "HL Plugin requires Kickstart 3.0+.")
(set #updatethesetpatch "The installer didn't find version 40.16 or higher of c:setpatch\nHL Plugin needs it to work correctly.\nIf you have it in another location then c: then you could leave it there,\nbut please make sure it's version 40.16 or higher.")
(if (= highcpu 1) (set #cputext "68020+/OS3.0+ version\n"))

(message
    (cat "Welcome to the HL Plugin " acsver " installer!\n\n")
    "You may either use this for a first time install or for updating a former version of HL Plugin.\n\n"
    "HL Plugin © Håkan Parting 2000-2001\n"
    "Requires:\n"
    "AmiComSys 2.0+\n"
    "MUI 3.8+ © Stefan Stuntz\n"
    "AMarquee V52+ © Jeremy Friesner & Håkan Parting\n"
    "NList.mcc 19+ © Gilles Masson\n"
    "Toolbar.mcc 15.6+ © Benny Kjær Nielsen\n"
    "Textinput.mcc © Oliver Wagner\n"
    "NListtree.mcc 18.5+ © Carsten Scholling\n"
    #stringtext 
)

(run "avail flush > NIL:") (run "avail flush > NIL:")

(message
    "\n\n\nPlease make sure that no session of AmiComSys\nis running before you proceed with this\ninstallation.\n\nIf you get object in use errors please wait\n3 to 5 minutes and then try again."
)

(if (< osver 39) (exit #wrongos))

(if (< setpatchver "40.16") (message #updatethesetpatch) )

(if (< (exists "MUI:") 2) (exit #nomui) )
(if (exists "LIBS:muimaster.library") (
    (set muiver (/(getversion "LIBS:muimaster.library") 65536))
))
(if (< muiver 19) ( 
    (exit #nomui)
))

(set muiver 0)
(if (exists "LIBS:MUI/NList.mcc") (
    (set muiver (/(getversion "MUI:libs/mui/NList.mcc") 65536))
))
(if (< muiver 19) ( 
    (exit #nonlist)
))

(welcome)
(set cpuVal (askchoice (choices "68000" "68010" "68020" "68030"
                         "68040" "68060"
                    )
                (prompt "Please, select the processor your Amiga have")
                (help   "Recommended is to leave it as default")
                (default #cpu)
        )
)

(if (= highcpu 1) (if (< cpuVal 2) (exit #wrongcpu0) ))
(if (= highcpu 0) (if (> cpuVal 1) (message #wrongcpu2) ))

(set DefDir (getassign "AMICOMSYS"))
(if (= DefDir "") (set DefDir (getassign "MIAMI")) )
(if (= DefDir "") (set DefDir (getassign "AmiTCP")) )
(if (= DefDir "") (set DefDir (getassign "Inet")) )

(set #target (askdir    (prompt "Please locate the AmiComSys directory!\nIt is the directory with the plugins directory in it")
                        (help "Select the AmiComSys directory.")
                        (default DefDir)
))

(set instdir (tackon #target "plugins"))
(set @default-dest instdir)

(if (< (exists instdir) 2) (makedir instdir) )
(if (< (exists (tackon instdir "docs")) 2) (makedir (tackon instdir "docs") (infos)) )
(if (< (exists (tackon instdir "HL_Images")) 2) (makedir (tackon instdir "HL_Images")) )
(if (< (exists (tackon instdir "HL_Bookmarks")) 2) (makedir (tackon instdir "HL_Bookmarks")) )
(if (< (exists (tackon instdir "HL_Downloads")) 2) (makedir (tackon instdir "HL_Downloads")) )

; check if another version of HL Plugin is already there
; if so, make a backup

(if (= 1 (exists (tackon instdir "hotline") ) )
    (
        (set vernum (getversion (tackon instdir "hotline")))
        (set ver (/ vernum 65536))
        (set rev (- vernum (* ver 65536)))
        (set acsverold (cat ver "." rev))

        (message (cat "HL Plugin version " acsverold " was found in the install directory.\n\nIt will be backed up as hotline" acsverold))
        (copyfiles (source (tackon instdir "hotline"))
                    (dest instdir)
                    (infos)
                    (newname (cat "hotline" acsverold))
        )
    )
)

; copy over files

(copyfiles (source "plugins/hotline") (dest instdir) )

; install docs
(set docs (askoptions (choices "ACS_HLPlugin.guide" "ACS_HLPlugin.readme")
                (prompt #seldocs)
                (help #seldocs)
                (default 3)
))

(if (<> docs 0) (
    (if (IN docs 1) (copyfiles (source #readmefile) (dest (tackon instdir "docs")) (newname "ACS_HLPlugin.readme") (infos) ) )
    (if (IN docs 0) (
        (set #doctarget (askdir (prompt "Where do you want to install the guide?")
                (default (tackon instdir "docs"))
                (help "Select where to install the documentation.\nRecommended is the plugins/docs directory\nor your HELP: directory.")
        ))
        (copyfiles (source "ACS_HLPlugin.guide") (dest #doctarget) (infos))
    ))
))

(textfile (dest "ENV:ACS_INSTALLPLUGIN") (include "installpluginpath.txt"))

(copyfiles (source "plugins/HL_Images") (dest (tackon instdir "HL_Images")) (all))

(copylib (prompt #prompt_copy "\n\nAMarquee.library" )
         (help @copylib-help)
         (confirm "average")
         (source "libs/amarquee.library")
         (dest "LIBS:")
         (optional "oknodelete" "force")
)


(message "Thanks for installing the HL Plugin for AmiComSys 2.0+!\n\n"
        "You should now start AmiComSys to have it installed into AmiComSys.\n"
        "\nPlease read the ACS_HL_Plugin.guide.\n"
        "Updates will be found at http://www.parting.nu/AmiComSys/")
