;--------------------------------------------------------------------------
; $VER: Deli14BitGenie Install V1.2 (13-Mar-00).
;
; Copyright 1999-2000 Chris Hodges. All rights reserved.
;--------------------------------------------------------------------------

(delopts "force" "askuser" "nofail")

;--------------------------------------------------------------------------
; Flexible installer script! So get our installation environment.
;--------------------------------------------------------------------------

(set #home @execute-dir)

;--------------------------------------------------------------------------
; English Installer Strings
;--------------------------------------------------------------------------

(if (= @language "english")
    (
        (set #lang 1)

        (set #ioerror "An error occured during the installation, please report it to me.\n\nThanks.")

        (set #installitem1 "Deli14BitGenie Main file")
        (set #installitem2 "Deli14BitGenie Guide")
        (set #installitem3 "")
        (set #installitem4 "Bonus Modules")
        (set #installitem5 "Extra Fonts")

        (set #intro
            (cat
                ("Welcome to the installation program for the\nDeli14BitGenie V%d.%d\n"
                (getversion ("DeliGenies/14Bit-Noteplayer")))
                "by Chris Hodges <hodges@in.tum.de>"
                "\n\nNote that this program is POSTCARD WARE!"
                "\n\nPlease select which parts do you want to install:"
            )
        )

        (set #intro_help
            (cat
                "Except for the main file, nothing is mandatory. You are adviced to install "
                "the Guide and the new Players, however."
            )
        )

        (set #installwhere
            (cat
                "I could not find DeliTracker myself, please select your DeliTracker drawer "
                "on your drive."
            )
        )

        (set #installwhere_help
            (cat
                "The Deli14Bit Genie requires a DeliTracker installation. If you haven't "
                "installed DeliTracker yet, abort the installation and please do this first. "
                "DeliTracker can be found on AmiNet in the directory mus/play.\n\n"
                "This script will normally select the consequent drawers automatically. "
                "In expert mode, however, you can choose them yourself."
            )
        )

        (set #askdrawer_help
            (cat
                "Please select the appropriate drawer. Normally this script finds the "
                "correct paths itself, but if you have a wierd installation of DeliTracker "
                "or have enabled expert mode, you may select every target directory yourself."
            )
        )

        (set #installgenie "Please select the drawer for the Genie main file (normally 'DeliGenies').")

        (set #installplayers "Please select the drawer for the bonus Players (normally 'DeliPlayers').")

        (set #installdocs "Where do you want the manual to be installed?")

        (set #installmods "Where do you want the bonus modules to be copied to?")

        (set #copygenie "Copying main genie file...")

        (set #copyplayers "Select the bonus Players you want to install:")

        (set #copyplayers_help
            (cat
                "As a bonus, I've included a selection of uptodate DeliPlayers for DeliTracker. "
                "Using these you can be sure to get out the most of Deli14Bit. Have a look at the "
                "DeliPlayers.readme or in the docs for details."
            )
        )

        (set #copydocs "Copying manual...")
        (set #copymods "Copying modules... ('.14b' files are prefs files)")
        (set #copyfonts
            (cat
                "Select drawer to copy the Protracker font to or skip this part.\n"
                "These fonts are pretty nice to use with the Deli14Bit Genie, but "
                "are not mandatory whatsoever."
            )
        )

    )
)

;--------------------------------------------------------------------------
; German Installer Strings
;--------------------------------------------------------------------------

(if (= @language "deutsch")
    (
        (set #lang 2)
    )
)

;--------------------------------------------------------------------------
; Error cleanup code.
;--------------------------------------------------------------------------

(onerror
    (
        (if (> @ioerr 0)
            (message (cat #ioerror "\n\n ERROR CODE: " @ioerr))
        )
    )
)


;--------------------------------------------------------------------------
; Initial questions
;--------------------------------------------------------------------------

(set #mask
    (askoptions
        (prompt #intro)
        (help #intro_help)
        (choices #installitem1 #installitem2 #installitem3 #installitem4 #installitem5)
        (default 27)
    )
)

;--------------------------------------------------------------------------
; Prepare some paths
;--------------------------------------------------------------------------

(set #deliconfig (getenv "DELICONFIG"))
(if #deliconfig
    (
        (set #delibase (pathonly #deliconfig))
    ) (
        (set #delibase
            (askdir
                (default @default-dest)
                (prompt #installwhere)
                (help #installwhere_help)
            )
        )
    )
)

(if (bitand #mask 1)
    (
        (set #deligenies (tackon #delibase "DeliGenies"))
        (set #ex (not (exists #deligenies)))
        (if (or #ex (= @user-level 2))
            (
                (set #deligenies
                    (askdir
                        (default (if #ex #delibase #deligenies))
                        (prompt #installgenie)
                        (help #askdrawer_help)
                    )
                )
            )
        )
    )
)

(if (bitand #mask 2)
    (
        (set #delidocs (tackon #delibase "Docs"))
        (set #ex (not (exists #delidocs)))
        (if (or #ex (= @user-level 2))
            (
                (set #delidocs
                    (askdir
                        (default (if #ex #delibase #delidocs))
                        (prompt #installdocs)
                        (help #askdrawer_help)
                    )
                )
            )
        )
    )
)

(if (bitand #mask 4)
    (
        (set #deliplayers (tackon #delibase "DeliPlayers"))
        (set #ex (not (exists #deliplayers)))
        (if (or #ex (= @user-level 2))
            (
                (set #deliplayers
                    (askdir
                        (default (if #ex #delibase #deliplayers))
                        (prompt #installplayers)
                        (help #askdrawer_help)
                    )
                )
            )
        )
    )
)

(if (bitand #mask 8)
    (
        (set #delimods "ST-00:Modules")
        (set #ex (not (exists #delimods (noreq))))
        (if (or #ex (= @user-level 2))
            (
                (set #delimods
                    (askdir
                        (default (if #ex #delibase #delimods))
                        (prompt #installmods)
                        (help #askdrawer_help)
                    )
                )
            )
        )
    )
)
;--------------------------------------------------------------------------
; Copy the files.
;--------------------------------------------------------------------------

(if (bitand #mask 1)
    (
        (copyfiles
            (prompt #copygenie)
            (help #copyfiles-help)
            (source "DeliGenies")
            (dest #deligenies)
            (all)
            (confirm)
        )
    )
)

(if (bitand #mask 2)
    (
        (copyfiles
            (prompt #copydocs)
            (help @copyfiles-help)
            (source "Deli14BitGenie.guide")
            (dest #delidocs)
            (confirm)
            (infos)
        )
    )
)

(if (bitand #mask 4)
    (
        (copyfiles
            (prompt #copyplayers)
            (help #copyplayers_help)
            (source "DeliPlayers")
            (dest #deliplayers)
            (all)
            (confirm)
        )
    )
)

(if (bitand #mask 8)
    (
        (copyfiles
            (prompt #copymods)
            (help @copyfiles-help)
            (source "Modules")
            (dest #delimods)
            (all)
            (confirm "average")
        )
    )
)

(if (bitand #mask 16)
    (
        (copyfiles
            (prompt #copyfonts)
            (help @copyfiles-help)
            (source "Fonts")
            (dest "FONTS:")
            (fonts)
            (all)
            (confirm "average")
        )
    )
)


;--------------------------------------------------------------------------
; Installation successful!
;--------------------------------------------------------------------------

(set @default-dest #delibase)
(exit)

