;;; Strings

(set #how-install
     (cat "Do you want to install the whole program or just update the "
          "language catalogs?"))

(set #how-install-help
     (cat "Choose \"Install whole program\" if you are installing from "
          "scratch or if you are updating an old version.\n"
          "\nChoose \"Update languages\" if you want to install new "
          "language catalogs."))

(set #how-install-1 "Install whole program")
(set #how-install-2 "Update languages")

(set #where-install
     "Choose location where you want to install Yahzee.")

(set #which-icons
     "Which icons do you want to install with Yahzee?")

(set #which-icons-help
     (cat "Choose \"MagicWB icons\" if you have MagicWB installed, "
          "otherwise choose \"Standard icons\"."))

(set #which-icons-1 "MagicWB icons")
(set #which-icons-2 "Standard icons")

(set #where-languages
     "Where do you want to install the language catalogs?")

(set #where-languages-help
     (cat "This lets you choose if you want the language catalogs to be "
          "copied to the same location as the rest of the program, or if "
          "you want to have them in the global Catalog dir."))

(set #which-languages
     "Which languages do you want Yahzee to support?")

(set #which-languages-help
     (cat "Check all languages you want Yahzee to support.\n"
          "\nIf a language is already installed and you don't check it, "
          "it will be removed."))

;;; Procedures

(procedure install-program
  (set @default-dest prog-dest)
  (copylib (source (tackon sourcedir "Yahzee"))
           (dest prog-dest))
  (copylib (source (tackon sourcedir "Yahzee.guide"))
           (dest prog-dest)))

(procedure install-icons
  (set which-icons (askchoice (prompt #which-icons)
                              (help #which-icons-help)
                              (choices #which-icons-1 #which-icons-2)))
  (if (= which-icons 1)
      (set icon-srcdir (tackon icon-srcdir "misc")))
  (copyfiles (source icon-srcdir)
             (dest prog-dest)
             (choices "Yahzee.info" "Yahzee.guide.info"))
  (tooltype (dest (tackon prog-dest "Yahzee"))
            (noposition))
  (tooltype (dest (tackon prog-dest "Yahzee.guide"))
            (noposition)))

(procedure install-locales
  (set where-languages (askchoice (prompt #where-languages)
                                  (help #where-languages-help)
                                  (choices locale-dest
                                           locale-sysdest)))
  (if (= where-languages 1)
      (set locale-dest locale-sysdest))
  (set which-languages (askoptions (prompt #which-languages)
                                   (help #which-languages-help)
                                   (choices "Dansk"
                                            "Deutsch"
                                            "Français (v1.3)"
                                            "Nederlands"
                                            "Norsk (v1.3)"
                                            "Suomi"
                                            "Svenska")))
  (set locale "dansk")
  (if (IN which-languages 0)
      (install-locale)
      (remove-locale))
  (set locale "deutsch")
  (if (IN which-languages 1)
      (install-locale)
      (remove-locale))
  (set locale "français")
  (if (IN which-languages 2)
      (install-locale)
      (remove-locale))
  (set locale "nederlands")
  (if (IN which-languages 3)
      (install-locale)
      (remove-locale))
  (set locale "norsk")
  (if (IN which-languages 4)
      (install-locale)
      (remove-locale))
  (set locale "suomi")
  (if (IN which-languages 5)
      (install-locale)
      (remove-locale))
  (set locale "svenska")
  (if (IN which-languages 6)
      (install-locale)
      (remove-locale)))

(procedure install-locale
  (makedir locale-dest)
  (makedir (tackon locale-dest locale))
  (copylib (source (tackon (tackon locale-srcdir locale) "yahzee.catalog"))
           (dest (tackon locale-dest locale))))

(procedure remove-locale
  (delete (tackon (tackon locale-dest locale) "yahzee.catalog"))
  (if (NOT (= locale-dest locale-sysdest))
      ((delete (tackon locale-dest locale))
       (delete locale-dest))))


;;; Main program

(set sourcedir (pathonly @icon))
(set icon-srcdir sourcedir)
(set locale-srcdir (tackon sourcedir "Catalogs"))
(set locale-sysdest "LOCALE:Catalogs")

(set prog-dest (askdir (prompt #where-install)
                       (help @askdir-help)
                       (default @default-dest)))

(set how-install (askchoice (prompt #how-install)
                            (help #how-install-help)
                            (choices #how-install-1 #how-install-2)))

(if (= how-install 0)
    ((install-program)
     (install-icons))
    (set @default-dest ""))

(set locale-dest (tackon prog-dest "Catalogs"))
(install-locales)
