; $VER: Installation script for MD2V 1.0 (14. June 2002)
; © David Crawford
; Created with GoldED 6.2
;
;///////////////////////////////If you want to copy this script
;///////////////////////////////Just let me know ;o) I'm always
;///////////////////////////////Interested in new things too!

; check if we are running under correct OS

(if (< (/ (getversion) 65536) 40)

    (
        (abort "\n\nIncorrect OS version (software requires OS 3.1 or better )!")
    )
)

; error handling

(onerror

    (if (> @ioerr 0)

        (
            (message

                ("\n\nAn error has occurred during installation. Please check the log file to understand the error.")
            )
        )
    )

    (exit (quiet))
)
; --- default english -- never can tell if it'll need a translation.
(set #msg-welcome "\nWelcome to the MD2V install utility. \n©2002 David Crawford.")
(set #exit-msg "\n\n\n\n\n\nThanks for trying my script!\n\nAuthor: David Crawford")
(set #msg-req "\n\n\nThis program requires that both the rexxreqtools and reqtools libraries to be installed on your system.\n\nIf you do not have these libraries, please acquire them first.\n\nYou cannot copy the file MD2V.mdrx manually and expect it to work, as this install script builds the program based on where MicroDot and Voyager are installed on your Amiga.")

(set #msg-mdinstallpath "Locate the Microdot directory.")
(set #msg-vinstallpath "\nImportant\n\nLocate your copy of Voyager")
(set #msg-copydocs "\n\n\n\n\n\nCopy documentation?")
(set #msg-copymdrx "\n\n\n\n\n\nCopy ARexx script?")
(set #msg-skipmdrx "\n\n\n\n\nSkipping copy of MD2V.mdrx\n\nCopy the file manually to the Rexx directory inside the MicroDot directory.")
(set #msg-skipdocs "\n\n\n\n\nSkipping copy of documentation.")
(set #msg-setup1 "\nMicroDot automatically detects *.mdrx files within it's Rexx directory. \n\n Thus, usage in a nutshell is just to select the message you want to view with Voyager and select MD2V from the ARexx menu.  The script will also send the text from messages without html tags to Voyager. \n\n Finally, the script also works from within the message reader window. If you open a mail and see a bunch of html, all you have to do is activate the script from the menu.")
(set #runmview "\n\n\n\nThe button prefs can be edited to allow launching from a button.")
(set #msg-runprefs "\n\n\n\nWould you like to launch MicroDot's preferences editor now?\n\n\nNOTE: MicroDot must be running for this to work!")
(set #launching "\n\n\n\n\n\nLaunching MD Prefs.")
(set #msg-vrequest "\nWhen the Voyager ARexx port is not found, do you want to automatically start Voyager, or would you prefer a requestor?")
(set #msg-drequest "\nWould you like to be asked before deleting the temporary file created from the email?\n\nNote: the original message will not be affected either way.")

(set #yes  "Yes")
(set #no   "No ")
(set #auto "Automatic")
(set #req  "Requestor")

; --- If Translating, do not edit below this line ---

(set #rexxprt1
    (cat
     "\ncall addlib \"rexxreqtools.library\", 0, -30\n"
     "\n"
     "/*Get Message*/\n"
     "if show(PORTS,MD.1) then do\n"
     "   address MD.1 'ExtractSelectedMsgs T:MDMessage.html PART 1 NOREQ'\n"
     "   end\n"
     "else do\n"
     "    call rtezrequest('ERROR: MicroDot Port Not Found!')\n"
     "    exit(20)\n"
     "    end\n"
     "\n/* --- Vars Set By Installer --- */\n\n"
    )
)
(set #rexxprt2a "no_vreq = '1'\n")
(set #rexxprt2b "no_vreq = '0'\n")
(set #rexxprt3a "no_dreq = '1'\n\n")
(set #rexxprt3b "no_dreq = '0'\n\n")

; --- End Parts of REXX Code
(welcome #msg-welcome)
(message #msg-req)
(set #mdinstallpath
    (askdir
        (prompt #msg-mdinstallpath)
        (help @askdir-help)
        (default "Netconnect3:Programs/Microdot2")
    )
)

(if (< @user-level 1)
    (
     (set #copymdrx 1)
     (set #copydocs 1)
    )
    ; else
    (
     (if (< @user-level 2)
         (
          (set #copymdrx 1)
          (set #copydocs

              (askbool

                  (prompt #msg-copydocs)

                  (help @askbool-help)

                  (choices

                      #yes
                      #no
                  )

                  (default 1)
              )
          )


         )

         ; else

         (
          (set #copydocs

              (askbool

                  (prompt #msg-copydocs)

                  (help @askbool-help)

                  (choices

                      #yes
                      #no
                  )

                  (default 1)
              )
          )
          (set #copymdrx

              (askbool

                  (prompt #msg-copymdrx)

                  (help @askbool-help)

                  (choices

                      #yes
                      #no
                  )

                  (default 1)
              )
          )


         )
     )

    )
)
(set
    #mdrexxinstallpath
    (tackon #mdinstallpath "Rexx")
)
(set #vrequest

    (askchoice

        (prompt #msg-vrequest)

        (help @askchoice-help)

        (choices

            #auto
            #req
        )

        (default 0)
    )
)
(if (= #vrequest 1)

    (
        (set #rexxprt2 #rexxprt2a)
    )

    ; else

    (
        (set #rexxprt2 #rexxprt2b)
    )
)
(set #drequest

    (askchoice

        (prompt #msg-drequest)

        (help @askchoice-help)

        (choices

            #auto
            #req
        )

        (default 0)
    )
)
(if (= #drequest 1)

    (
        (set #rexxprt3 #rexxprt3a)
    )

    ; else

    (
        (set #rexxprt3 #rexxprt3b)
    )
)

(if (= #copymdrx 1)

    (
       (set #vinstallpath
            (askfile
                (prompt #msg-vinstallpath)
                (help @askdir-help)
                (default "Netconnect3:Programs/Voyager/V")
            )
       )
       (set #part1 "/* $VER: 0.8, ©2002 David Crawford. Open Microdot-II mail in Voyager window. */\n")
       (set #part2 "\nPath_V = 'Run >NIL: ")
       (set #part3 #vinstallpath)
       (set #part4 "'\n")
       (set #toprexx
            (cat #part1 #part2 #part3 #part4 #rexxprt1 #rexxprt2 #rexxprt3)
       )
       ;Create Requestors

       ;(message #toprexx)
         (textfile
          (prompt "\n\n\n\n\n\nBuilding Custom Script")
          (help @textfile-help)
          (dest (tackon #mdrexxinstallpath "MD2V.mdrx"))
          (append #toprexx)
          (include "Rexx/MD2V.mdrx")
         )
       ; (copyfiles
       ;
       ;     (source "Rexx/MD2V.mdrx")
       ;
       ;     (dest #mdrexxinstallpath)
       ;
       ;     (optional "oknodelete" "force" "askuser")
       ; )

    )

    ; else

    (
      (message #msg-skipmdrx)
    )
)
(if (= #copydocs 1)

    (
        (copyfiles

            (source "MD2V.guide")

            (dest (tackon #mdinstallpath "MD2V.guide"))

            (infos)

            (optional "oknodelete" "force" "askuser")
        )
        (copyfiles

            (source "prefs.iff")

            (dest (tackon #mdinstallpath "prefs.iff"))

            (optional "oknodelete" "force" "askuser")
        )

    )

    ; else

    (
        (working #msg-skipdocs)
    )
)

; --- end of program ---

(exit #exit-msg(quiet))

