; $VER: C++ 2.6  (29.03.98); installer script 1998 Dietmar Eilert

(delopts "oknodelete" "force" "askuser")

(complete 0)

(onerror

    (if (> @ioerr 0)

        (
            (delete "env:INSTALLOPTIONS")

            (message "An error has occurred. Please inform our support (Dietmar.Eilert@post.rwth-aachen.de)")
        )
    )
)

; initialize return code

(textfile (dest "env:COMPONENTINSTALL") (append "INCOMPLETE"))

; initialize strings

(if (= @installer-version 0)

    (set #cpp_esc "")
    (set #cpp_esc "[2p")
)

(if (= @language "deutsch")

    (
        (set #cpp_uninstalling "Die C-Erweiterung wird entfernt ...")

        (set #cpp_badversion   "Diese Software bentigt GoldED 6.2.0+ !")

        (set #cpp_welcome      "Willkommen beim Setup fr die C-Erweiterung !")

        (set #cpp_install      "Installieren")

        (set #cpp_uninstall    "Entfernen")

        (set #cpp_golded       "Bitte installieren Sie GoldED, bevor Sie diese Installation ausfhren !")

        (set #cpp_registry     "Registry wird aktualisiert...")

        (set #cpp_toolbar      "Sprache fr Symbolleiste whlen:")

        (set #cpp_parser       "Farbhervorhebung:")

        (set #cpp_parser_max   "Erweitert")

        (set #cpp_parser_std   "Standard")

        (set #cpp_parser_min   "Einfach")

        (set #cpp_parser_none  "Keine Farbhervorhebung")

        (set #cpp_parser_help

            (cat "\n"

                "Whlen Sie eine dieser Einstellungen fr die  \n"
                "die farbige Darstellung von Schlsselworten:  \n"
                "                                              \n"
                "Erweitert                                     \n"
                "                                              \n"
                "  Empfohlen fr Rechner mit 68060 CPU und     \n"
                "  Grafikkarte.                                \n"
                "                                              \n"
                "Standard                                      \n"
                "                                              \n"
                "  Empfohlen fr Rechner mit 68030/40 CPU und  \n"
                "  Grafikkarte.                                \n"
                "                                              \n"
                "Einfach                                       \n"
                "                                              \n"
                "  Empfohlen fr Rechner mit 68030-60 CPU ohne \n"
                "  Grafikkarte.                                \n"
                "                                              \n"
                "Keine Farbhervorhebung                        \n"
                "                                              \n"
                "  Empfohlen fr Rechner mit 68020 CPU ohne    \n"
                "  Grafikkarte.                                \n"
            )
        )

        (set #cpp_control      "Projekt Explorer installieren ?")

        (set #cpp_explorer     "Projekt Explorer")

        (set #cpp_control_help

            (cat "\n"

                "Diese Erweiterung zeigt eine Liste der Dateien\n"
                "(Sourcecodes und Header) im Projektverzeichnis\n"
                "an. Die Installation wird nur empfohlen, wenn \n"
                "mindestens ein 19\"-Monitor vorhanden ist.    \n"
            )
        )
    )

    (
        (set #cpp_uninstalling "Uninstalling C add-on ...")

        (set #cpp_badversion   "This software requires GoldED 6.2.0+ !")

        (set #cpp_welcome      "Welcome to the setup for the C add-on !")

        (set #cpp_install      "Install")

        (set #cpp_uninstall    "Uninstall")

        (set #cpp_golded       "Please install GoldED before you install this add-on !")

        (set #cpp_registry     "Updating registry ...")

        (set #cpp_toolbar      "Choose language for toolbar:")

        (set #cpp_parser       "Syntax highlighting:")

        (set #cpp_parser_max   "Extensive")

        (set #cpp_parser_std   "Normal")

        (set #cpp_parser_min   "Simple")

        (set #cpp_Parser_none  "No syntax highlighting")

        (set #cpp_parser_help

            (cat "\n"

                 "Choose one of these configurations for color  \n"
                 "coded text:                                   \n"
                 "                                              \n"
                 "Extensive                                     \n"
                 "                                              \n"
                 "  For computers with 68060 CPU and graphics   \n"
                 "  card.                                       \n"
                 "                                              \n"
                 "Normal                                        \n"
                 "                                              \n"
                 "  For computers with 68020-68040 CPU and      \n"
                 "  graphics card or WinUAE with Picasso        \n"
                 "  drivers.                                    \n"
                 "                                              \n"
                 "Simple                                        \n"
                 "                                              \n"
                 "  For computers with 68030-68060 CPU without  \n"
                 "  graphics card.                              \n"
                 "                                              \n"
                 "No syntax highlighting                        \n"
                 "                                              \n"
                 "  For computers with 68020 CPU without        \n"
                 "  graphics card.                              \n"
            )
        )

        (set #cpp_control      "Install Project Explorer control ?")

        (set #cpp_explorer     "Project Explorer")

        (set #cpp_control_help

            (cat "\n"

                "This plug-in shows a list of source codes and  \n"
                "headers in the project directory. Installation \n"
                "is not recommended for small monitors (< 19\").\n"
            )
        )
    )
)

(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 62)

            (
                (message #cpp_badversion)
            )
        )

        ; read command passed in to our script in the env variable INSTALLOPTIONS

        (if (exists "env:INSTALLOPTIONS" (noreq))

            ; (getenv) may not be used without checking if var exists (installer bug)

            (
                (set cpp_installmode (getenv "INSTALLOPTIONS"))

                (if (= cpp_installmode "UNINSTALL")

                    (working #cpp_uninstalling)

                    (message #cpp_welcome)
                )
            )

            (set cpp_installmode "ASK")
        )

        (if (= cpp_installmode "ASK")

            (if

                (askbool

                    (prompt #cpp_welcome)

                    (choices

                        #cpp_install
                        #cpp_uninstall
                    )

                    (help @askbool_help)
                )

                (set cpp_installmode "INSTALL")

                (set cpp_installmode "UNINSTALL")
            )
        )

        (delete "env:INSTALLOPTIONS")

        ; verify directory structure

        (makedir "golded:etc")

        (makedir "golded:etc/api")

        (makedir "golded:etc/syntax")

        (makedir "golded:etc/images")

        (makedir "golded:etc/images/toolbar")

        (makedir "golded:add-ons")

        (makedir "golded:etc/uninstall")

        ; install registry editor (if not yet installed)

        (if (exists "golded:add-ons/regedit")

            (
                (set oldver (getversion "golded:add-ons/regedit/regedit"))

                (set newver (getversion "regedit/regedit"))

                (if (> newver oldver)

                    (copyfiles

                        (source "regedit")

                        (dest "golded:add-ons/regedit")

                        (all)

                        (nogauge)
                    )
                )
            )

            (copyfiles

                (source "regedit")

                (dest "golded:add-ons/regedit")

                (all)

                (nogauge)
            )
        )

        (if (= cpp_installmode "UNINSTALL")

            ; uninstall

            (
                ; update registry

                (working #cpp_registry)

                (if (exists ("golded:etc/uninstall/envCPP.bat"))

                    (
                        (run "golded:add-ons/regedit/regedit script=golded:etc/uninstall/envCPP.bat label=uninstall")

                        (delete "golded:etc/uninstall/envCPP.bat")
                    )

                    (run "golded:add-ons/regedit/regedit script=install.bat label=uninstall")
                )


                (exit (quiet))
            )

            ; install

            (
                (if (= bat_installmode "ASK")

                    (welcome)
                )

                (if (= @language "deutsch")

                    (set language 1)
                    (set language 0)
                )

                (set language

                    (askchoice

                        (prompt #cpp_toolbar)

                        (choices

                            (cat #cpp_esc "English")
                            (cat #cpp_esc "Deutsch")
                        )

                        (default language)

                        (help @askchoice-help)
                    )
                )

                (set syntax

                    (askchoice

                        (prompt #cpp_parser)

                        (help #cpp_parser_help)

                        (choices

                            (cat #cpp_esc #cpp_parser_max)
                            (cat #cpp_esc #cpp_parser_std)
                            (cat #cpp_esc #cpp_parser_min)
                            (cat #cpp_esc #cpp_parser_none)
                        )

                        (default 1)
                    )
                )

                (set explorer

                    (askoptions

                        (prompt #cpp_control)

                        (help #cpp_control_help)

                        (choices

                            (cat #cpp_esc #cpp_explorer)
                        )

                        (default 0)
                    )
                )

                ; install basic files

                (makedir "golded:add-ons/c++")

                (copyfiles

                    (source "c++")
                    (dest   "golded:add-ons/c++")
                    (all)
                )

                ; install toolbar images

                (copyfiles

                    (source "toolbar")
                    (dest   "golded:etc/images/toolbar")
                    (all)
                )

                ; create temporary directory

                (if (not (exists "t:" (noreq)))

                    (
                        (makedir "ram:t")

                        (makeassign "t" "ram:t")
                    )
                )

                (copyfiles

                    (source "presets")

                    (dest "t:")

                    (pattern "c.#?")

                    (nogauge)
                )

                (if (= language 0)

                    (copyfiles

                       (source "presets/e")

                       (dest "t:")

                       (all)

                       (nogauge)
                    )

                    (copyfiles

                       (source "presets/d")

                       (dest "t:")

                       (all)

                       (nogauge)
                    )
                )

                (if (= explorer 0)

                    (copyfiles

                        (source "presets/cpp/c_0.api")

                        (dest "t:")

                        (newname "c.api")

                        (nogauge)
                    )

                    (copyfiles

                        (source "presets/cpp/c_1.api")

                        (dest "t:")

                        (newname "c.api")

                        (nogauge)
                    )
                )

                (if (= syntax 3)

                    (copyfiles

                        (source "presets/cpp/cpp_off.syntax")

                        (dest "t:")

                        (newname "c.syntax")

                        (nogauge)
                    )
                )

                (if (= syntax 2)

                    (copyfiles

                        (source "presets/cpp/cpp_min.syntax")

                        (dest "t:")

                        (newname "c.syntax")

                        (nogauge)
                    )
                )

                (if (= syntax 1)

                    (copyfiles

                        (source "presets/cpp/cpp_std.syntax")

                        (dest "t:")

                        (newname "c.syntax")

                        (nogauge)
                    )
                )

                (if (= syntax 0)

                    (copyfiles

                        (source "presets/cpp/cpp_max.syntax")

                        (dest "t:")

                        (newname "c.syntax")

                        (nogauge)
                    )
                )

                ; update registry

                (working #cpp_registry)

                (run "golded:add-ons/regedit/regedit script=install.bat")

                ; prepare uninstallation

                (copyfiles

                   (source "install.bat")

                   (dest "golded:etc/uninstall")

                   (newname "envCPP.bat")
                )

                ; installation completed

                (textfile (dest "env:COMPONENTINSTALL") (append "OK"))

                (complete 100)

                (set @default-dest "golded:add-ons/c++")

                (if (= cpp_installmode "INSTALL")

                    (exit)
                    (exit (quiet))
                )
            )
        )
    )

    (message #cpp_golded)
)

(exit (quiet))
