;**************************************************************************
;*                                                                        *
;*                 Installer Script For Accessible Player                 *
;*                                                                        *
;*                             Update 9/6-1997                            *
;*                                                                        *
;**************************************************************************

;--------------------------------------------------------------------------
; 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 DeleteAll
    (if (exists deldir)
        (foreach deldir "#?"
            (delete (tackon deldir @each-name)
                (optional force)
            )
        )
    )
)

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

(procedure Install
    (message "This version of APlayer is shareware. "
             "This is a non-crippled version, but you can still "
             "register if you want to. "
             "On how to register, read the guide.\n\n"
             "If you still want to install press proceed else abort."
    )

    (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 install APlayer? A drawer called "
                    "APlayer will be created.")
            (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"
                "Commercial Picture"
            )
        )
    )

    (set big
        (askbool
            (prompt "Do you want to install all players, noteplayers and "
                    "agents? If you select yes, a default player config "
                    "file will be installed, except if you already have "
                    "a config file installed. Note that all agents will "
                    "be active, so if you don't want them to be active, "
                    "you have to disable them by yourself after the "
                    "installation.")
            (help @askbool-help)
            (choices "Yes" "No")
        )
    )

    (if big
        (
            (set play 1)
            (set playflag1 -1)
            (set playflag2 -1)
            (set playflag3 -1)
            (set playflag4 -1)
            (set playflag5 -1)
            (set playflag6 -1)
            (set playflag7 -1)

            (set noteplay 1)
            (set noteplayflag1 -1)

            (set agentflag 1)
            (set agentflag1 -1)
            (set multiflag1 -1)
        )
        (                               ; else statement
            (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)
            (set playflag4 0)
            (set playflag5 0)
            (set playflag6 0)
            (set playflag7 0)
            (if play
                (
                    (set playflag1
                        (askoptions
                            (prompt "Which external players do you want to install in "
                                    "your \"LIBS:APlayer\" drawer?")
                            (help @askoptions-help)
                            (choices
                                "Activision Pro"
                                "Art of Noise"
                                "Ben Daglish"
                                "DeliCustom"
                                "Delta 1.0"
                                "Delta 2.0"
                                "Digi Booster"
                                "Digital Mugician"
                            )
                        )
                    )

                    (set playflag2
                        (askoptions
                            (prompt "Which external players do you want to install in "
                                    "your \"LIBS:APlayer\" drawer?")
                            (help @askoptions-help)
                            (choices
                                "DSS"
                                "FastTracker"
                                "FastTracker 2.0"
                                "Fred"
                                "Future Composer 1.0-1.3"
                                "Future Composer 1.4"
                                "Hippel"
                                "IFF-8SVX"
                            )
                        )
                    )

                    (set playflag3
                        (askoptions
                            (prompt "Which external players do you want to install in "
                                    "your \"LIBS:APlayer\" drawer?")
                            (help @askoptions-help)
                            (choices
                                "IFF-AIFF"
                                "IFF-SMUS"
                                "ImpulseTracker"
                                "In Stereo 2.0"
                                "JamCracker"
                                "J.C. Brooke"
                                "Maniacs of Noise"
                                "Mark Cooksey"
                            )
                        )
                    )

                    (set playflag4
                        (askoptions
                            (prompt "Which external players do you want to install in "
                                    "your \"LIBS:APlayer\" drawer?")
                            (help @askoptions-help)
                            (choices
                                "Mark II"
                                "MultiTracker"
                                "Music Assembler"
								"MusicLine Editor"
                                "Noise Packer 2.0"
                                "Noise Packer 3.0"
                                "OctaMed"
                                "OctaMed Sound Studio"
                            )
                        )
                    )

                    (set playflag5
                        (askoptions
                            (prompt "Which external players do you want to install in "
                                    "your \"LIBS:APlayer\" drawer?")
                            (help @askoptions-help)
                            (choices
                                "Oktalyzer"
                                "Puma Tracker"
                                "Quadra Composer"
                                "RIFF-WAVE"
                                "Ron Klaren"
                                "ScreamTracker 3.0"
                                "SID"
                                "SidMon 1.0"
                            )
                        )
                    )

                    (set playflag6
                        (askoptions
                            (prompt "Which external players do you want to install in "
                                    "your \"LIBS:APlayer\" drawer?")
                            (help @askoptions-help)
                            (choices
                                "SidMon 2.0"
                                "Sound Factory"
                                "Sound FX 1.3"
                                "Sound FX 2.0"
                                "Sound Monitor 2.0"
                                "StarTrekker 4"
                                "StarTrekker 4AM"
                                "Syntracker"
                            )
                        )
                    )

                    (set playflag7
                        (askoptions
                            (prompt "Which external players do you want to install in "
                                    "your \"LIBS:APlayer\" drawer?")
                            (help @askoptions-help)
                            (choices
                                "TFMX 1.5"
                                "THX Sound System"
                                "Tronic Tracker"
                                "Whittaker"
                            )
                        )
                    )
                )
            )


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

            (set noteplayflag1 0)
            (if noteplay
                (
                    (set noteplayflag1
                        (askoptions
                            (prompt "Which external NotePlayers do you want to install in "
                                    "your \"LIBS:APlayer/NotePlayers\" drawer?")
                            (help @askoptions-help)
                            (choices
                                "14 Bit Stereo - 2 Voices"
                                "14 Bit Stereo - 32 Voices"
                                "AHI - 64 Voices"
                                "FastMem - 4 Voices"
                                "Mono - 32 Voices"
                                "Real Surround - 32 Voices"
                                "Stereo - 32 Voices"
                                "Surround - 32 Voices"
                            )
                        )
                    )
                )
            )


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

            (set agentflag1 0)
            (if agent
                (
                    (set agentflag1
                        (askoptions
                            (prompt "Which external Agents do you want to install in "
                                    "your \"LIBS:APlayer/Agents\" drawer?")
                            (help @askoptions-help)
                            (choices
                                "Favourite Song System"
                                "Multi - Sample Saver"
                                "Bar - Scope"
                                "FreqAnalyzer - Scope"
                                "RGBBox - Scope"
                                "SpinSquare - Scope"
                            )
                        )
                    )

                    (set multiflag1 0)
                    (if (in agentflag1 1)
                        (
                            (set multiflag1
                                (askoptions
                                    (prompt "You have selected the Multi-SampleSaver agent. "
                                            "Which sample modules do you want to install?")
                                    (help @askoptions-help)
                                    (choices
                                        "IFF-8SVX"
                                        "IFF-AIFF"
                                        "Raw"
                                        "RIFF-WAVE"
                                        "Worms"
                                    )
                                )
                            )
                        )
                    )
                )
            )
        )
    )


    (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"
                  "MLine.library: Mline.library is used for playing "
                  "musicline-modules.\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"
                  "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
                "MLine.library"
                "PlaySID.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 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
                    "APlayer.guide"
                    "MissingModules.txt"
                    "PlaySid.doc"
                    "SMPL.doc"
                    "SQSH.doc"
                    "Unpack.guide"
                    "RegistrationForm"
                    "Installer Script"
                )
            )
        )
    )


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


    (set ahi
        (askbool
            (prompt "Do you want to install AHI?\n\n"
                    "The AHI package is created by Martin Blom "
                    "and is an audio driver for sound cards and "
                    "the standard Amiga hardware. APlayer has a NotePlayer "
                    "in this archive which use AHI.\n\n"
                    "Notice that the AHI requires 68020+.")
            (help "If you select yes, you can select between all the "
                  "different drivers.")
        )
    )

    (set ahiflag 0)
    (if ahi
        (
            (set ahic
                (askdir
                    (prompt "AHI needs a CLI command to run. Where do you "
                            "want to install it?")
                    (help @askdir-help)
                    (default "C:")
                )
            )

            (set ahiflag
                (askoptions
                    (prompt "Which AHI drivers do you want to install in "
                                    "your \"DEVS:AudioModes\" and "
                                    "your \"DEVS:AHI\" drawers?")
                    (help @askoptions-help)
                    (choices
                        "Delfina"
                        "File Save"
                        "Paula"
                        "Prelude"
                        "Toccata"
                        "Wavetools"
                    )
                )
            )
        )
    )


