;;----------------------------------------------------------------------------
;;
;; 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)

;;------------------------------ english messages ----------------------------

(if (= @language "english")
 (

   (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?"))
))


;;------------------------------ french messages -----------------------------

(if (= @language "français")
 (

   (set #welcome           (cat "Bienvenu dans l'utilitaire d'installation de " @app-name "."))
   (set #bad-MUI (cat "Vous devez utiliser MUI 3.2 ou plus pour utliser " @app-name
                                "2.0."))
   (set #bad-OS            (cat "Vous devez utiliser l'OS 3.x pour utiliser " @app-name
                                "2.0."))
   (set #dir-choice (cat "Choisissez l'emplacement où le répertoire de " @app-name
                                " sera créé."))
   
   (set #copy (cat "Copie de " @app-name " en cours..."))
   (set #wbstrt            (cat "Installation de " @app-name " dans la WBStartup"))
   (set #diricon           (cat "Installation de l'icône du répertoire..."))
   (set #doc-copy (cat "Copie de la documentation en cours..."))
   (set #tooltype-prompt   (cat "Réglage des Types d'Outils..."))
   (set #update            (cat "Mise à jour "))
   
   (set #browser-prompt    (cat "Il vaut mieux lire la documentation HTML "
                                "avec un browser comme IBrowse qui supporte les "
                                "tables.  Entrez la commande utilisée pour envoyer "
                                "un URL à votre browser.  Un %s sera "
                                "remplacé par l'URL de la documentation "
                                "d'OpaqueMove.  Par exemple, pour IBrowse vous "
                                "pouvez  entrer\n\n"
                                "Internet:IBrowse/IBrowse URL %s"))
   
   (set #replbr-prompt     (cat "Une ligne d'appel à un browser existe déjà. "
                                "Voulez-vous la mettre à jour?"))
   
   (set #wbstart-prompt    (cat "Désirez-vous démarrer OpaqueMove dès l'initialisation "
                                "de votre Amiga?  Si oui, un icône de lancement "
                                "d'OpaqueMove sera aussi copié dans votre "
                                "répertoire sys:WBStartup."))
   
   (set #reinst-prompt     (cat "le répertoire " @app-name " était déjà "
                                "installé dans %s.  Désirez-vous "
                                "utiliser cet emplacement à nouveau?"))
))

;=============================================================================
; 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"))
               (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")
               (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)
