;;----------------------------------------------------------------------------
;;
;; Install-BarNOne - BarNone installation script for Installer
;;
;; Copyright © 1996 Steve Koren, All Right reserved.
;;
;; Use following Icon tooltypes / Command line options:
;; APPNAME=BarNone
;; 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 BarNone "
                                "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 BarNone each time "
                                "your Amiga boots?  If so, an icon to launch "
                                "BarNone 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?"))

   (set #shutdown-prompt   (cat "If BarNone is running, it must be stopped "
                                "before this installation.  Continue?"))

   (set #halted            (cat "Installation halted."))

   (set #badarch           (cat "Bad archive.  File paths and empty directories "
                                "must be preserved when unarchiving BarNone.lha!"))
))


;;------------------------------ 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'BarNone.  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 BarNone dès l'initialisation "
                                "de votre Amiga?  Si oui, un icône de lancement "
                                "d'BarNone 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?"))

   (set #shutdown-prompt   (cat "If BarNone is running, it must be stopped "
                                "before this installation.  Continue?"))

   (set #halted            (cat "Installation arrête."))

   (set #badarch           (cat "Bad archive.  File paths and empty directories "
                                "must be preserved when unarchiving BarNone.lha!"))
))

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

(if (not (askbool (prompt #shutdown-prompt)
                  (help   @askbool-help)
                  (default 1)))
    (abort #halted))


; -- check for proper archive ------------------------------------------------

(if (or      (exists "ReadMe.TXT")
        (not (exists "/MUI/S5697_Barnone.mcc"))
        (not (exists "/C"))
        (not (exists "/C/FlushLibs"))
        (not (exists "/Catalogs"))
        (not (exists "/Contrib"))
        (not (exists "/Docs"))
        (not (exists "/Icons"))
        (not (exists "/Images"))
        (not (exists "/Install"))
        (not (exists "/MUI"))
        (not (exists "/Objects"))
        (not (exists "/Projects"))
        (not (exists "/Projects/Tutorials"))
        (not (exists "/Projects/Project.Default.Orig"))
        (not (exists "/Reginfo"))
        (not (exists "/Remove")))
    (abort #badarch))


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

(set LastDir "")
(set BN-Dir  "")

(if (exists "ENV:BarNone/BN-Dir")
    ((set LastDir (getenv "BarNone/BN-Dir"))
     (if (not (exists (tackon LastDir "BarNone/BarNone")))
         (set LastDir ""))))

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

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


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

(complete 20)

(set @default-dest BN-Dir)


;; -- save old program icon, if there is one ---------------------------------

(if (exists (tackon BN-Dir "BarNone.info"))
  (copyfiles (prompt #copy) (help   @copyfiles-help)
             (source BN-Dir) (dest "T:") (choices "BarNone.info")))

;; -- copy all of our files to the destination directory ---------------------

(copyfiles
 (prompt #copy) (help   @copyfiles-help)
 (infos)
 (source "/") (dest BN-Dir)
 (choices "Catalogs" "Contrib" "Docs" "Images" "Remove" "BarNone" "MUI"
          "RegInfo" "Projects" "Objects" "ReadMe.MUI" "ReadMe.TXT" "C"
          "Icons"))

(complete 55)

;; -- restore original program icon, if we had one ---------------------------

(if (exists "T:BarNone.info")
  ((copyfiles (prompt #copy) (help   @copyfiles-help)
              (source "T:") (dest BN-Dir) (choices "BarNone.info"))
   (delete "T:BarNone.info")))

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

(complete 58)

(tooltype (dest (tackon (pathonly BN-Dir) "BarNone"))
               (prompt #diricon)
               (noposition))

(complete 60)

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

(if (not (exists "sys:WBStartup/BarNone.info"))
   (if (askbool (prompt  #wbstart-prompt)
                (help    @askbool-help)
                (default 1))
       (copyfiles (prompt #wbstrt) (help @copyfiles-help)
                  (source "/Icons/BarNone.info")
                  (dest "sys:WBStartup"))))

(if (exists "sys:WBStartup/BarNone.info")
   (tooltype (dest "sys:WBStartup/BarNone")
             (prompt #wbstrt)
             (setdefaulttool (tackon BN-Dir "BarNone"))
             (noposition)))

(complete 70)


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

(set DocLauncher (tackon BN-Dir "Docs/English/BN-Main"))
(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}/BN-Main.html")
                            "\n")))))



; -- Copy Project.Default, if none exists ------------------------------------

(if (not (exists (tackon BN-Dir "Projects/Project.Default")))
    (copyfiles (prompt #copy) (help @copyfiles-help)
               (source "/Projects/Project.Default.Orig")
               (dest (tackon BN-Dir "Projects"))
               (newname "Project.Default")))


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

(complete 80)

(makedir "ENV:BarNone")
(makedir "ENVARC:BarNone")

(if (exists "ENV:BarNone/BN-Dir")    (delete "ENV:BarNone/BN-Dir"))
(if (exists "ENVARC:BarNone/BN-Dir") (delete "ENVARC:BarNone/BN-Dir"))

(textfile (dest (tackon "ENV:BarNone"    "BN-Dir"))
          (append (pathonly BN-Dir)))
(textfile (dest (tackon "ENVARC:BarNone" "BN-Dir"))
          (append (pathonly BN-Dir)))


(run (tackon BN-Dir "C/FlushLibs"))

(complete 98)


; -- Remove files deleted in Rev 1.1 -----------------------------------------

(if (exists (tackon BN-Dir "Docs/English/Tutorials/Graphics/BN-Tut-2-EWin.GIF"))
   (delete (tackon BN-Dir "Docs/English/Tutorials/Graphics/BN-Tut-2-EWin.GIF")))


(complete 100)

(exit)
