; $VER: 1.5

(delopts "oknodelete" "force" "askuser")
(complete 0)

(if (exists "GOLDED:" (NOREQ))

    (
        (set vernum (getversion "golded:golded"))

        (set ver (/ vernum 65536))
        (set rev (- vernum (* ver 65536)))

        (set version (+ (* 10 ver) rev))

        (if (< version 47)

            (
                (message "\nSorry, GoldED 4.7.0 or better required")

                (exit (quiet))
            )
        )

        (message (cat "\n"

            "This is an environment for TeX, LaTeX and   \n"
            "TeXInfo                                     \n"
            "                                            \n"
            "©1998 BURGHARD Eric                         \n"
            "      EnvTeX environnement                  \n"
            "      E-Mail: eburghar@ufr.lirmm.fr         \n"
            "              eburghar@online.worldnet.fr   \n"
            "                                            \n"
            "©1997 Dietmar Eilert                        \n"
            "      Installation/Configuration            \n"
            "                                            \n"
            "Requirements: GoldED 4.7.0+, TeX            \n"
        ))

        (if (not (exists "golded:api"))

            (makedir "golded:api")
        )

        (if (not (exists "golded:syntax"))

            (makedir "golded:syntax")
        )

        ; autodetect Words installation

        (if (and (exists "ispell:" (noreq)) (exists "golded:tools/words"))

            (set ispell

                (askoptions

                    (prompt (cat "\n"

                        "Use existing ISpell/Words installation to   \n"
                        "highlight spelling errors in TeX documents ?\n"
                    ))

                    (help askoptions-help)

                    (choices "Use existing Words installation")

                    (default 0)
                )
            )

            (set ispell 0)
        )

        ; install syntax parser

        (if (= ispell 1)

            (copylib

                (prompt "Install syntax parser ?")
                (source "syntax/ispell/TeX.parser")
                (dest   "golded:syntax")
                (confirm)
                (help @copylib-help)
            )

            (copylib

                (prompt "Install syntax parser ?")
                (source "syntax/standard/TeX.parser")
                (dest   "golded:syntax")
                (confirm)
                (help @copylib-help)
            )
        )

        ; install API clients

        (copylib

            (prompt "Install API client ?")
            (source "api/texserver.api")
            (dest   "golded:api")
            (confirm)
            (help @copylib-help)
        )

        (copylib

            (prompt "Install API client ?")
            (source "api/mirror.api")
            (dest   "golded:api")
            (confirm)
            (help @copylib-help)
        )

        (if (exists "locale:catalogs/français" (noreq))

            (copyfiles

                (source "catalogs/envtex.catalog" )
                (dest   "locale:catalogs/français")
                (nogauge)
            )
        )

        ; install scanner

        (if (not (exists "golded:scanner"))

            (makedir "golded:scanner")
        )

        (copyfiles

            (source "scanner/latexsection")
            (dest   "golded:scanner")
            (nogauge)
        )

        ; install registry editor (if not yet installed)

        (if (not (exists "golded:tools"))

            (makedir "golded:tools")
        )

        (if (not (exists "golded:tools/regedit"))

            (makedir "golded:tools/regedit")
        )

        (copylib

            (prompt "Install registry editor ?")
            (source "bin/regedit" )
            (dest   "golded:tools/regedit")
            (confirm)
            (help @copylib-help)
        )

        ; install basic files

        (working "\nInstalling TeXServer ...")

        (if (not (exists "golded:texserver"))

            (makedir "golded:tools/texserver")
        )

        (copyfiles

            (source "texserver")
            (dest   "golded:tools/texserver")
            (nogauge)
            (all)
        )

        ; install toolbar images

        (set toolbar

            (askchoice

                (prompt "\nSelect toolbar type:\n")

                (default 0)

                (choices

                    "TeX/LaTeX"
                    "TeXInfo"
                )

                (help @askchoice-help)
            )
        )

        (set hicolor

            (askchoice

                (prompt "\nSelect toolbar style:\n")

                (choices

                    "4  colors"
                    "8+ colors"
                )

                (default 1)

                (help (cat "\n"

                    " You can use both styles on all screens. The 4\n"
                    " color style has been optimized for 4-color   \n"
                    " screens. The 8+ style has been optimized for \n"
                    " screens with eight or more colors.           \n"
                ))
            )
        )

        (if (not (exists "golded:toolbar"))

            (makedir "golded:toolbar")
        )

        (if (not (exists "golded:toolbar/texserver"))

            (makedir "golded:toolbar/texserver")
        )

        (copyfiles

            (source "toolbar")
            (dest   "golded:toolbar")
            (nogauge)
            (all)
        )

        (if (= hicolor 1)

            (copyfiles

                (source "toolbar16")
                (dest   "golded:toolbar")
                (nogauge)
                (all)
            )
        )

        // choose presets from pool

        (if (= toolbar 0)

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

                (set gadgetsfile "presets/f/tex/tex.gadgets")
                (set gadgetsfile "presets/e/tex/tex.gadgets")
            )

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

                (set gadgetsfile "presets/f/texinfo/tex.gadgets")
                (set gadgetsfile "presets/e/texinfo/tex.gadgets")
            )
        )

        (if (= ispell 1)

            (set apifile "presets/ispell/tex.api")
            (set apifile "presets/tex.api")
        )

        (if (= ispell 1)

            (set basetype "WORDS")
            (set basetype "anytext")
        )

        ; update registry

        (working "Updating registry...")

        (run (cat "golded:tools/regedit/regedit script=install.bat " gadgetsfile " " apifile " " basetype))
    )

    (message (cat "\n"

        "Please install GoldED before attempting to\n"
        "install this client.                      \n"
    ))
)

(exit (quiet))

(welcome)
