;;;; $VER: Install 3.0 (30.7.96)


;;; Strings

(set #ask-rexx
     "Do you want to install some arexx scripts?")

(set #ask-rexx-help
     "The scripts provided helps you solve the first level")

(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 ASokoban to support?")

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

(set #where-classes
     "Where do you want to install the ClassAct classes?")

(set #where-classes-help
     (cat "ASokoban uses the ClassAct GUI toolkit."
		      "This means that you need to install some"
					"of the ClassAct class libraries.\n\n"
					"This lets you choose where to install the classes."))

(set #where-install
     (cat "Choose location where you want to install ASokoban"
		      "(Note that NO new drawer will be created)."))


;;; Procedures

(procedure install-program
  (set @default-dest prog-dest)
	;; install program and doc
	(copylib (source (tackon sourcedir "ASokoban"))
	         (dest prog-dest))
	(copylib (source (tackon sourcedir "ASokoban.guide"))
	         (dest prog-dest))
	;; install icons
	(if (= 0 (exists (tackon prog-dest "ASokoban.info") (noreq)))
	    (copyfiles (source (tackon sourcedir "ASokoban.info"))
			           (dest prog-dest)))
	(if (= 0 (exists (tackon prog-dest "ASokoban.guide.info") (noreq)))
	    (copyfiles (source (tackon sourcedir "ASokoban.guide.info"))
			           (dest prog-dest)))
	;; install images
	(makedir (tackon prog-dest "Images"))
	(copyfiles (source (tackon sourcedir "Images/Original"))
	           (pattern "#?.xpm")
						 (dest (tackon prog-dest "Images/Original")))
	(copyfiles (source (tackon sourcedir "Images/Color"))
	           (pattern "#?.xpm")
						 (dest (tackon prog-dest "Images/Color")))
	;; install levels
	(makedir (tackon prog-dest "Levels"))
	(copyfiles (source (tackon sourcedir "Levels/Original"))
	           (pattern "screen.#?")
						 (dest (tackon prog-dest "Levels/Original")))
	;; make various directories
	(makedir (tackon prog-dest "Saves"))
	(makedir (tackon prog-dest "Rexx")))

(procedure install-rexx
  (if (= 1 (askbool (prompt #ask-rexx) (help #ask-rexx-help)))
	    (copyfiles (source (tackon sourcedir "Rexx"))
	               (pattern "#?.rexx")
					    	 (dest (tackon prog-dest "Rexx")))))

(procedure install-locales
  (set locale-dest (tackon prog-dest "Catalogs"))
  (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 "Bosanski"
																	          "Deutsch"
																	          "Svenska")))
  (set locale "Bosanski")
  (if (IN which-languages 0)
      (install-locale)
      (remove-locale))
  (set locale "Deutsch")
  (if (IN which-languages 1)
      (install-locale)
      (remove-locale))
  (set locale "svenska")
  (if (IN which-languages 2)
      (install-locale)
      (remove-locale)))

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

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

(procedure install-classes
  (set classes-dest (askdir (prompt #where-classes)
	                          (help #where-classes-help)
														(default "SYS:Classes")))
	(copylib (source (tackon sourcedir "Classes/arexx.class"))
	         (dest classes-dest))
	(copylib (source (tackon sourcedir "Classes/window.class"))
	         (dest classes-dest))
	(copylib (source (tackon sourcedir "Classes/Gadgets/button.gadget"))
	         (dest (tackon classes-dest "Gadgets")))
	(copylib (source (tackon sourcedir "Classes/Gadgets/integer.gadget"))
	         (dest (tackon classes-dest "Gadgets")))
	(copylib (source (tackon sourcedir "Classes/Gadgets/string.gadget"))
	         (dest (tackon classes-dest "Gadgets")))
	(copylib (source (tackon sourcedir "Classes/Gadgets/listbrowser.gadget"))
	         (dest (tackon classes-dest "Gadgets")))
	(copylib (source (tackon sourcedir "Classes/Gadgets/scroller.gadget"))
	         (dest (tackon classes-dest "Gadgets")))
	(copylib (source (tackon sourcedir "Classes/Images/label.image"))
	         (dest (tackon classes-dest "Images")))
	(copylib (source (tackon sourcedir "Classes/Images/bevel.image"))
	         (dest (tackon classes-dest "Images")))
	(copylib (source (tackon sourcedir "Classes/Images/drawlist.image"))
	         (dest (tackon classes-dest "Images")))
	(copylib (source (tackon sourcedir "Classes/Images/glyph.image"))
	         (dest (tackon classes-dest "Images")))
	(set cpu (database "cpu"))
  (set cpu020 (and (<> cpu "68000") (<> cpu "68010")))
  (set v39 (>= (/ (getversion "exec.library" (resident)) 65536) 39))
	(if (and cpu020 v39)
    	(copylib (source (tackon sourcedir "Classes/Gadgets/layout.gadget.020"))
	             (dest (tackon classes-dest "Gadgets"))
				    	 (newname "layout.gadget"))
    	(copylib (source (tackon sourcedir "Classes/Gadgets/layout.gadget"))
	             (dest (tackon classes-dest "Gadgets")))))


;;; Main program

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

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

(install-program)
(install-rexx)
(install-locales)
(install-classes)
