;**************************************************************************
;*                                                                        *
;*                 Installer Script For Accessible Player                 *
;*                                                                        *
;*                            Update 21/03-1995                           *
;*                                                                        *
;**************************************************************************

;--------------------------------------------------------------------------
; Procedures

(procedure InstallLib
    (working ("Testing %s" libname))
    (copylib
        (prompt ("Do you want to install the \"%s\"?" libname))
        (help @copylib-help)
        (source (tackon tempdir libname))
        (dest libdest)
        (confirm)
    )
)

(procedure MakeDocDir
    (makedir (tackon @default-dest "Docs"))
    (copyfiles
        (source (tackon sdir "Docs.info")) ;Copy Icon To Docs Directory
        (dest @default-dest)
    )
)

(procedure DeleteAll
    (if (exists deldir)
        (foreach deldir "#?"
            (delete (tackon deldir @each-name)
                (optional force)
            )
        )
    )
)

;--------------------------------------------------------------------------
; ** Install Procedure

(procedure Install
    (message "You are now about to install the APlayer program. "
             "You will first be asked for all the different files "
             "you can install and then this script will begin to "
             "install the files."
    )

    (set default-dest
        (askdir
            (prompt "Where do you want to make the APlayer drawer?")
            (help @askdir-help)
            (default @default-dest)
        )
    )
    (set @default-dest default-dest)


    (set fileflag
        (askoptions
            (prompt "Which files do you want to install in the "
                    "\"APlayer\" drawer?")
            (help @askoptions-help)
            (choices
                "APlayer"
                "APlayer.guide"
                "Commercial Picture"
                "Sheep module"
            )
        )
    )


    (set play
        (askbool
            (prompt "Do you want to install external players?")
            (help "If you select yes, you can select between all the "
                  "external players this version support. All the players "
                  "will be stored in your \"LIBS:APlayer\" drawer.")
        )
    )

    (set playflag1 0)
    (set playflag2 0)
    (set playflag3 0)
    (if play
        (
            (set playflag1
                (askoptions
                    (prompt "Which extern players do you want to install in "
                            "your \"LIBS:APlayer\" drawer?")
                    (help @askoptions-help)
                    (choices
                        "Action Amics"
                        "Digital Mugician"
                        "DSS"
                        "Fred"
                        "Face The Music"
                        "Future Composer 1.0-1.3"
                        "Future Composer 1.4"
                        "Hippel-COSO"
                        "Hippel"
                        "IFF-8SVX"
                        "IFF-AIFF"
                        "IFF-SMUS"
                        "In Stereo!"
                        "JamCracker"
                        "Major Tom"
                        "Maniacs of Noise"
                    )
                )
            )

            (set playflag2
                (askoptions
                    (prompt "Which extern players do you want to install in "
                            "your \"LIBS:APlayer\" drawer?")
                    (help @askoptions-help)
                    (choices
                        "MED"
                        "Music Assembler"
                        "Noise Packer 2.0"
                        "Noise Packer 3.0"
                        "OctaMed"
                        "Oktalyzer"
                        "Puma Tracker"
                        "Quadra Composer"
                        "RIFF-WAVE"
                        "Ron Klaren"
                        "SID"
                        "SidMon 1.0"
                        "SidMon 2.0"
                        "Sonic Arranger"
                        "Sound Control"
                        "Sound FX 1.3"
                    )
                )
            )

            (set playflag3
                (askoptions
                    (prompt "Which extern players do you want to install in "
                            "your \"LIBS:APlayer\" drawer?")
                    (help @askoptions-help)
                    (choices
                        "Sound FX 2.0"
                        "Sound Monitor 2.0"
                        "StarTrekker 4"
                        "StarTrekker 4AM"
                        "Synthesis"
                        "TFMX 1.5"
                        "TFMX 7-Voices"
                        "TFMX Professional"
                        "The Musical Enlightenment"
                        "Tronic Tracker"
                        "Vector Dean"
                        "Whittaker"
                    )
                )
            )
        )
    )


    (set libs
        (askoptions
            (prompt "Which other libraries do you want to install in your "
                    "\"LIBS:\" drawer?  Press help for more info.")
            (help "This is some libraries the APlayer uses or can use. "
                  "Here follow a little description of the different "
                  "libraries:\n\n"
                  "PlaySID.library: This library are used in the SID "
                  "player. That means, if you want to hear some C64 SID "
                  "tunes, you have to install this library.\n\n"
                  "Powerpacker.library: APlayer can use this library to "
                  "decrunch powerpacked modules.\n\n"
                  "Reqtools.library: This library is required by APlayer. "
                  "With this library APlayer shows filerequesters etc.\n\n"
                  "Rexxtools.library: If you want ARexx in APlayer, you "
                  "have to install this library. It helps APlayer to make "
                  "the ARexx interface.\n\n"
                  "Xpkmaster.library: APlayer can also use this library to "
                  "decrunch both powerpacked and xpk packed modules.\n\n"
                  "Unpack.library: This library can decrunch a lot of "
                  "different types of crunched modules. See the unpack.doc "
                  "for more information.")
            (choices
                "PlaySID.library"
                "Powerpacker.library"
                "Reqtools.library"
                "Rexxtools.library"
                "Xpkmaster.library"
                "Unpack.library"
            )
        )
    )


    (set cpu (database "cpu"))
    (if (< cpu 68020)
        (set marked 3)
        (set marked 5)
    )

    (set xpk
        (askoptions
            (prompt "Which xpk libraries do you want to install in your "
                    "\"LIBS:compressors\" drawer?")
            (help @askoptions-help)
            (choices
                "xpkSMPL.library"
                "xpkSQSH.library (68000)"
                "XpkSQSH.library (68020)"
            (default marked)
            )
        )
    )


    (set bonus
        (askbool
            (prompt "Do you want to install some bonus programs?")
            (help @askbool-help)
        )
    )

    (set bonusflag 0)
    (if bonus
        (
            (set bonusflag
                (askoptions
                    (prompt "Which bonus programs do you want to install?")
                    (help @askoptions-help)
                    (choices
                        "FSS2APML - Converts from FSS to APML file"
                        "FSSOptimizer - Optimize your FSS file"
                    )
                )
            )
        )
    )


    (set arexx
        (askbool
            (prompt "Do you want to install ARexx?")
            (help @askbool-help)
        )
    )


    (set doc
        (askbool
            (prompt "Do you want to install docs?")
            (help "If you select yes, you can select between all the "
                  "different docs. All the docs will be install in the "
                  "\"APlayer/Docs\" drawer.")
        )
    )

    (set docflag 0)
    (if doc
        (set docflag
            (askoptions
                (prompt "Which files do you want to install in the "
                        "\"APlayer/Docs\" drawer?")
                (help @askoptions-help)
                (choices
                    "Bonus.doc"
                    "MissingModules.txt"
                    "PlaySid.doc"
                    "SMPL.doc"
                    "SQSH.doc"
                    "Unpack.doc"
                    "Installer Script"
                )
            )
        )
    )


    (set developer
        (askbool
            (prompt "Do you want to install the developer set?")
            (help @askbool-help)
        )
    )

; ** Begin to copy the files

    (set @default-dest (tackon @default-dest "APlayer"))
    (set lhex (tackon sdir "lhex"))
    (set tempdir "T:apTemp")
    (set deldir tempdir)

    (makedir tempdir)
    (makedir @default-dest)

    (copyfiles                             ;Copy Icon To APlayer Directory
        (source (tackon sdir "/APlayer.info"))
        (dest (tackon @default-dest "/"))
    )

    (if fileflag
        (
            (if (in fileflag 0)                     ;APlayer File
                (
                    (copyfiles
                        (source (tackon sdir "APlayer"))
                        (dest @default-dest)
                        (infos)
                    )
                )
            )

            (if (in fileflag 1)                     ;APlayer.guide
                (
                    (MakeDocDir)
                    (copyfiles                      ;Copy Icon To Docs Directory
                        (source (tackon sdir "Docs.info"))
                        (dest @default-dest)
                    )

                    (copyfiles
                        (source (tackon sdir "Docs/APlayer.guide"))
                        (dest (tackon @default-dest "Docs"))
                        (infos)
                    )
                )
            )

            (if (in fileflag 2)                     ;Commercial Picture
                (
                    (copyfiles
                        (source (tackon sdir "ShowMe.jpg"))
                        (dest @default-dest)
                        (infos)
                    )
                )
            )

            (if (in fileflag 3)                     ;Sheep Module
                (
                    (copyfiles
                        (source (tackon sdir "MOD.Sheeps"))
                        (dest @default-dest)
                        (infos)
                    )
                )
            )

        )
    )
    (complete 9)


    (if (or (or playflag1 playflag2) playflag3)
        (
            (makedir "LIBS:APlayer")
            (working "Unpacking player archive....")
            (run ("\"%s\" -fqw=%s x Files/Players.lha >NIL:" lhex tempdir))
            (set libdest "LIBS:APlayer/")
            (delete "LIBS:APlayer/apHolyNoise.library")

            (if playflag1
                (
                    (if (in playflag1 0)
                        (
                            (set libname "apActionAmics.library")
                            (InstallLib)
                        )
                    )

                    (if (in playflag1 1)
                        (
                            (set libname "apDigitalMugician.library")
                            (InstallLib)
                        )
                    )

                    (if (in playflag1 2)
                        (
                            (set libname "apDSS.library")
                            (InstallLib)
                        )
                    )

                    (if (in playflag1 3)
                        (
                            (set libname "apFred.library")
                            (InstallLib)
                        )
                    )

                    (if (in playflag1 4)
                        (
                            (set libname "apFTM.library")
                            (InstallLib)
                        )
                    )

                    (if (in playflag1 5)
                        (
                            (set libname "apFuture13.library")
                            (InstallLib)
                        )
                    )

                    (if (in playflag1 6)
                        (
                            (set libname "apFuture14.library")
                            (InstallLib)
                        )
                    )

                    (if (in playflag1 7)
                        (
                            (set libname "apHippel-COSO.library")
                            (InstallLib)
                        )
                    )

                    (if (in playflag1 8)
                        (
                            (set libname "apHippel.library")
                            (InstallLib)
                        )
                    )

                    (if (in playflag1 9)
                        (
                            (set libname "apIFF-8SVX.library")
                            (InstallLib)
                        )
                    )

                    (if (in playflag1 10)
                        (
                            (set libname "apIFF-AIFF.library")
                            (InstallLib)
                        )
                    )

                    (if (in playflag1 11)
                        (
                            (set libname "apIFF-SMUS.library")
                            (InstallLib)
                        )
                    )

                    (if (in playflag1 12)
                        (
                            (set libname "apInStereo!.library")
                            (InstallLib)
                        )
                    )

                    (if (in playflag1 13)
                        (
                            (set libname "apJamCracker.library")
                            (InstallLib)
                        )
                    )

                    (if (in playflag1 14)
                        (
                            (set libname "apMajorTom.library")
                            (InstallLib)
                        )
                    )

                    (if (in playflag1 15)
                        (
                            (set libname "apMON.library")
                            (InstallLib)
                        )
                    )
                )
            )
            (complete 18)

            (if playflag2
                (
                    (if (in playflag2 0)
                        (
                            (set libname "apMED.library")
                            (InstallLib)
                        )
                    )

                    (if (in playflag2 1)
                        (
                            (set libname "apMusicAss.library")
                            (InstallLib)
                        )
                    )

                    (if (in playflag2 2)
                        (
                            (set libname "apNoisePacker20.library")
                            (InstallLib)
                        )
                    )

                    (if (in playflag2 3)
                        (
                            (set libname "apNoisePacker30.library")
                            (InstallLib)
                        )
                    )

                    (if (in playflag2 4)
                        (
                            (set libname "apOctaMed.library")
                            (InstallLib)
                        )
                    )

                    (if (in playflag2 5)
                        (
                            (set libname "apOktalyzer.library")
                            (InstallLib)
                        )
                    )

                    (if (in playflag2 6)
                        (
                            (set libname "apPumaTracker.library")
                            (InstallLib)
                        )
                    )

                    (if (in playflag2 7)
                        (
                            (set libname "apQuadraComposer.library")
                            (InstallLib)
                        )
                    )

                    (if (in playflag2 8)
                        (
                            (set libname "apRIFF-WAVE.library")
                            (InstallLib)
                        )
                    )

                    (if (in playflag2 9)
                        (
                            (set libname "apRonKlaren.library")
                            (InstallLib)
                        )
                    )

                    (if (in playflag2 10)
                        (
                            (set libname "apSID.library")
                            (InstallLib)
                        )
                    )

                    (if (in playflag2 11)
                        (
                            (set libname "apSidMon10.library")
                            (InstallLib)
                        )
                    )

                    (if (in playflag2 12)
                        (
                            (set libname "apSidMon20.library")
                            (InstallLib)
                        )
                    )

                    (if (in playflag2 13)
                        (
                            (set libname "apSonicArranger.library")
                            (InstallLib)
                        )
                    )

                    (if (in playflag2 14)
                        (
                            (set libname "apSoundControl.library")
                            (InstallLib)
                        )
                    )

                    (if (in playflag2 15)
                        (
                            (set libname "apSoundFX13.library")
                            (InstallLib)
                        )
                    )
                )
            )
            (complete 27)

            (if playflag3
                (
                    (if (in playflag3 0)
                        (
                            (set libname "apSoundFX20.library")
                            (InstallLib)
                        )
                    )

                    (if (in playflag3 1)
                        (
                            (set libname "apSoundMon20.library")
                            (InstallLib)
                        )
                    )

                    (if (in playflag3 2)
                        (
                            (set libname "apStarTrekker4.library")
                            (InstallLib)
                        )
                    )

                    (if (in playflag3 3)
                        (
                            (set libname "apStarTrekker4AM.library")
                            (InstallLib)
                        )
                    )

                    (if (in playflag3 4)
                        (
                            (set libname "apSynthesis.library")
                            (InstallLib)
                        )
                    )

                    (if (in playflag3 5)
                        (
                            (set libname "apTFMX_15.library")
                            (InstallLib)
                        )
                    )

                    (if (in playflag3 6)
                        (
                            (set libname "apTFMX_7V.library")
                            (InstallLib)
                        )
                    )

                    (if (in playflag3 7)
                        (
                            (set libname "apTFMX_Pro.library")
                            (InstallLib)
                        )
                    )

                    (if (in playflag3 8)
                        (
                            (set libname "apTME.library")
                            (InstallLib)
                        )
                    )

                    (if (in playflag3 9)
                        (
                            (set libname "apTronicTracker.library")
                            (InstallLib)
                        )
                    )

                    (if (in playflag3 10)
                        (
                            (set libname "apVectorDean.library")
                            (InstallLib)
                        )
                    )

                    (if (in playflag3 11)
                        (
                            (set libname "apWhittaker.library")
                            (InstallLib)
                        )
                    )
                )
            )
        (DeleteAll)
        )
    )
    (complete 36)


    (if libs
        (
            (working "Unpacking library archive....")
            (run ("\"%s\" -fqw=%s x Files/Libraries.lha >NIL:" lhex tempdir))
            (set libdest "LIBS:")

            (if (in libs 0)
                (
                    (set libname "playsid.library")
                    (InstallLib)
                )
            )

            (if (in libs 1)
                (
                    (set libname "powerpacker.library")
                    (InstallLib)
                )
            )

            (if (in libs 2)
                (
                    (set libname "reqtools.library")
                    (InstallLib)
                )
            )

            (if (in libs 3)
                (
                    (set libname "rexxtools.library")
                    (InstallLib)
                )
            )

            (if (in libs 4)
                (
                    (set libname "xpkmaster.library")
                    (InstallLib)
                )
            )

            (if (in libs 5)
                (
                    (set libname "unpack.library")
                    (InstallLib)
                )
            )
        (DeleteAll)
        )
    )
    (complete 45)


    (if xpk
        (
            (makedir "LIBS:compressors")
            (working "Unpacking XPK-Subs archive....")
            (run ("\"%s\" -fqw=%s x Files/XPKSubs.lha >NIL:" lhex tempdir))
            (set libdest "LIBS:compressors/")

            (if (in xpk 0)
                (
                    (set libname "xpkSMPL.library")
                    (InstallLib)
                )
            )

            (if (in xpk 1)
                (
                    (working ("Testing compressors/xpkSQSH.library"))
                    (copylib
                        (prompt ("Do you want to install the \"compressors/xpkSQSH.library\"?"))
                        (help @copylib-help)
                        (source (tackon tempdir "xpkSQSH000.library"))
                        (dest libdest)
                        (newname "xpkSQSH.library")
                        (confirm)
                    )
                )
            )

            (if (in xpk 2)
                (
                    (working ("Testing compressors/xpkSQSH.library"))
                    (copylib
                        (prompt ("Do you want to install the \"compressors/xpkSQSH.library\"?"))
                        (help @copylib-help)
                        (source (tackon tempdir "xpkSQSH020.library"))
                        (dest libdest)
                        (newname "xpkSQSH.library")
                        (confirm)
                    )
                )
            )
        (DeleteAll)
        )
    )
    (complete 55)


    (if bonusflag
        (
            (set bonusdir (tackon @default-dest "Bonus"))
            (makedir bonusdir)
            (working "Unpacking Bonus archive....")
            (run ("\"%s\" -fqw=%s x Files/Bonus.lha >NIL:" lhex tempdir))

            (if (in bonusflag 0)
                (
                    (copyfiles
                        (source (tackon tempdir "FSS2APML"))
                        (dest bonusdir)
                    )
                )
            )

            (if (in bonusflag 1)
                (
                    (copyfiles
                        (source (tackon tempdir "FSSOptimizer"))
                        (dest bonusdir)
                    )
                )
            )
        (DeleteAll)
        )
    )
    (complete 64)


    (if arexx
        (
            (set arexxdir (tackon @default-dest "ARexx"))
            (makedir arexxdir)
            (working "Unpacking ARexx archive....")
            (run ("\"%s\" -fqw=%s x Files/ARexx.lha >NIL:" lhex arexxdir))
        )
    )
    (complete 73)


    (if doc
        (
            (set docdir (tackon @default-dest "Docs"))
            (MakeDocDir)
            (working "Unpacking Docs archive....")
            (run ("\"%s\" -fqw=%s x Files/Docs.lha >NIL:" lhex tempdir))

            (if (in docflag 0)
                (
                    (copyfiles
                        (source (tackon tempdir "Bonus.doc"))
                        (dest docdir)
                        (infos)
                    )
                )
            )

            (if (in docflag 1)
                (
                    (copyfiles
                        (source (tackon tempdir "MissingModules.txt"))
                        (dest docdir)
                        (infos)
                    )
                )
            )

            (if (in docflag 2)
                (
                    (copyfiles
                        (source (tackon tempdir "PlaySid.doc"))
                        (dest docdir)
                        (infos)
                    )
                )
            )

            (if (in docflag 3)
                (
                    (copyfiles
                        (source (tackon tempdir "SMPL.doc"))
                        (dest docdir)
                        (infos)
                    )
                )
            )

            (if (in docflag 4)
                (
                    (copyfiles
                        (source (tackon tempdir "SQSH.doc"))
                        (dest docdir)
                        (infos)
                    )
                )
            )

            (if (in docflag 5)
                (
                    (copyfiles
                        (source (tackon tempdir "Unpack.doc"))
                        (dest docdir)
                        (infos)
                    )
                )
            )

            (if (in docflag 6)
                (
                    (copyfiles
                        (source (tackon sdir "HDInstall"))
                        (dest @default-dest)
                        (infos)
                    )
                )
            )
        (DeleteAll)
        )
    )
    (complete 82)


    (if developer
        (
            (set devdir (tackon @default-dest "Developer"))
            (makedir devdir)
            (working "Unpacking Developer archive....")
            (run ("\"%s\" -fqw=%s x Files/Developer.lha >NIL:" lhex devdir))
        )
    )
    (complete 91)

; Fix the configuration files

    (set flag 0)
    (if (exists "ENVARC:APlayer/")
        (
            (makedir "ENVARC:APlayer/Players")
            (if (exists "ENVARC:APlayer/IFF-8SVX.cfg")
                (
                    (copyfiles
                        (source "ENVARC:APlayer/IFF-8SVX.cfg")
                        (dest "ENVARC:APlayer/Players/")
                    )
                    (delete "ENVARC:APlayer/IFF-8SVX.cfg")
                    (set flag 1)
                )
            )

            (if (exists "ENVARC:APlayer/RIFF-WAVE.cfg")
                (
                    (copyfiles
                        (source "ENVARC:APlayer/RIFF-WAVE.cfg")
                        (dest "ENVARC:APlayer/Players/")
                    )
                    (delete "ENVARC:APlayer/RIFF-WAVE.cfg")
                    (set flag 1)
                )
            )

            (if (exists "ENVARC:APlayer/Protracker.cfg")
                (
                    (copyfiles
                        (source "ENVARC:APlayer/Protracker.cfg")
                        (dest "ENVARC:APlayer/Players/")
                    )
                    (delete "ENVARC:APlayer/Protracker.cfg")
                    (set flag 1)
                )
            )
        )
    )
    (complete 100)
    (delete deldir)

    (if flag
        (message "You have to reset your computer before using APlayer.")
    )
)

