; $VER: 38.0 İDietmar Eilert

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

(onerror

    (exit (quiet))
)

(set app-name "RA Remote Access")

(if (= @installer-version 0)

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

(message "Welcome to the RA Remote Access Setup !\n\nCOPYRIGHT: This package is freely distributable provided that it is distributed in its original unmodified form, with all copyright notices intact. For more details, please see the included documentation.")

(set @options

    (askoptions

        (prompt "Select components to install or update:")

        (help @askoptions-help)

        (default 15)

        (choices

            (cat #esc "Library")

            (cat #esc "Programs")

            (cat #esc "Configuration")

            (cat #esc "Developer material (optional)")
        )
    )
)

; install library

(if (IN @options 0)

    (
        (copylib

            (prompt "Install shared library ?")

            (source "libs/remote.library")

            (dest "libs:")

            (confirm)

            (help @copylib-help)
        )

        (copyfiles

            (source "locale")

            (dest "locale:")

            (all)
        )
    )
)

; install programs

(if (IN @options 1)

    (copyfiles

        (source "c")

        (dest "c:")

        (all)
    )
)

; install database

(if (IN @options 2)

    (
        (if (getenv "remote.cfg")

            (
                (set @cfgfile (getenv "remote.cfg"))

                ; get rid of LF

                (set @cfgfile (substr @cfgfile 0 (- (strlen @cfgfile) 1)))
            )

            (set @cfgfile "s:remote.ini")
        )

        (if (exists @cfgfile)

            (set @overwrite (askbool

                (prompt "Overwrite existing configuration ?")

                (help (cat "\n"

                    "The configuration file is a database of applications\n"
                    "installed on your computer. It comes preconfigured  \n"
                    "with RA and is updated automatically on an as-needed\n"
                    "basis while RA is used (RA will then scan your hard \n"
                    "disks(s).                                           \n"
                ))

                (default 0)
            ))

            (set @overwrite 1)
        )

        (if (= @overwrite 1)

            (copyfiles

                (source "config/remote.ini")

                (dest (pathonly @cfgfile))

                (newname (fileonly @cfgfile))
            )
        )
    )
)

; install developer material

(if (IN @options 3)

    (
        (if (exists "golded:" (quiet))

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

                    (makedir "golded:developer")
                )

                (set @default-dest "golded:developer")
            )
        )

        (set @default-dest

            (askdir

                (prompt "Choose a directory for installing the developer material. The drawer Remote Access is created in the path you specify:")

                (help @askdir-help)

                (default @default-dest)
            )
        )

        (copyfiles

            (source "developer")

            (dest (tackon @default-dest "Remote Access"))

            (all)
        )

        (copyfiles

            (source "manual")

            (dest (tackon @default-dest "Remote Access"))

            (infos)
        )

        ; set environment variable

        (run (cat "echo >envarc:remote.cfg " @cfgfile))

        (run (cat "echo >env:remote.cfg " @cfgfile))
    )
)

(exit)

(welcome)