; ** Begin to copy the files

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

    (makedir tempdir)
    (makedir @default-dest)

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

    (set oldversion 0)
    (if (exists (tackon @default-dest "APlayer"))
        (
            (set ver (getversion (tackon @default-dest "APlayer")))
            (set oldversion (/ ver 65536))
        )
    )

    (if fileflag
        (
            (working "Unpacking program archive....")
            (run ("\"%s\" -fqw=%s x Files/Program.lha >NIL:" lhex tempdir))

            (if (in fileflag 0)                     ;APlayer File
                (
                    (set datadir (tackon @default-dest "Data"))
                    (makedir datadir)
                    (copyfiles
                        (source (tackon tempdir "APlayer"))
                        (dest @default-dest)
                        (infos)
                    )

                    (copyfiles
                        (source (tackon tempdir "Data/Help.Nodes"))
                        (dest (tackon @default-dest "Data/"))
                    )

                    (copyfiles
                        (source (tackon tempdir "Data/Tips.dat"))
                        (dest (tackon @default-dest "Data/"))
                    )

                    (copyfiles
                        (source (tackon tempdir "Data/Why.dat"))
                        (dest (tackon @default-dest "Data/"))
                    )
                )
            )

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

            (set deldir (tackon tempdir "Data"))
            (DeleteAll)
            (set deldir tempdir)
            (DeleteAll)
        )
    )
    (complete 10)


    (if (or (or (or (or (or (or playflag1 playflag2) playflag3) playflag4) playflag5) playflag6) playflag7)
        (
            (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 "apActivisionPro.library")
                            (InstallLib)
                        )
                    )

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

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

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

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

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

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

                    (if (in playflag1 7)
                        (
                            (set libname "apDigitalMugician.library")
                            (InstallLib)
                        )
                    )
                )
            )
            (complete 11)

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

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

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

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

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

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

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

                    (if (in playflag2 7)
                        (
                            (set libname "apIFF-8SVX.library")
                            (InstallLib)
                        )
                    )
                )
            )
            (complete 13)

            (if playflag3
                (
                    (if (in playflag3 0)
                        (
                            (set libname "apIFF-AIFF.library")
                            (InstallLib)
                        )
                    )

                    (if (in playflag3 1)
                        (
                            (set libname "apIFF-SMUS.library")
                            (InstallLib)
                        )
                    )

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

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

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

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

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

                    (if (in playflag3 7)
                        (
                            (set libname "apMarkCooksey.library")
                            (InstallLib)
                        )
                    )
                )
            )
            (complete 14)

            (if playflag4
                (
                    (if (in playflag4 0)
                        (
                            (set libname "apMarkII.library")
                            (InstallLib)
                        )
                    )

                    (if (in playflag4 1)
                        (
                            (set libname "apMultiTracker.library")
                            (InstallLib)
                        )
                    )

                    (if (in playflag4 2)
                        (
                            (set libname "apMusicAss.library")
                            (InstallLib)
                        )
                    )

                    (if (in playflag4 3)
                        (
                            (set libname "apMLine.library")
                            (InstallLib)
                        )
                    )

                    (if (in playflag4 4)
                        (
                            (set libname "apNoisePacker20.library")
                            (InstallLib)
                        )
                    )

                    (if (in playflag4 5)
                        (
                            (set libname "apNoisePacker30.library")
                            (InstallLib)
                        )
                    )

                    (if (in playflag4 6)
                        (
                            (set libname "apOctaMed.library")
                            (InstallLib)
                        )
                    )

                    (if (in playflag4 7)
                        (
                            (set libname "apOctaMedSS.library")
                            (InstallLib)
                        )
                    )
                )
            )
            (complete 16)

            (if playflag5
                (
                    (if (in playflag5 0)
                        (
                            (set libname "apOktalyzer.library")
                            (InstallLib)
                        )
                    )

                    (if (in playflag5 1)
                        (
                            (set libname "apPumaTracker.library")
                            (InstallLib)
                        )
                    )

                    (if (in playflag5 2)
                        (
                            (set libname "apQuadraComposer.library")
                            (InstallLib)
                        )
                    )

                    (if (in playflag5 3)
                        (
                            (set libname "apRIFF-WAVE.library")
                            (InstallLib)
                        )
                    )

                    (if (in playflag5 4)
                        (
                            (set libname "apRonKlaren.library")
                            (InstallLib)
                        )
                    )

                    (if (in playflag5 5)
                        (
                            (set libname "apScreamTracker30.library")
                            (InstallLib)
                        )
                    )

                    (if (in playflag5 6)
                        (
                            (set libname "apSID.library")
                            (InstallLib)
                        )
                    )

                    (if (in playflag5 7)
                        (
                            (set libname "apSidMon10.library")
                            (InstallLib)
                        )
                    )
                )
            )
            (complete 17)

            (if playflag6
                (
                    (if (in playflag6 0)
                        (
                            (set libname "apSidMon20.library")
                            (InstallLib)
                        )
                    )

                    (if (in playflag6 1)
                        (
                            (set libname "apSoundFactory.library")
                            (InstallLib)
                        )
                    )

                    (if (in playflag6 2)
                        (
                            (set libname "apSoundFX13.library")
                            (InstallLib)
                        )
                    )

                    (if (in playflag6 3)
                        (
                            (set libname "apSoundFX20.library")
                            (InstallLib)
                        )
                    )

                    (if (in playflag6 4)
                        (
                            (set libname "apSoundMon20.library")
                            (InstallLib)
                        )
                    )

                    (if (in playflag6 5)
                        (
                            (set libname "apStarTrekker4.library")
                            (InstallLib)
                        )
                    )

                    (if (in playflag6 6)
                        (
                            (set libname "apStarTrekker4AM.library")
                            (InstallLib)
                        )
                    )

                    (if (in playflag6 7)
                        (
                            (set libname "apSyntracker.library")
                            (InstallLib)
                        )
                    )
                )
            )
            (complete 19)

            (if playflag7
                (
                    (if (in playflag7 0)
                        (
                            (set libname "apTFMX_15.library")
                            (InstallLib)
                        )
                    )

                    (if (in playflag7 1)
                        (
                            (set libname "apTHX.library")
                            (InstallLib)
                        )
                    )

                    (if (in playflag7 2)
                        (
                            (set libname "apTronicTracker.library")
                            (InstallLib)
                        )
                    )

                    (if (in playflag7 3)
                        (
                            (set libname "apWhittaker.library")
                            (InstallLib)
                        )
                    )
                )
            )
        (DeleteAll)
        )
    )
    (complete 20)


    (if noteplayflag1
        (
            (makedir "LIBS:APlayer/NotePlayers")
            (working "Unpacking NotePlayer archive....")
            (run ("\"%s\" -fqw=%s x Files/NotePlayers.lha >NIL:" lhex tempdir))
            (set libdest "LIBS:APlayer/NotePlayers")

            (if (in noteplayflag1 0)
                (
                    (set libname "an14BitStereo-2Voices.library")
                    (InstallLib)
                )
            )

            (if (in noteplayflag1 1)
                (
                    (set libname "an14BitStereo-32Voices.library")
                    (InstallLib)
                )
            )

            (if (in noteplayflag1 2)
                (
                    (set libname "anAHI-64Voices.library")
                    (InstallLib)
                )
            )

            (if (in noteplayflag1 3)
                (
                    (set libname "anFastMem-4Voices.library")
                    (InstallLib)
                )
            )

            (if (in noteplayflag1 4)
                (
                    (set libname "anMono-32Voices.library")
                    (InstallLib)
                )
            )

            (if (in noteplayflag1 5)
                (
                    (set libname "anReSurround-32Voices.library")
                    (InstallLib)
                )
            )

            (if (in noteplayflag1 6)
                (
                    (set libname "anStereo-32Voices.library")
                    (InstallLib)
                )
            )

            (if (in noteplayflag1 7)
                (
                    (set libname "anSurround-32Voices.library")
                    (InstallLib)
                )
            )
        (DeleteAll)
        )
    )
    (complete 30)


    (if agentflag1
        (
            (makedir "LIBS:APlayer/Agents")
            (working "Unpacking Agent archive....")
            (run ("\"%s\" -fqw=%s x Files/Agents.lha >NIL:" lhex tempdir))
            (set libdest "LIBS:APlayer/Agents")

            (if (in agentflag1 0)
                (
                    (set libname "aaFSS.library")
                    (InstallLib)
                )
            )

            (if (in agentflag1 1)
                (
                    (set libname "aaMulti-SampleSaver.library")
                    (InstallLib)
                )
            )

            (if (in agentflag1 2)
                (
                    (set libname "aaBar-Scope.library")
                    (InstallLib)
                )
            )

            (if (in agentflag1 3)
                (
                    (set libname "aaFreqAnalyzer-Scope.library")
                    (InstallLib)
                )
            )

            (if (in agentflag1 4)
                (
                    (set libname "aaRGBBox-Scope.library")
                    (InstallLib)
                )
            )

            (if (in agentflag1 5)
                (
                    (set libname "aaSpinSquare-Scope.library")
                    (InstallLib)
                )
            )
        (DeleteAll)
        )
    )
    (complete 35)

    (if multiflag1
        (
            (makedir "LIBS:APlayer/Agents/MSSModules")
            (working "Unpacking Multi Modules archive....")
            (run ("\"%s\" -fqw=%s x Files/MultiMods.lha >NIL:" lhex tempdir))
            (set libdest "LIBS:APlayer/Agents/MSSModules")

            (if (in multiflag1 0)
                (
                    (set libname "mmIFF-8SVX.library")
                    (InstallLib)
                )
            )

            (if (in multiflag1 1)
                (
                    (set libname "mmIFF-AIFF.library")
                    (InstallLib)
                )
            )

            (if (in multiflag1 2)
                (
                    (set libname "mmRaw.library")
                    (InstallLib)
                )
            )

            (if (in multiflag1 3)
                (
                    (set libname "mmRIFF-WAVE.library")
                    (InstallLib)
                )
            )

            (if (in multiflag1 4)
                (
                    (set libname "mmWorms.library")
                    (InstallLib)
                )
            )
        (DeleteAll)
        )
    )
    (complete 40)


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

            (if (in libs 1)
                (
                    (set libname "playsid.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 50)


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


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


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

            (if (in docflag 0)
                (
                    (copyfiles
                        (source (tackon tempdir "APlayer.guide"))
                        (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)
                (
                    (delete (tackon docdir "Unpack.doc"))
                    (delete (tackon docdir "Unpack.doc.info"))
                    (copyfiles
                        (source (tackon tempdir "Unpacker.guide"))
                        (dest docdir)
                        (infos)
                    )
                )
            )

            (if (in docflag 6)
                (
                    (copyfiles
                        (source (tackon tempdir "RegistrationForm"))
                        (dest docdir)
                        (infos)
                    )
                )
            )

            (if (in docflag 7)
                (
                    (copyfiles
                        (source (tackon sdir "HDInstall"))
                        (dest @default-dest)
                        (infos)
                    )
                )
            )
        (delete (tackon docdir "Bonus.doc"))
        (delete (tackon docdir "Bonus.doc.info"))
        (DeleteAll)
        )
    )
    (complete 80)


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


    (if ahi
        (
            (working "Unpacking AHI archive....")
            (run ("\"%s\" -fqw=%s x Files/AHI.lha >NIL:" lhex tempdir))

            (delete (tackon docdir "ahi.readme"))

            (if doc
                (
                    (copyfiles
                        (source (tackon tempdir "ahiusr.readme"))
                        (dest docdir)
                    )
                )
            )

            (copyfiles
                (source (tackon tempdir "C/AddAudioModes"))
                (dest ahic)
            )

            (set libdest "DEVS:")
            (set libname "Devs/ahi.device")
            (InstallLib)

            (makedir "DEVS:AHI")
            (makedir "DEVS:AudioModes")

            (if (in ahiflag 0)
                (
                    (set libdest "DEVS:AHI")
                    (set libname "Devs/AHI/delfina.audio")
                    (InstallLib)

                    (copyfiles
                        (source (tackon tempdir "Devs/AudioModes/DELFINA"))
                        (dest "DEVS:AudioModes")
                    )
                )
            )

            (if (in ahiflag 1)
                (
                    (set libdest "DEVS:AHI")
                    (set libname "Devs/AHI/filesave.audio")
                    (InstallLib)

                    (copyfiles
                        (source (tackon tempdir "Devs/AudioModes/FILESAVE"))
                        (dest "DEVS:AudioModes")
                    )
                )
            )

            (if (in ahiflag 2)
                (
                    (set libdest "DEVS:AHI")
                    (set libname "Devs/AHI/paula.audio")
                    (InstallLib)

                    (copyfiles
                        (source (tackon tempdir "Devs/AudioModes/PAULA"))
                        (dest "DEVS:AudioModes")
                    )
                )
            )

            (if (in ahiflag 3)
                (
                    (set libdest "DEVS:AHI")
                    (set libname "Devs/AHI/prelude.audio")
                    (InstallLib)

                    (copyfiles
                        (source (tackon tempdir "Devs/AudioModes/PRELUDE"))
                        (dest "DEVS:AudioModes")
                    )
                )
            )

            (if (in ahiflag 4)
                (
                    (set libdest "DEVS:AHI")
                    (set libname "Devs/AHI/toccata.audio")
                    (InstallLib)

                    (copyfiles
                        (source (tackon tempdir "Devs/AudioModes/TOCCATA"))
                        (dest "DEVS:AudioModes")
                    )

                    (message "The Toccata driver doesn't work with the "
                             "toccata.library version 9.10. This is just "
                             "a notice.")

                    (set libdest "LIBS:")
                    (set libname "toccata.library")
                    (InstallLib)
                )
            )

            (if (in ahiflag 5)
                (
                    (set libdest "DEVS:AHI")
                    (set libname "Devs/AHI/wavetools.audio")
                    (InstallLib)

                    (copyfiles
                        (source (tackon tempdir "Devs/AudioModes/WAVETOOLS"))
                        (dest "DEVS:AudioModes")
                    )
                )
            )

            (set deldir (tackon tempdir "C"))
            (DeleteAll)
            (set deldir (tackon tempdir "Devs/AHI"))
            (DeleteAll)
            (set deldir (tackon tempdir "Devs/AudioModes"))
            (DeleteAll)
            (set deldir (tackon tempdir "Devs"))
            (DeleteAll)
            (set deldir tempdir)
            (DeleteAll)
        )
    )
    (complete 90)

; Delete Bonus Files

    (set deldir (tackon @default-dest "Bonus"))
    (DeleteAll)
    (delete deldir)

; Check for obsolete players

    (set obplay "")
    (if (exists "LIBS:APlayer/apMED.library")
        (
            (set obplay "MED\n")
            (delete "LIBS:APlayer/apMED.library")
        )
    )

    (if (exists "LIBS:APlayer/apTakeTracker.library")
        (
            (set obplay (cat obplay "TakeTracker\n"))
            (delete "LIBS:APlayer/apTakeTracker.library")
        )
    )

    (if (not (= obplay ""))
        (message "Below is a list of some players which are obsolete. "
                 "They are deleted from your LIBS:APlayer/ drawer. "
                 "Be sure to delete them from your player config.\n\n"
                 obplay)
    )


; Fix the configuration files

    (makedir "ENVARC:APlayer")
    (makedir "ENVARC:APlayer/Players")
    (makedir "ENVARC:APlayer/NotePlayers")

    ; From a very early version, the config where in the "root".

    (delete "ENVARC:APlayer/IFF-8SVX.cfg")
    (delete "ENVARC:APlayer/IFF-AIFF.cfg")
    (delete "ENVARC:APlayer/Protracker.cfg")
    (delete "ENVARC:APlayer/Players/Protracker.cfg")


    ; From Version 2, we have changed the config data, so we have
    ; to delete old config files.

    (if (< oldversion 2)
        (
            (delete "ENVARC:APlayer/Players/IFF-8SVX.cfg")
            (delete "ENVARC:APlayer/Players/IFF-AIFF.cfg")
            (delete "ENVARC:APlayer/Players/RIFF-WAVE.cfg")
        )
    )


    ; Delete files that are obsolete.

    (delete "ENVARC:APlayer/NotePlayers/FastMem4.cfg")


    ; Copy default player config file.

    (if big
        (
            (if (not (exists "ENVARC:APlayer/APlayer.libs"))
                (
                    (copyfiles
                        (source "Files/!APlayer.libs")
                        (dest "ENVARC:APlayer/")
                    )
                    (rename "ENVARC:APlayer/!APlayer.libs" "ENVARC:APlayer/APlayer.libs")
                )
            )
        )
    )


    ; Do we have to convert the config file?

    (if (< oldversion 2)
        (
            (if (exists "ENVARC:APlayer/APlayer.prefs")
                (
                    (if (askbool
                            (prompt "Do you want to convert your old preference"
                                    "file to the new format?")
                            (help "From this version of APlayer, the file format"
                                  " of the preference file is changed. Therefore"
                                  " you have to convert your preference file to"
                                  " the new format if you want to use your old"
                                  " settings.")
                        )
                        (
                            (run ("\"%s\" >ENV:convtxt" (tackon sdir "C/PrefsConvert")))

                            (if (not (exists "ENVARC:APlayer/APlayer2.0.prefs"))
                                (
                                    (message "Something went wrong when converting!!!\n\n"
                                             ("%s" (getenv "convtxt")))
                                )
                                (
                                    (if (askbool
                                            (prompt "You now have a new preference file."
                                                    " Do you want to delete your"
                                                    " old preference files and rename the new "
                                                    "one?")
                                            (help @askbool-help)
                                        )
                                        (
                                            (delete "ENVARC:APlayer/APlayer.prefs")
                                            (delete "ENVARC:APlayer/APlayer.win")
                                            (delete "ENVARC:APlayer/APlayer.arexx")
                                            (rename "ENVARC:APlayer/APlayer2.0.prefs" "ENVARC:APlayer/APlayer.prefs")
                                            (rename "ENVARC:APlayer/APlayer2.0.win" "ENVARC:APlayer/APlayer.win")
                                        )
                                    )
                                )
                            )
                        )
                    )
                    (delete "ENV:convtxt")
                )
            )
        )
    )
	(
	    (run ("\"%s\" >ENV:convtxt" (tackon sdir "C/PrefFix")))
	)

    (complete 100)
    (delete tempdir)

    (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 @askbool-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 "Data"))
            (DeleteAll)

            (set deldir (tackon ddir "ARexx/IR_Scripts"))
            (DeleteAll)
            (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/Rexxtools/Doc"))
            (DeleteAll)
            (set deldir (tackon ddir "Developer/Rexxtools/FD"))
            (DeleteAll)
            (set deldir (tackon ddir "Developer/Rexxtools/Include/CLib"))
            (DeleteAll)
            (set deldir (tackon ddir "Developer/Rexxtools/Include/Libraries"))
            (DeleteAll)
            (set deldir (tackon ddir "Developer/Rexxtools/Include/Pragmas"))
            (DeleteAll)
            (set deldir (tackon ddir "Developer/Rexxtools/Include/Proto"))
            (DeleteAll)
            (set deldir (tackon ddir "Developer/Rexxtools/Include"))
            (DeleteAll)
            (set deldir (tackon ddir "Developer/Rexxtools/Libs"))
            (DeleteAll)
            (set deldir (tackon ddir "Developer/Rexxtools"))
            (DeleteAll)
            (set deldir (tackon ddir "Developer"))
            (DeleteAll)

            (set deldir ddir)
            (DeleteAll)

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

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


            (working "Deleting preference files...")
            (set ddir "ENVARC:APlayer")
            (set deldir (tackon ddir "Players"))
            (DeleteAll)
            (set deldir (tackon ddir "NotePlayers"))
            (DeleteAll)
            (set deldir (tackon ddir "Agents"))
            (DeleteAll)
            (set deldir ddir)
            (DeleteAll)
            (delete "ENVARC:APlayer")
            (complete 40)

            (working "Deleting external Agents...")
            (set deldir "LIBS:APlayer/Agents/MSSModules")
            (DeleteAll)
            (set deldir "LIBS:APlayer/Agents")
            (DeleteAll)
            (delete "LIBS:APlayer/Agents")
            (complete 60)

            (working "Deleting external NotePlayers...")
            (set deldir "LIBS:APlayer/NotePlayers")
            (DeleteAll)
            (delete "LIBS:APlayer/NotePlayers")
            (complete 80)

            (working "Deleting external 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
)