;--------------------------------------------------------------------------
; ** Remove Procedure

(procedure Remove
    (if (askbool
            (prompt "This procedure will remove all files associated to "
                    "the APlayer program. This means the program, docs, "
                    "preference files and all extern players.\n\n"
                    "Are you sure you want to continue?")
            (help "")
        )

        (
            (set @default-dest
                (askdir
                    (prompt "Select where the \"APlayer\" drawer are "
                            "stored.")
                    (help @askdir-help)
                    (default @default-dest)
                )
            )

            (working "Deleting the \"APlayer\" drawer...")
            (set ddir (tackon @default-dest "APlayer"))

            (set deldir (tackon ddir "ARexx"))
            (DeleteAll)

            (set deldir (tackon ddir "Bonus"))
            (DeleteAll)

            (set deldir (tackon ddir "Docs"))
            (DeleteAll)

            (set deldir (tackon ddir "Developer/Examples"))
            (DeleteAll)
            (set deldir (tackon ddir "Developer/Include3.0/Own"))
            (DeleteAll)
            (set deldir (tackon ddir "Developer/Include3.0"))
            (DeleteAll)
            (set deldir (tackon ddir "Developer"))
            (DeleteAll)

            (set deldir ddir)
            (DeleteAll)

            (delete ddir)
            (delete (tackon @default-dest "APlayer.info"))

            (delete "S:APlayer.FSS")
            (complete 33)


            (working "Deleting preference files...")
            (set ddir "ENVARC:APlayer")

            (set deldir (tackon ddir "Players"))
            (DeleteAll)
            (set deldir ddir)
            (DeleteAll)
            (delete "ENVARC:APlayer")
            (complete 67)

            (working "Deleting extern players...")
            (set deldir "LIBS:APlayer")
            (DeleteAll)
            (delete "LIBS:APlayer")
            (complete 100)
        )
    )
)

;--------------------------------------------------------------------------
; ** Main Stript

(complete 0)
(set sdir (pathonly @icon))

(if (< (/ (getversion) 65536) 37)
    (abort "You must have Kickstart 2.0 or greater to use this installation"
           " utility and to run \"Accessible Player\".")
)

(message "This installer script will help you to install/remove "
         "\"Accessible Player\" to/from your hard disk.\n"
         "If you don't own one, abort immediately.")

(welcome)


; ** Ask to Install Or Remove

(set askflag (askbool
                (prompt "Do you want to install or remove "
                        "\"Accessible Player\"?")
                (help "")
                (choices "Install" "Remove")
             )
)

(if askflag
    (Install)                       ;Start Install Procedure
    (Remove)                        ;Start Remove Procedure
)
