; Installer script for GetPayed
;

(if (< (getversion) 2555865 )
    (abort "You need at least Kickstart V39 (OS3.0) to use GetPayed")
)

; * Get place to install to *
(complete 5)
(set #destDir
    (askdir
        (prompt "Where should GetPayed be installed??\nA new drawer will be created.")
        (help @askdir-help)
        (default @default-dest)
    )
)

(set @default-dest #destDir)

(if (> (exists (tackon #destDir "GetPayed")) 0)
  (
    (if (= (askbool
               (prompt "GetPayed seems to be installed already.\n\nContinue with install?\n\n(This script does not backup old installations!)")
               (help @askbool-help)
           ) 0)
      (
        (if (= @user-level 0))
          (
            ; * Inform novice users (displays path) *
            (exit "Installation canceled.\n\nGetPayed seems to be already installed.")
          )
          (
            ; * Inform Average and Expert users (should now install path) *
            (exit "Installation canceled.\n\nGetPayed was already installed." (quiet))
          )
      )
    ) ;if
  )
) ;if


; * Make destination directories *
(complete 10)
(makedir (tackon #destDir "GetPayed") (infos))
(complete 11)
(makedir (tackon #destDir "GetPayed/docs") (infos))
(complete 12)
(makedir (tackon #destDir "GetPayed/rules"))
(complete 13)
(makedir (tackon #destDir "GetPayed/catalogs"))
(complete 14)
(makedir (tackon #destDir "GetPayed/projects"))

; * Copy needed files in main directory *
(complete 15)
(copyfiles
    (source "/")
    (dest (tackon #destDir "GetPayed/"))
    (choices "GetPayed")
    (infos)
)

; * Copy documentation files *
(complete 30)
(copyfiles
    (source "/docs/")
    (dest (tackon #destDir "GetPayed/docs/") )
    (all)
    (infos)
    (confirm)
    (prompt "Select documentations to install:")
    (help @copyfiles-help)
)

; * Copy locale catalogs *
(complete 45)
(copyfiles
    (source "/catalogs")
    (dest (tackon #destDir "GetPayed/catalogs/"))
    (all)
    (confirm)
    (prompt "Which languages do you want to install?")
    (help "Put a checkmark at all languages you want GetPayed to be able to use.\nWhen installed, if GetPayed cannot open in a language that matches your system settings, then it will show up in English.")
)


; * Copy preset rule-files *
(complete 65)
(copyfiles
    (source "/rules/")
    (dest (tackon #destDir "GetPayed/rules/"))
    (all)
    (confirm)
    (prompt "Select payment rules to install:")
    (help "Put a checkmark at all rule files you wish to install.\n\nA rule file is a file describing a set of payment rules used by GetPayed for calculating the final payment.")
)

; * Install tutorial project(s) *
(complete 80)
(copyfiles
    (source "/projects/")
    (dest (tackon #destDir "GetPayed/projects/"))
    (all)
    (confirm)
    (prompt "Install tutorial script(s):")
    (help @copyfiles-help)
)

; * Copy uninstal script (and icon) *
(complete 85)
(if (set #scriptDir (if (= @user-level 2)
                      (
                        ; * Expert users can select place for uninstall script *
                        (askdir
                            (default (tackon #destDir "GetPayed/") )
                            (prompt "Where should the uninstall script be placed?")
                            (help @askdir-help)
                        )
                      )
                      (
                        ; * Other users get uninstall script in GetPayed drawer *
                        (tackon #destDir "GetPayed/")
                      )
                    ))
  (
    (copyfiles
        (source "UnInstall-GetPayed")
        (dest #scriptDir)
    )
    (complete 90)
    (copyfiles
        (source "UnInstall-GetPayed._info")
        (dest #scriptDir)
        (newname "UnInstall-GetPayed.info")
    )
  )
) ;if

; * Install developer info (not for novice users) *

(complete 95)
(if (= (askbool
           (prompt "Do you want to install developer files?")
           (help "The developer files needs only be copied if you intend to do some developing for GetPayed.\n\nThe casual user will not need these files.")
       ) 1)
  (
    (copyfiles
        (source "/developer")
        (dest (tackon #destDir "GetPayed/developer"))
        (all)
        (infos)
    )
  )
)

(complete 100)

