; $VER: SAS/C 1.0  (6.04.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 (= @language "deutsch")

    (
        (set #sas_uninstalling "Die SAS/C-Erweiterung wird entfernt ...")

        (set #sas_badversion   "Diese Software benötigt GoldED 5 !")

        (set #sas_welcome      "Willkommen beim Setup für die SAS/C-Erweiterung !")

        (set #sas_install      "Installieren")

        (set #sas_uninstall    "Entfernen")

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

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

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

        (set #sas_parser       "Farbhervorhebung:")

        (set #sas_warp         "Erweitert")

        (set #sas_standard     "Standard")

        (set #sas_none         "Keine Farbhervorhebung")

        (set #sas_help

            (cat "\n"

                "Vorauswahl des Syntax-Parsers (zuständig für  \n"
                "die farbige Darstellung von Schlüsselworten): \n"
                "                                              \n"
                "Erweitert                                     \n"
                "                                              \n"
                "  Erkennt C/C++-Befehle. Empfohlen für 68030  \n"
                "  oder besser. Speicherverbrauch: mittel.     \n"
                "  Relative Performance: 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 #sas_uninstalling "Uninstalling SAS/C add-on ...")

        (set #sas_badversion   "This software requires GoldED 5 !")

        (set #sas_welcome      "Welcome to the setup for the SAS/C add-on !")

        (set #sas_install      "Install")

        (set #sas_uninstall    "Uninstall")

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

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

        (set #sas_menu         "Choose language for menu:")

        (set #sas_parser       "Syntax highlighting:")

        (set #sas_warp         "Extended")

        (set #sas_standard     "Standard")

        (set #sas_none         "No syntax highlighting")

        (set #sas_help

            (cat "\n"

                 "Preselection of syntax highlighting parser    \n"
                 "(responsible for color-coded text):           \n"
                 "                                              \n"
                 "Extended                                      \n"
                 "                                              \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"
            )
        )
    )
)

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

            (
                (message #sas_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 sas_installmode (getenv "INSTALLOPTIONS"))

                (if (= sas_installmode "UNINSTALL")

                    (working #sas_uninstalling)

                    (message #sas_welcome)
                )
            )

            (set sas_installmode "ASK")
        )

        (if (= sas_installmode "ASK")

            (if

                (askbool

                    (prompt #sas_welcome)

                    (choices

                        #sas_install
                        #sas_uninstall
                    )

                    (help @askbool_help)
                )

                (set sas_installmode "INSTALL")

                (set sas_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")

        (if (= sas_installmode "UNINSTALL")

            ; uninstall

            (
                ; update registry

                (working #sas_registry)

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

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

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

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

                (exit (quiet))
            )

            ; install

            (
                (if (= sas_installmode "ASK")

                    (welcome)
                )

                (if (= @language "deutsch")

                    (set language 1)
                    (set language 0)
                )

                (set language

                    (askchoice

                        (prompt #sas_menu)

                        (choices

                            "English"
                            "Deutsch"
                        )

                        (default language)

                        (help @askchoice-help)
                    )
                )

                (set syntax (askchoice

                    (prompt #sas_parser)

                    (help #sas_help)

                    (choices

                        #sas_warp
                        #sas_standard
                        #sas_none
                    )

                    (default 0)
                ))

                ; install basic files

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

                (copyfiles

                    (source "sas-c")

                    (dest "golded:add-ons/sas-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 "sas#?")

                    (nogauge)
                )

                (if (= language 0)

                    (copyfiles

                       (source "presets/e")

                       (dest "t:")

                       (all)

                       (nogauge)
                    )

                    (copyfiles

                       (source "presets/d")

                       (dest "t:")

                       (all)

                       (nogauge)
                    )
                )

                (if (= syntax 0)

                    (copyfiles

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

                        (dest "t:")

                        (newname "sas_cpp.syntax")

                        (nogauge)
                    )
                )

                (if (= syntax 1)

                    (copyfiles

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

                        (dest "t:")

                        (newname "sas_cpp.syntax")

                        (nogauge)
                    )
                )

                (if (= syntax 2)

                    (copyfiles

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

                        (dest "t:")

                        (newname "sas_cpp.syntax")

                        (nogauge)
                    )
                )

                ; update registry

                (working #sas_registry)

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

                ; prepare uninstallation

                (copyfiles

                   (source "install.bat")

                   (dest "golded:etc/uninstall")

                   (newname "envSAS.bat")
                )

                ; install autorun macro

                (copyfiles

                    (source "autorun/sas-c.rexx")

                    (dest "golded:etc/autorun")
                )

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

                ; installation completed

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

                (complete 100)

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

                (if (= sas_installmode "INSTALL")

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

    (message #sas_golded)
)

(exit (quiet))
