;**********************************************************************
;
;   Install - DCTV Installer script
;
;   v1.1 - 19 Nov 1991
;
;**********************************************************************


; --------------------- Setup

(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)

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

(complete 0)


; --------------------- Get destination directory

(transcript "Selecting target drawer.")

    ; init DestDir to default drawer (doesn't actually need to exist)
(set ProgDir "DCTV")

(if (= (exists (tackon @default-dest ProgDir)) 1)   ; if there's a file named "DCTV", use "DCTV_1.1" instead
    (set ProgDir "DCTV_1.1")
)

(set DestDir (tackon @default-dest ProgDir))

    ; get / create target
(if (> @user-level 0)
    (set DestDir                    ; average and expert users: ask where to put DCTV
        (askdir
            (prompt "In which drawer should the DCTV software be installed?")
            (help
                "Select the drawer where the following files should be installed:\n"
                (if BigVersion
                    (cat
                        "    DCTV\n"
                    )
                    (cat
                        "    DCTVProc\n"
                        "    DCTVPaint\n"
                    )
                )
                "    DCTVData\n"
                "\n"
                @askdir-help
            )
            (default DestDir)
        )
    )
    (makedir DestDir (infos))       ; novice users: just make the directory
)

(set @default-dest DestDir)         ; set @default-dest w/ result
(complete 10)


; --------------------- Delete old fonts (must do before trying to install anything)

(if (exists "FONTS:dctv")
    (
        (transcript "\nOld DCTV fonts detected.  Delete 'em?")
        (if (askbool
                (default 0)
                (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")
            )
        )
    )
)
(complete 20)


; --------------------- Copy programs + DCTVData drawer

(transcript "\nInstalling software.")
(working "Installing software...")  ; clear any remaining prompts

    ; Define flags for which programs to install (based on BigVersion).
    ; Only has non-zero flags for objects in this version.
(if BigVersion
    (set
        INSTF_DCTV      $1
        INSTF_DCTVPaint 0
        INSTF_DCTVProc  0
        INSTF_DCTVData  $2
    )
    (set
        INSTF_DCTV      0
        INSTF_DCTVPaint $1
        INSTF_DCTVProc  $2
        INSTF_DCTVData  $4
    )
)

    ; set InstFlags for things to install
(set InstFlags $ffff)           ; default to installing everything
(if (= @user-level 2)           ; only ask experts which programs to install
    (set InstFlags
        (askoptions
            (prompt "Installing the following DCTV software to \"" DestDir "\":")
            (if BigVersion
                (choices
                    "DCTV"
                    "DCTVData"
                )
                (choices
                    "DCTVPaint"
                    "DCTVProc"
                    "DCTVData"
                )
            )
            (help
                (if BigVersion
                    (cat
                        "Software for users with 3MB or more of memory:\n"
                        "    DCTV - full version of the DCTV software.\n"
                        "    DCTVData - drawer contain data files necessary for DCTV to run. "
                        "It must be installed in the same drawer as this program.\n"
                    )
                    (cat
                        "Software for users with less than 3MB of memory:\n"
                        "    DCTVPaint - low memory Paint module.\n"
                        "    DCTVProc - Digitize, Process, and Convert module.\n"
                        "    DCTVData - drawer contain data files necessary for DCTVProc and DCTVPaint to run. "
                        "It must be installed in the same drawer as these programs.\n"
                    )
                )
                "\n"
                @askoptions-help
            )
            (default InstFlags)
        )
    )
)

    ; loop thru program and data drawer list installing only those things that have bits set in InstFlags
(set n 0)
(while (set fname (select n "DCTV" "DCTVPaint" "DCTVProc" "DCTVData" ""))
    (if (AND InstFlags (select n INSTF_DCTV INSTF_DCTVPaint INSTF_DCTVProc INSTF_DCTVData))
        (
            (copyfiles
                (source SrcDir)
                (dest DestDir)
                (choices fname)
            )
            (if (not (exists (tackon DestDir (cat fname ".info"))))
                (
                    (copyfiles
                        (source SrcDir)
                        (dest DestDir)
                        (choices (cat fname ".info"))
                    )
                    (tooltype
                        (dest (tackon DestDir fname))
                        (noposition)
                    )
                )
            )
        )
    )
    (complete
        (if BigVersion
            (select n 50 50 50 60)
            (select n 20 40 50 60)
        )
    )
    (set n (+ n 1))
)


; --------------------- Install disk-resident libraries (where newer)

(transcript "\nChecking libraries.")
(working "Checking system files...")                    ; close status box

    ; iffparse.library.  not originally available to 1.3 owners.
    ; (if getversion... avoids prompting experts to install an older version)
(if (< (getversion "LIBS:iffparse.library") (getversion (tackon SrcDir "libs/iffparse.library")))
    (copylib
        (source (tackon SrcDir "libs/iffparse.library"))
        (dest "LIBS:")
        (confirm)
        (prompt
            "Installing iffparse.library in LIBS:"
        )
        (help
            "DCTV software requires iffparse.library v2 or newer."
        )
    )
)
(complete 70)

    ; diskfont.library v34.  might update 1.2 owners this way.
    ; (if getversion... avoids prompting experts to install an older version)
(if (< (getversion "LIBS:diskfont.library") (getversion (tackon SrcDir "libs/diskfont.library")))
    (copylib
        (source (tackon SrcDir "libs/diskfont.library"))
        (dest "LIBS:")
        (confirm)
        (prompt
            "Installing diskfont.library in LIBS:"
        )
        (help
            "DCTV software requires diskfont.library v34 or newer."
        )
    )
)
(complete 80)


; --------------------- Install 1.3 patches (if system version < 36)

(if (< (/ (getversion) 65536) 36)           ; getversion returns 32-bit version #
    (
        (transcript "\nInstalling system files for OS v1.3.")
        (working "Checking system files...")

        (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 (<> (getsize "C:SetPatch") (getsize (tackon SrcDir "C/SetPatch")))
                1
                (<> (getsum "C:SetPatch") (getsum (tackon SrcDir "C/SetPatch")))
            )
            (set InstFlags (OR InstFlags INSTF_SetPatch))
        )
        (if (< (getversion "C:SetPatchMrgCop") (getversion (tackon SrcDir "C/SetPatchMrgCop")))
            (set InstFlags (OR InstFlags INSTF_SetPatchMrgCop))
        )

        (if (= @user-level 2)           ; only ask experts which patches to install
            (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)
                )
            )
        )
        (complete 90)

            ; 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 "\nInstalling system files for OS v2.0.")
)
(complete 100)
