;**********************************************************************
;
;   SGInstallLibs - SuperGen library Installer script
;
;   v3.1 - 07 Aug 1992
;
;**********************************************************************


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

(set                                ; define button labels
    proceed-label "Proceed"
    skip-label    "Skip This Part"
)

(onerror                            ; set abort handler (must match cleanup below)
    (makeassign "_sgdevs" (safe))
)

(set srcdir (pathonly @icon))       ; Set source directory

(set @default-dest "")              ; clear @default-dest since there's no real target for this installation


; --------------------- Welcome

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

(welcome
    "    This utility will install system files required by the SuperGen software.\n"
    "    It does not install SuperGen utilities, however. "
    "The utilities may be installed by dragging the desired icons on the Workbench."
)


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

(set                                ; library descriptions (used multiple places).  user-level == 2 only.
    supergenlib-desc (cat
        "    \"supergen.library\" and \"copinit.library\" are custom "
        "libraries supplied by Digital Creations "
        "providing software control functions for the SuperGen "
        "family of genlocks. SGHotKeys and SGJoyStick "
        "require these libraries. The SuperGen 2000s control "
        "panel also requires these libraries.\n"
    )
    iffparselib-desc (cat
        "    \"iffparse.library\" is supplied by Commodore as part "
        "of Workbench 2.0 for reading and writing IFF files. "
        "It may also be used with Amiga OS v1.3. The picture "
        "display utility \"Disp\" requires this library.\n"
    )
)

(set destlibdir "LIBS:")
(if (= @user-level 2)               ; ask expert users where to put libraries
    (set destlibdir
        (askdir
            (prompt "Where should libraries be installed?")
            (help
                "The following libraries will be installed if not already present in your system:\n"
                "    supergen.library\n"
                "    copinit.library\n"
                "    iffparse.library\n"
                "\n"
                "These files must reside in the LIBS: logical device. "
                "If you use a multiple-directory assign for LIBS:, enter the appropriate "
                "directory for these libraries.  Otherwise use LIBS:.\n"
                "\n"
                "Description of libraries:\n"
                supergenlib-desc
                iffparselib-desc
                "\n"
                @askdir-help
            )
            (default destlibdir)
        )
    )
)
(working)                           ; clear askdir requester (below stuff can proceed silently)

(set srclibdir (tackon srcdir "libs"))

(set i 0)
(while (set libname (select i "supergen.library" "copinit.library" "iffparse.library" ""))

    (copylib
        (source (tackon srclibdir libname))
        (dest destlibdir)
        (confirm)
        (prompt "Installing \"" libname "\"")
        (help
            (select i supergenlib-desc supergenlib-desc iffparselib-desc)       ; order must be same as above
            "\n"
            @copylib-help
        )
    )
    (complete (select i 25 50 75))      ; @@@ something of a hack.  might need to change

    (set i (+ i 1))
)


; --------------------- Install supergen-configuration

(set                                ; set string describing supergen-config (used more than once).  user-level == 2 only.
    sgconfig-desc (cat
        "    The \"supergen-configuration\" file contains information required for \"supergen.library\" "
        "to communicate with the SuperGen. It describes which model SuperGen you have "
        "(default is original SuperGen). "
        "It also contains default settings for the SuperGen 2000s.\n"
    )
)

(set devdir "DEVS:")
(if (= @user-level 2)               ; ask experts where to put supergen-configuration.
    (set devdir
        (askdir
            (prompt "Where should \"supergen-configuration\" be installed?")
            (help
                sgconfig-desc
                "    \"supergen-configuration\" must be installed into your DEVS: logical device. "
                "If you use a multiple-directory assign for DEVS:, enter the appropriate "
                "directory for \"supergen-configuration\". Otherwise use DEVS:.\n"
                "\n"
                @askdir-help
            )
            (default devdir)
        )
    )
)
(makeassign "_sgdevs" devdir (safe))        ; get first directory of multi-directory assign
(transcript "Assign _sgdevs: \""devdir"\"") ; doesn't get doc'd otherwise

(set copyconfig TRUE)
(if (> @user-level 0)               ; if non-novice and supergen-configuration already exists, get user confirmation before installing
    (if (exists "_sgdevs:supergen-configuration")
        (set copyconfig
            (askbool
                (prompt
                    "\"supergen-configuration\" already installed in " devdir ".\n"
                    "\n"
                    "Re-install this file?"
                )
                (help
                    sgconfig-desc
                    "    Re-installing this file will reset SuperGen 2000s default settings to the factory presets.\n"
                )
                (choices proceed-label skip-label)
            )
        )
    )
)

(if copyconfig
    (copyfiles
        (source (tackon SrcDir "devs/supergen-configuration"))
        (dest "_sgdevs:")
    )
)
(complete 100)


; --------------------- clean up (must match onerror above)

(makeassign "_sgdevs" (safe))

(exit
    "You may now install the SuperGen utilities by dragging the desired icons on the Workbench."
)
