;;----------------------------------------------------------------------------
;;
;; Install-OpaqueMove - OpaqueMove installation script for Installer
;;
;; Copyright © 1996 Steve Koren, All Right reserved.
;;
;; Use following Icon tooltypes / Command line options:
;; APPNAME=OpaqueMove
;; MINUSER=AVERAGE
;;----------------------------------------------------------------------------

(complete 0)

(set locale 0)

(set #welcome           (cat "Welcome to the " @app-name " installation "
                             "process."))
(set #bad-MUI 		(cat "You need at least MUI 3.2 to use " @app-name
                             "2.0."))
(set #bad-OS            (cat "You need at least OS 3.0 to use " @app-name
                             "2.0."))
(set #dir-choice 	(cat "Select the directory where the " @app-name
                             " Directory will be created."))

(set #copy 		(cat "Copying " @app-name "..."))
(set #wbstrt            (cat "Installing " @app-name " in WBStartup"))
(set #diricon           (cat "Installing directory icon..."))
(set #doc-copy 		(cat "Copying Documentation..."))
(set #tooltype-prompt   (cat "Setting tooltypes..."))
(set #update            (cat "Updating "))

(set #browser-prompt    (cat "The HTML documentation is best read with a web "
                             "browser such as IBrowse which supports "
                             "tables.  Enter a the command used to send a "
                             "URL to your web browser.  A %s will be "
                             "replaced by the URL of the OpaqueMove "
                             "documentation.  For example, for IBrowse you "
                             "might enter\n\n"
                             "Work:IBrowse/IBrowse URL %s"))

(set #replbr-prompt     (cat "A browser invocation line already exists.  Do "
                             "you wish to update it?"))

(set #wbstart-prompt    (cat "Do you wish to start OpaqueMove each time "
                             "your Amiga boots?  If so, an icon to launch "
                             "OpaqueMove will also be copied to your "
                             "sys:WBStartup directory."))

(set #reinst-prompt     (cat "The " @app-name " directory was last "
                             "installed in %s.  Do you "
                             "wish to use this location again?"))


;=============================================================================
; Installation procedure
;=============================================================================

; -- check for existance of MUI: ---------------------------------------------

(welcome #welcome)

(if (< (exists "MUI:") 2) ( abort #bad-MUI ) )
(if (< (getversion "exec.library" (resident)) 2555904) (abort #bad-OS))

; -- select our install dir --------------------------------------------------

(set LastDir "")
(set OM-Dir  "")

(if (exists "ENV:OpaqueMove/OM-Dir")
    ((set LastDir (getenv "OpaqueMove/OM-Dir"))
     (if (not (exists (tackon LastDir "OpaqueMove/OpaqueMove")))
         (set LastDir ""))))

(complete 10)
(set Reuse 0)
(if LastDir
    (if (askbool (prompt  (#reinst-prompt LastDir))
                 (help    @askbool-help)
                 (default 1))
        ((set Reuse 1)
         (set OM-Dir (tackon LastDir "OpaqueMove")))))

(if (= OM-Dir "")
    (set OM-Dir
         (tackon (askdir (prompt #dir-choice )
                         (help "")
                         (default "SYS:Utilities")
                         (newpath))
                 @app-name)))


; -- copy our files into place -----------------------------------------------

(complete 20)

(set @default-dest OM-Dir)

(copyfiles
 (prompt #copy) (help   @copyfiles-help)
 (infos)
 (source "/") (dest OM-Dir)
 (choices "Docs-TXT" "Docs-HTML" "Brushes" "OpaqueMove" "Contrib" "Catalogs"
          "Remove" "ReadMe.MUI" "ReadMe.TXT"))

(complete 55)

(copyfiles
 (prompt #copy) (help   @copyfiles-help)
 (source "//") (dest (pathonly OM-Dir))
 (choices "OpaqueMove.info"))

(complete 58)

(tooltype (dest (tackon (pathonly OM-Dir) "OpaqueMove.info"))
               (prompt #diricon)
               (noposition))

(complete 60)

; -- install icon in WBStartup if needed & requested -------------------------

(if (askbool (prompt  #wbstart-prompt)
             (help    @askbool-help)
             (default 1))
    ((copyfiles (prompt #wbstrt) (help @copyfiles-help)
                (source "/Icons") (dest "sys:WBStartup")
                (choices "OpaqueMove.info"))
     (tooltype (dest "sys:WBStartup/OpaqueMove.info")
               (prompt #wbstrt)
               (setdefaulttool (tackon OM-Dir "OpaqueMove"))
               (noposition))))

(complete 70)


; -- add or update the browser launcher script -------------------------------

(set DocLauncher (tackon OM-Dir "Docs-HTML/English/OpaqueDocs"))
(set UpdateLauncher 0)

(if (exists DocLauncher)
    (if (askbool (prompt  #replbr-prompt)
                 (help    @askbool-help)
                 (default 1))
        ((delete DocLauncher)
         (set    UpdateLauncher 1)))
  (set    UpdateLauncher 1))

(if UpdateLauncher
    ((set LaunchCmd (askstring (prompt #browser-prompt)
                               (help    @askstring-help)
                               (default "Work:IBrowse/IBrowse URL %s")))
     (textfile (dest DocLauncher)
               (append (cat ";!c:execute\n"
                            "stack 64000\n"
                            "set wd `cd`\n"
                            (LaunchCmd "file://localhost/${wd}/Index.html")
                            "\n")))))


; -- create env vars ---------------------------------------------------------

(complete 80)

(makedir "ENV:OpaqueMove")
(makedir "ENVARC:OpaqueMove")

(if (exists "ENV:OpaqueMove/OM-Dir")    (delete "ENV:OpaqueMove/OM-Dir"))
(if (exists "ENVARC:OpaqueMove/OM-Dir") (delete "ENVARC:OpaqueMove/OM-Dir"))

(textfile (dest (tackon "ENV:OpaqueMove"    "OM-Dir"))
          (append (pathonly OM-Dir)))
(textfile (dest (tackon "ENVARC:OpaqueMove" "OM-Dir"))
          (append (pathonly OM-Dir)))


(complete 100)

(exit)
