; DCTV Installation script (v1.1)

(set    ; define some strings
    S_Proceed "Proceed"
    S_Skip    "Skip This Part"
)

(set SrcDir (pathonly @icon))           ; Set source directory
(set BigVersion (exists (tackon SrcDir "DCTV")))    ; figure out which disk we're on (and which files to install)

    ; See if the user booted off our disk
(if (= (getassign "SYS") SrcDir)
    (abort "You must boot from your native environment in order to run this installation utility.")
)

    ; Ask user for target drawer
(set ProgDir "DCTV_1.1")                ; define for DCTV drawer that will be created
(set DestDir
    (tackon
        (askdir
            (prompt "In which disk or drawer should the \"DCTV_1.1\" drawer be created?")
            (help
                "A drawer named \""ProgDir"\" will be created "
                "in the disk or drawer that you select. "
                (if BigVersion
                    "DCTV"
                    "DCTVProc and DCTVPaint"
                )
                " will be installed in the " ProgDir " drawer.\n"
                "\n"
                @askdir-help
            )
            (default @default-dest)
        )
        ProgDir
    )
)
(set @default-dest DestDir)             ; set @default-dest w/ result

    ; Create destination
(makedir DestDir (infos))

    ; Delete old fonts (must do before trying to install anything)
(if (> @user-level 0)
    (if (exists "FONTS:dctv")
        (if (askbool
                (prompt
                    "Your FONTS: directory appears to contain old DCTV fonts. "
                    "DCTV v1.1 no longer requires these fonts to reside in FONTS:.\n"
                    "\n"
                    "Do you wish to delete the old DCTV fonts?"
                )
                (help
                    "The following files will be deleted by this operation:\n"
                    "    FONTS:DCTV/6\n"
                    "    FONTS:DCTV/7e\n"
                    "    FONTS:DCTV/8e\n"
                    "    FONTS:DCTV\n"
                    "    FONTS:DCTV.font\n"
                    "\n"
                    "NOTE:  While these files are not needed by DCTV v1.1, they are required "
                    "for DCTV v1.0. If you still plan on running the old version of DCTV, "
                    "you shouldn't delete these fonts now."
                )
            )
            (
                (delete "FONTS:DCTV.font")
                (delete "FONTS:DCTV/6")
                (delete "FONTS:DCTV/7e")
                (delete "FONTS:DCTV/8e")
                (delete "FONTS:DCTV")
            )
        )
    )
)

    ; Copy programs + DCTVData drawer
(copyfiles
    (source SrcDir)
    (dest DestDir)
    (if BigVersion                                      ; install whichever programs are on the source disk
        (choices "DCTV" "DCTVData")
        (choices "DCTVPaint" "DCTVProc" "DCTVData")
    )
    (infos)
)

    ; Install disk-resident libraries (where newer)
(copylib
    (source (tackon SrcDir "libs/iffparse.library"))    ; not originally available to 1.3 owners
    (dest "LIBS:")
)
(copylib
    (source (tackon SrcDir "libs/diskfont.library"))    ; v34.  might update 1.2 owners this way.
    (dest "LIBS:")
)

    ; Install 1.3 patches (if system version < 36)
(if (< (/ (getversion) 65536) 36)           ; getversion returns 32-bit version #
    (
        (transcript "Installing for OS v1.3.")

        (set    ; define flags used later
            INSTF_SetPatch       $1         ; install SetPatch v1.38
            INSTF_SetPatchMrgCop $2         ; install SetPatchMrgCop
        )

            ; determine which objects need to be installed
        (set InstFlags 0)
        (if (if (not (exists "C:SetPatch"))
                1
                (if (<> (getsize "C:SetPatch") (getsize (tackon SrcDir "C/SetPatch")))
                    1
                    (<> (getsum "C:SetPatch") (getsum (tackon SrcDir "C/SetPatch")))
                )
            )
            (set InstFlags (OR InstFlags INSTF_SetPatch))
        )
        (if (if (not (exists "C:SetPatchMrgCop"))
                1
                (< (getversion "C:SetPatchMrgCop") (getversion (tackon SrcDir "C/SetPatchMrgCop")))
            )
            (set InstFlags (OR InstFlags INSTF_SetPatchMrgCop))
        )

        (if InstFlags               ; only present user w/ choices if there's anything to install
            (set InstFlags
                (askoptions
                    (prompt "The following checkmarked commands need to be installed into your system:")
                    (help
                        "These programs fix bugs in Version 1.3 of the Amiga Operating System:\n"
                        "    SetPatch v1.38 fixes a bug that can cause the system to crash "
                        "when you mix usage of interlaced and non-interlaced screens.\n"
                        "    SetPatchMrgCop fixes some problems with full overscan displays.\n"
                        "\n"
                        "Only the commands initially marked with a checkmark need to be installed into your system. "
                        "The checkmarked commands will be installed in your C: directory. "
                        "To skip installation of any of these commands, turn off the corresponding checkmark.\n"
                        "\n"
                        @askoptions-help
                    )
                    (choices "SetPatch v1.38" "SetPatchMrgCop")
                    (default InstFlags)
                )
            )
        )

            ; install SetPatch
        (if (AND InstFlags INSTF_SetPatch)
            (
                (set CDir "C:")             ; set default CDir (spot to place SetPatch)
                (if (= @user-level 2)       ; if expert user, ask where to put SetPatch
                    (set CDir
                        (askdir
                            (prompt "Where should SetPatch be installed?")
                            (help
                                "SetPatch must be installed in the C directory of your boot partition or diskette "
                                "in order for it to be found by your Startup-Sequence. "
                                "You may need to examine your boot environment before "
                                "choosing the appropriate location for SetPatch.\n"
                                "\n"
                                "The following list shows the correct location for SetPatch on standard configurations "
                                "of Commodore hard disks:\n"
                                "    A3000    C:\n"
                                "    A2091    C:\n"
                                "    A2090A   Boot:C\n"
                                "    A2090    Workbench1.3:C\n"
                                "\n"
                                @askdir-help
                            )
                            (default CDir)
                        )
                    )
                )
                (copyfiles
                    (source (tackon SrcDir "c/SetPatch"))
                    (dest CDir)
                )
            )
        )

            ; install SetPatchMrgCop
        (if (AND InstFlags INSTF_SetPatchMrgCop)
            (
                (copyfiles
                    (source (tackon SrcDir "c/SetPatchMrgCop"))
                    (dest "C:")
                )
                (startup "DCTV"
                    (prompt
                        "Some instructions need to be added to \"S:user-startup\" "
                        "so that your system will be properly configured to use DCTV."
                    )
                    (help
                        "The command \"SetPatchMrgCop\" will be added to your \"S:user-startup\".\n"
                        "\n"
                        @startup-help
                    )
                    (command
                        "SetPatchMrgCop\n"
                    )
                )
            )
        )
    )
    (transcript "Installing for OS v2.0.")
)
