;**********************************
;
;   Installer for LotsaBlankers
;       v0.07
;
;**********************************

;************
; PROCEDURES
;************

(procedure P_USERQUESTIONS
(select @user-level
    ( ; NOVICE-mode
        (set @default-dest "Work:")
    )
    ( ; ADVANCED-mode
        (set @default-dest (askdir (disk)
            (prompt ("Where do you want to install %s\n" @app-name)
                  "It should be installed where your other Garshneblanker-modules are.")
            (help ("You should select where you want to install %s. This should be the directory where your other GarshneBlanker modules are located.\n\n" @app-name)
                  ("No directory will be created.\n\n" @app-name)
                  @askdir-help)
            (default @default-dest)
            )
        )
        (set #docicon 1)
        (set #docdir (askdir (disk)
            (prompt "Where do you want to install the documentation?\nNo drawer will be created.")
            (help   "You should select where you would like to install the documentation.\n"
                    "It is a file called LotsaBlankers.guide, that contains necessary information for using the blankers, as well as information on our other products.\n\n"
                    @askdir-help)
            (default #docdir))
        )
        (if (askbool
                (prompt "Would you like to copy the Garshnelib.library replacement with better AGA support.\n\nIf your original version is newer than the one replaced with this, it won't be overwritten. Older ones will be overwritten.")
                (help   "This is a replacement for Garshnelib.library, with a little better AGA support - namely that the function copying the frontmost screen supports AGA now.\n\nIf you have an AGA screen you would want to copy this one!")
                (default 1)
            )
            (set #libdir "LIBS:")
            (set #libdir 0)
        )
        (set #nofpu (database "fpu" "NOFPU"))

    )
    ( ; EXPERT-mode
        (set @default-dest (askdir (disk)
            (prompt ("Where do you want to install %s\n" @app-name)
                  "It should be installed where your other Garshneblanker-modules are.")
            (help ("You should select where you want to install %s. This should be the directory where your other GarshneBlanker modules are located.\n\n" @app-name)
                  ("No directory will be created.\n\n" @app-name)
                  @askdir-help)
            (default @default-dest)
            )
        )
        (if (askbool
                (prompt "Would you like to install the documentation?")
                (help   "The documentation contains much useful information on the usage of LotsaBlankers, as well as information on our other products.\n\nNormally you would want to install the documentation.")
                (default 1)
            )
            (
                (set #docdir
                    (askdir (disk)
                        (prompt "Where do you want to install the documentation?\nNo drawer will be created.")
                        (help   "You should select where you would like to install the documentation.\n"
                                "It is a file called LotsaBlankers.guide, that contains necessary information for using the blankers, as well as information on our other products.\n\n")
                        (default #docdir)
                    )
                )
                (set #docicon
                    (askbool
                        (prompt "Would you like to install the icon for the documentation?")
                        (help   "Would you?")
                        (default 1)
                    )
                )
            )
            (set #docdir 0)
        )
        (if (askbool
                (prompt "Would you like to copy the Garshnelib.library replacement with better AGA support.\n\nIf your original version is newer than the one replaced with this, it won't be overwritten. Older ones will be overwritten.")
                (help   "This is a replacement for Garshnelib.library, with a little better AGA support - namely that the function copying the frontmost screen supports AGA now.\n\nIf you have an AGA screen you would want to copy this one!")
                (default 1)
            )
            (set #libdir
                (askdir
                    (prompt "Where do you want to install the Garshnelib.library replacement?\nNormally this is LIBS:")
                    (help   @askdir-help)
                    (default #libdir)
                )
            )
            (set #libdir 0)
        )
        (set #nofpu
            (askbool
                (prompt "There is an FPU and a non-FPU version available of LotsaDistortion.\n\nWhich one should be copied?")
                (help   "The FPU is a special processor unit that calculates floating point numbers (decimal numbers) faster than a normal non-FPU processor."
                        "The Amiga's FPU is either an MC68881 or MC68882, if you have one of these, you have an FPU.\n\n"
                        "The non-FPU version works on all computers, and you should select it if you are in doubt.\n\n"
                        "68040 processors have a built-in FPU.")
                (choices "Non-FPU" "FPU")
                (default 1)
            )
        )
    )
)
(if (> #docdir 0)
    (if (> #docicon 0)
        (set #info ("The documentation will be copied to \"%s\", along with its icon." #docdir))
        (set #info ("The documentation will be copied to \"%s\". No icon will be copied for it." #docdir))
    )
    (set #info "No documentation will be copied")
)
(if (> #libdir 0)
    (set #libinfo ("\n\nThe Garshnelib.library replacement will be copied to \"%s\"" #libdir))
    (set #libinfo "\n\nThe Garshnelib.library replacement won't be copied.")
)
(if (> #nofpu 0)
    (set #fpu "\nThe non-FPU version of LotsaDistortion will be copied.")
    (set #fpu "\nThe FPU version of LotsaDistortion will be copied.")
)

(if (> @user-level 0)
    (askbool
        (prompt "These actions will now be performed:\n\n\n"
            ("The executable will be copied to:\"%s\"\n\n" @default-dest)
            #info
            #libinfo
            #fpu
            "\n\n\nShall I proceed?"
        )
        (help   "You are presented with the choices you made in earlier questions, if you are satisfied with them, click on \"Yes\", and the installation will continue.\n\n"
                "If you wish to alter your choices, click on \"No\"\n\n")
        (default 1)
        (choices "Go ahead" "Alter choices")
    )
(askbool (prompt "Do not run the installer in NOVICE mode!") (help "Sorry if you ever get this requester") (default 1)))
)

;********
;  MAIN
;********

(if (< (/ (getversion) 65536) 37) (abort ("%s requires at least AmigaOS v2.0." @app-name)))

;  Choose where&what to install
; =============================

(set @default-dest "Work:" #docdir @default-dest #libdir "LIBS:")

(if (> @user-level 0) (message ("You will now be asked a few questions about how you want to install %s.\n\n" @app-name)
                                "You will be asked to verify your choices before any actions are taken, so that you can correct any errors made."))
(if (askbool
        (prompt ("To use %s, you must have GarshneBlanker installed.\n\nDo you have GarshneBlanker installed?" @app-name))
        (help   "GarshneBlanker is a screensaver system for AmigaOS, you can find it on Aminet as:\n\n"
                "util/blank/GBlanker#?.lha\n\nWhere #? is the version number and other data.\n\n"
                "If you don't have it installed, you must click on \"No\" here, which will abort the installation."
                )
        (default 1)
    )
    (while (= (P_USERQUESTIONS) 0))
    (abort "You can find GarshneBlanker on Aminet in:\n\n"
           "util/blank/GBlanker#?.lha\n\n"
           "You must install it before you can install LotsaBlankers\n\nError occurred")
)

;  Copy da stuff
; ===============

(copyfiles (source "Blankers/")
           (pattern "#?")
           (dest @default-dest)
)

(delete (tackon @default-dest "LotsaDistortion"))

(if (> #nofpu 0)
    (copyfiles
        (source (tackon @default-dest "LotsaDistortion.FFP"))
        (dest @default-dest)
        (newname "LotsaDistortion")
    )
    (copyfiles
        (source (tackon @default-dest "LotsaDistortion.881"))
        (dest @default-dest)
        (newname "LotsaDistortion")
    )
)

(delete (tackon @default-dest "LotsaDistortion.881"))
(delete (tackon @default-dest "LotsaDistortion.FFP"))

(if (> #docdir 0)
    (copyfiles (source "LotsaBlankers.guide")
               (dest #docdir)
    )
)

(if (> #docicon 0)
    (copyfiles (source "LotsaBlankers.guide.info")
               (dest #docdir)
    )
)

(if (> #libdir 0)
(if (<=
        (getversion (tackon #libdir "Garshnelib.library") (resident)) (getversion "libs/Garshnelib.library" (resident)))
        (if (> #libdir 0)
            (copyfiles
                (source "libs/Garshnelib.library")
                (dest #libdir)
            )
        )
    (message "Your current version of Garshnelib.library is newer than the replacement, it won't be replaced, sorry.")
)
)
