; $VER: ASM 1.3  (1.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 #asm_uninstalling "Die A68K-Erweiterung wird entfernt ...")

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

        (set #asm_welcome      "Willkommen beim Setup fr die A68K-Erweiterung !")

        (set #asm_install      "Installieren")

        (set #asm_uninstall    "Entfernen")

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

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

    (
        (set #asm_uninstall    "Uninstalling A68K add-on ...")

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

        (set #asm_welcome      "Welcome to the setup for the A68K add-on !")

        (set #asm_install      "Install")

        (set #asm_uninstall    "Uninstall")

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

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

(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 #asm_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 asm_installmode (getenv "INSTALLOPTIONS"))

                (if (= asm_installmode "UNINSTALL")

                    (working #asm_uninstalling)

                    (message #asm_welcome)
                )
            )

            (set asm_installmode "ASK")
        )

        (if (= asm_installmode "ASK")

            (if

                (askbool

                    (prompt #asm_welcome)

                    (choices

                        #asm_install
                        #asm_uninstall
                    )

                    (help @askbool_help)
                )

                (set asm_installmode "INSTALL")

                (set asm_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 (= asm_installmode "UNINSTALL")

            ; uninstall

            (
                ; update registry

                (working #asm_registry)

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

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

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

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

                (exit (quiet))
            )

            ; install

            (
                (if (= asm_installmode "ASK")

                    (welcome)
                )

                ; install basic files

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

                (copyfiles

                    (source "a68k")

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

                    (all)
                )

                (working #asm_registry)

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

                ; prepare uninstallation

                (copyfiles

                   (source "install.bat")

                   (dest "golded:etc/uninstall")

                   (newname "envASM.bat")
                )

                ; installation completed

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

                (complete 100)

                (set @default-dest "golded:")

                (if (= asm_installmode "INSTALL")

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

    (message #asm_golded)
)

(exit (quiet))
