; $VER: Installation script for Convert35Icon 1.3 (11. Marzec 2000)
; © Rafal Mania
; Created with GoldED 6.2

; check if we are running under correct OS

(if (< (/ (getversion) 65536) 40)

    (
        (abort "Incorrect OS version (software requires OS 40 or better )!")
    )
)


; error handling

(onerror

    (if (> @ioerr 0)

        (
            (message

                ("An error has occurred during installation. Please check the log file to understand the error.")
            )
        )
    )

    (exit (quiet))
)

(set sourcePath (expandpath (pathonly @icon)))

(set #installmode

    (askbool

        (prompt "Choose the installation mode:")

        (help (cat "\nYou may here choose if You want install/remove ")
                   " supplied package.\n")

        (choices

            "Install"
            "Uninstall"
        )

        (default 1)
    )
)

(if (= #installmode 1)

    ; normal installation

    (
        (welcome)

        ; --- insert your code below ---


        (set #os31

            (askbool

                (prompt "Do You want OS3.1 version installed?")

                (help (cat "\nThere is a special version of Convert35Icon for OS3.1 "
                       "which doesn't need OS3.5 installed.\n\nInstead "
                       "only icon.library V44+ is needed (not included).\n\n"
                       "The OS3.5 version has more features then OS3.1 version, "
                       "but it NEEDS OS3.5")
                )

                (choices

                    "Yes"
                    "No"
                )

                (default 2)
            )
        )
        (if (= #os31 1)
                                      
            (
              (run
                   (cat
                        ("\"")
                        (tackon sourcepath "gpatch")
                        ("\"")
                        (" \"")
                        (tackon sourcepath "Convert35Icon")
                        ("\"")
                        (" \"")
                        (tackon sourcepath "patches.ptg")
                        ("\" ")
                        "T:Convert35Icon"
                   )

                   (prompt "Now patching the Convert35Icon executable")

                   (help (cat "\nIf You want to use Convert35Icon on OS3.1 machine,"
                              " original Convert35Icon has to be patched." )
                   )

                   (confirm)
              )

              (copyfiles

                  (source (tackon sourcepath "Convert35Icon.info") )

                  (dest "T:")
              )

              (tooltype

                  (prompt "Setting STRIPPALETTEMAPPED tooltype")

                  (dest "T:Convert35Icon" )

                  (settooltype "STRIPPALETTEMAPPED" "")

                  (confirm)

                  (help (cat "\nWhen this tooltype is set, palettemapped icon"
                             " image will be stripped." )
                  )

                  (noposition)
              )

              (copyfiles

                  (prompt "Copying OS3.1 version of Convert35Icon")

                  (source "T:Convert35Icon")

                  (dest (expandpath "C:"))

                  (newname "Convert35Icon")

                  (infos)

                  (confirm)

                  (optional "fail")

                  (help (cat"\nThe patched version of Convert35Icon will be"
                             " copied to specified destination.")
                  )
              )

              (set #iconlib

                  (askfile
                    
                      (prompt "Choose icon.library V44+ to patch")

                      (help (cat"\nAs the OS3.1 version of Convert35Icon needs"
                                " some function from OS3.5 icon.library,"
                                " the original one has to be patched.\n"
                                "Only three versions are supported:\n"
                                "Original OS3.5 distribution (44616 bytes)\n"
                                "BoingBag1 update (44804 bytes)\n"
                                "DirectoryOpus 5.82 update (44808 bytes)")
                      )

                      (default "RAM:")
                  )
              )

              (working "Now patching selected library")

              (run
                   (cat ("\"")
                        (tackon sourcepath "gpatch")
                        ("\" ")
                        ("\"")
                        (cat #iconlib)
                        ("\" ")
                        ("\"")
                        (tackon sourcepath "patches.ptg")
                        ("\" ")
                        "T:ic35.library"
                   )

                   (prompt "The OS3.5 icon.library will be patched now")

                   (help "The patching programm will be started now\n")

                   (confirm)
              )
              
              (copylib

                  (prompt "Now copy the patched icon.library")

                  (source "T:ic35.library")

                  (dest (expandpath "LIBS:"))

                  (confirm)

                  (newname "ic35.library")

                  (optional "fail")

                  (help (cat"\nThe patched icon.library HAS to be"
                            " copied to LIBS: assign as ic35.library."
                        )
                  )
              )


            )

            ; else

            (

             (tooltype

                  (prompt "Now setting STRIPPALETTEMAPPED tooltype")

                  (dest "Convert35Icon")

                  (settooltype "STRIPPALETTEMAPPED" "")

                  (confirm)

                  (help (cat "\nWhen this tooltype is set, palettemapped icon"
                             " image will be stripped.")
                  )

                  (noposition)
             )

             (tooltype

                  (prompt "Now setting KEEPPLAIN tooltype")

                  (dest "Convert35Icon")

                  (settooltype "KEEPPLAIN" "")

                  (confirm)

                  (help (cat "\nWhen this tooltype is set, plain icon"
                             " image will be preserved.")
                  )

                  (noposition)
             )

             (copyfiles

                (prompt "Now copying the OS3.5 version of Convert35Icon")

                (source "Convert35Icon")

                (dest (expandpath "C:"))

                (infos)

                (confirm)

                (optional "fail")

                (help (cat"\nThe OS3.5 version of Convert35Icon will be copied"
                          " to specified destination.")
                )
            )



            )
        )



        ; --- end of your code ---

        (exit)
    )

    ; uninstall application

    (
        (welcome)
        ; --- insert your code below ---

        (delete "LIBS:ic35.library"

             (prompt "Deleting ic35.library")
        
             (confirm)
             
             (optional "force")
        
             (help "The patched icon.library will be removed.")
        )

        (delete "C:Convert35Icon"

             (prompt "Deleting Convert35Icon")

             (confirm)

             (optional "force")

             (help "The Convert35Icon executable will be removed.")
        )

        ; -- end of your code ---

        (message "Uninstallation completed.")

        (exit (quiet))
    )
)

