; $VER: StormC 2.6  (10.6.99); installer script ©1999 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 (= @language "deutsch")

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

        (set #cpp_badversion   "Diese Software benötigt GoldED 6.1 !")

        (set #cpp_welcome      "Willkommen beim Setup für die StormC-Erweiterung !")

        (set #cpp_install      "Installieren")

        (set #cpp_uninstall    "Entfernen")

        (set #cpp_golded       "Bitte installieren Sie GoldED, bevor Sie diese Installation ausführen !")

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

        (set #cpp_menu         "Sprache für Menu wählen:")

        (set #cpp_parser       "Farbhervorhebung:")

        (set #cpp_storm        "StormC-spezifisch")

        (set #cpp_warp         "Erweitert")

        (set #cpp_standard     "Standard")

        (set #cpp_none         "Keine Farbhervorhebung")

        (set #cpp_help

            (cat "\n"

                "Vorauswahl des Syntax-Parsers (zuständig für  \n"
                "die farbige Darstellung von Schlüsselworten): \n"
                "                                              \n"
                "StormC-spezifisch                             \n"
                "                                              \n"
                "  Komplexer konfigurierbarer C++-Parser. Er-  \n"
                "  kennt und markiert C/C++-Befehle und Amiga- \n"
                "  typische Ausdrücke. Empfohlen für 68040 und \n"
                "  besser. Speicherverbrauch: hoch (Minimum:   \n"
                "  150 K). Relative Performance: 45%           \n"
                "                                              \n"
                "Erweitert                                     \n"
                "                                              \n"
                "  Schneller C++ Parser. Beschränkte Konfi-    \n"
                "  gurierbarkeit. Erkennt C/C++-Befehle.       \n"
                "  Empfohlen für 68030 oder besser. Speicher-  \n"
                "  verbrauch: mittel. Relative Performance:    \n"
                "  60%                                         \n"
                "                                              \n"
                "Standard                                      \n"
                "                                              \n"
                "  Einfacher Kommentar-Parser: Erkennt und     \n"
                "  markiert C/C++-Kommentare im Quelltext.     \n"
                "  Empfohlen für 68020 oder besser. Kein       \n"
                "  nennenswerter Speicherverbrauch. Relative   \n"
                "  Performance: 65%                            \n"
                "                                              \n"
                "Keiner                                        \n"
                "                                              \n"
                "  Keine farbliche Hervorhebungen im Text.     \n"
                "  Empfohlen für 68000 oder besser. Relative   \n"
                "  Performance: 100%                           \n"
            )
        )

        (set #stormc_control      "Projekt Explorer installieren ?")

        (set #stormc_explorer     "Projekt Explorer")

        (set #stormc_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 StormC add-on ...")

        (set #cpp_badversion   "This software requires GoldED 6.1 !")

        (set #cpp_welcome      "Welcome to the setup for the StormC 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_menu         "Choose language for menu:")

        (set #cpp_parser       "Syntax highlighting:")

        (set #cpp_storm        "StormC-specific")

        (set #cpp_warp         "Extended")

        (set #cpp_standard     "Standard")

        (set #cpp_none         "No syntax highlighting")

        (set #cpp_help

            (cat "\n"

                 "Preselection of syntax highlighting parser    \n"
                 "(responsible for color-coded text):           \n"
                 "                                              \n"
                 "StormC-specific                               \n"
                 "                                              \n"
                 "  Complex configurable C++ parser. Highlights \n"
                 "  C keywords and Amiga keywords. Recommended  \n"
                 "  for 68040 or better. RAM requirements: high \n"
                 "  (150 K minimum). Relative performance: 45%  \n"
                 "                                              \n"
                 "Extended                                      \n"
                 "                                              \n"
                 "  Fast C++ parser. Limited configurability.   \n"
                 "  Highlights C++ keywords. Recommended for    \n"
                 "  68030 or better. RAM requirements: medium.  \n"
                 "  Relative performance: 60%                   \n"
                 "                                              \n"
                 "Standard                                      \n"
                 "                                              \n"
                 "  Simple C++ comment parser. Highlights C/C++ \n"
                 "  comments only. Recommended for 68020 or     \n"
                 "  better. RAM requirements: small. Relative   \n"
                 "  performance: 65%                            \n"
                 "                                              \n"
                 "None                                          \n"
                 "                                              \n"
                 "  No syntax highlighting. Recomended for      \n"
                 "  68000 or better. Relative performance: 100% \n"
            )
        )

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

        (set #stormc_explorer     "Project Explorer")

        (set #stormc_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 61)

            (
                (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/envSTM.bat"))

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

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

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

                (exit (quiet))
            )

            ; install

            (
                (if (= cpp_installmode "ASK")

                    (welcome)
                )

                (if (= @language "deutsch")

                    (set language 1)
                    (set language 0)
                )

                (set language

                    (askchoice

                        (prompt #cpp_menu)

                        (choices

                            "English"
                            "Deutsch"
                        )

                        (default language)

                        (help @askchoice-help)
                    )
                )

                (set syntax

                    (askchoice

                        (prompt #cpp_parser)

                        (help #cpp_help)

                        (choices

                            #cpp_storm
                            #cpp_warp
                            #cpp_standard
                            #cpp_none
                        )

                        (default 1)
                    )
                )

                (set explorer

                    (askoptions

                        (prompt #stormc_control)

                        (help #stormc_control_help)

                        (choices #stormc_explorer)

                        (default 0)
                    )
                )

                ; install basic files

                (makedir "golded:add-ons/stormc")

                (copyfiles

                    (source "stormc")

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

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

                    (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/stormc_0.api")

                        (dest "t:")

                        (newname "stormc.api")

                        (nogauge)
                    )

                    (copyfiles

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

                        (dest "t:")

                        (newname "stormc.api")

                        (nogauge)
                    )
                )

                (if (= syntax 0)

                    (copyfiles

                        (nogauge)

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

                        (dest "t:")

                        (newname "stormc_cpp.syntax")
                    )
                )

                (if (= syntax 1)

                    (copyfiles

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

                        (dest "t:")

                        (newname "stormc_cpp.syntax")

                        (nogauge)
                    )
                )

                (if (= syntax 2)

                    (copyfiles

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

                        (dest "t:")

                        (newname "stormc_cpp.syntax")

                        (nogauge)
                    )
                )

                (if (= syntax 3)

                    (copyfiles

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

                        (dest "t:")

                        (newname "stormc_cpp.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 "envSTM.bat")
                )

                ; install autorun macro

                (copyfiles

                    (source "autorun/stormc.rexx")

                    (dest "golded:etc/autorun")
                )

                (run "golded:add-ons/regedit/regedit autorunrexx golded:etc/autorun/stormc.rexx autodelete")

                ; installation completed

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

                (complete 100)

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

                (if (= cpp_installmode "INSTALL")

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

    (message #cpp_golded)
)

(exit (quiet))
