; Installation script for XES
; Copyright (c) 1995 Fergus Duniho

(transcript "Installing the XDME Excelsior Suite ...")

(set @default-dest (getassign "XES"))
(if (> (strlen @default-dest) 0)
    (
        (set response
            (askchoice
                (prompt
                    "Because I sometimes remove stuff from XES, it is best "
                    "to delete your present XES installation before the "
                    "installation of the present version commences.  Do "
                    "you wish to delete it?"
                )
                (help @askchoice-help)
                (choices "Yes" "No")
            )
        )
        (if (= response 0)
            (run "delete XES:#? ALL")
        )
    )
    (
        (set @default-dest "Work:")
        (set appdir
            (askdir
                (prompt "In which drawer should the XES drawer reside?")
                (help @askdir-help)
                (default @default-dest)
            )
        )
        (set @default-dest (tackon appdir "XES"))

        (makedir @default-dest
            (infos)
            (prompt "Creating XES directory")
        )
        (makeassign "XES" @default-dest)
        ; Make changes to the startup sequence
        (working "Modifying the user-startup")
        (startup "XES"
            (prompt "Adding XES: assignment to user-startup")
            (help @startup-help)
            (command "; The XDME Excelsior Suite\n")
            (command "; Copyright (c) 1995 Fergus Duniho.\n")
            (command (cat "Assign XES: " @default-dest "\n"))
        )
    )
)

(makedir (tackon @default-dest "S")
    (prompt "Creating S directory")
)
(makedir (tackon @default-dest "GUI")
    (prompt "Creating GUI directory")
)
(makedir (tackon @default-dest "Rexx")
    (prompt "Creating Rexx directory")
)
(makedir (tackon @default-dest "Docs")
    (infos)
    (prompt "Creating Docs directory")
)

(copyfiles
    (prompt "Copying XDME scripts")
    (help @copyfiles-help)
    (source "S/")
    (dest (tackon @default-dest "S"))
    (confirm)
    (files)
    (all)
)

(copyfiles
    (prompt "Copying Graphical User Interfaces")
    (help @copyfiles-help)
    (source "GUI/")
    (dest (tackon @default-dest "GUI"))
    (confirm)
    (files)
    (all)
)

(copyfiles
    (prompt "Copying Documentation")
    (help @copyfiles-help)
    (source "Docs/")
    (dest (tackon @default-dest "Docs"))
    (infos)
    (confirm)
    (all)
)

(copyfiles
    (prompt "Copying ARexx Scripts")
    (help @copyfiles-help)
    (source "Rexx/")
    (dest (tackon @default-dest "Rexx"))
    (infos)
    (confirm)
    (all)
)

(set @default-dest
    (askdir
        (prompt "Install Paginate where?")
        (help @askdir-help)
        (default "C:")
    )
)

(copyfiles
    (prompt "Copying utility programs")
    (help @copyfiles-help)
    (source "C/Paginate")
    (dest @default-dest)
    (confirm)
)

(set edrc
    (tackon
        (askdir
            (prompt "In which drawer does (or will) your .edrc file reside?")
            (help @askdir-help)
            (default "S:")
        )
        ".edrc"
    )
)

(set response
    (askchoice
        (prompt
            "To make use of XES, your .edrc file must contain a line "
            "which reads: source XES:S/xes.xrc.  If you have your own "
            "macros, keymappings, or settings in your .edrc file, then "
            "you should just add this line to it.  Append it to get the "
            "full benefit of XES, or prepend to give priority to what is "
            "already in your .edrc file.  If you don't have an .erdc file, "
            "or if you are just using one from a previous version of XES, "
            "you should just write a new .edrc file."
        )
        (help @askchoice-help)
        (choices "Append to .edrc" "Prepend to .edrc" "Write new .edrc" "Leave .edrc alone")
    )
)

(if (= response 0)
    (run (cat "echo >>" edrc " source XES:S/xes.xrc"))
)

(if (= response 1) (
    (run (cat "copy " edrc " t:"))
    (run (cat "echo >" edrc " source XES:S/xes.xrc"))
    (run (cat "type >>" edrc " t:.edrc"))
))

(if (= response 2)
    (run (cat "echo >" edrc " source XES:S/xes.xrc"))
)

(if (not (exists "ENV:Diary"))
    (
        (set diarydir
            (askdir
                (prompt
                    "XES makes special provisions for you to keep a secret diary. "
                    "It expects to find all diary entries in a single drawer. "
                    "This script will create a drawer for you called /Diary/. "
                    "Where do you want the Diary drawer to reside? Please don't "
                    "choose to put it in the XES: drawer, as that drawer may get "
                    "flushed when you update XES again."
                )
                (help @askdir-help)
                (default "Work:")
            )
        )

        (set @default-dir (tackon diarydir "Diary/"))
        (makedir @default-dest
            (infos)
            (prompt "Creating Diary directory")
        )
        (run (cat "setenv Diary " @default-dir))
        (run "copy ENV:Diary ENVARC:")
    )
)

(if (not (exists "ENV:MyName"))
    (
        (set name
            (askstring
                (prompt
                    "To mark your diary entries as yours, XES also needs to "
                    "know what name you wish to be referred to at the "
                    "beginning of each diary entry. You probably want to "
                    "enter your first name and last. What name do you want "
                    "to appear in your diary entries?"
                )
                (help @asktstring-help)
            )
        )

        (run (cat "setenv MyName " name))
        (run "copy ENV:MyName ENVARC:")
    )
)

(message
    "The XDME Excelsior Suite has been successfully installed. "
    "It will be available to you the next time you use XDME."
)

(exit (quiet))
