; script to install Translator library and associated files
; Should be run from Workbench by double-clicking on the icon

(set @default-dest (expandpath "Sys:"))

;; Install library


(set OS-Version (/ (getversion "dos.library" (resident)) 65536))

(if (>= OS-Version 37)
    (if (>= (database "cpu") 68020)
	((set libext "020") (set name "V37, CPU 68020"))
      ((set libext "v37") (set name "V37")))
  ((set libext "v33") (set name "V33")))


(set libname (cat libext "_translator.library"))

;; Install library

;; Save old version if it exists.


(if (exists "libs:translator.library")
    (   (set oldver (getversion "Libs:translator.library"))
        (if (< oldver (* 65536 42))
            (   (set oldnum ("%ld.%ld" (/ oldver 65536) (bitand oldver 65535)))
                (set oldname ("LIBS:%s-translator.library" oldnum))
                
        	    (rename "LIBS:translator.library"
        		    oldname
        		    (prompt
                        "You currently have version " oldnum " of the "
                        "origional Commodore translator.library installed. "
                        "Do you wish to have it saved and renamed?")
        		    (help "The pre-V42 version of LIBS:translator.library "
                      "currently installed "
        			  "will be renamed as " oldname " if you select Proceed.")
        		    (confirm))))))

	
(copylib
 (source (cat "Libs/" libname))
 (dest "Libs:")
 (confirm)
 (prompt "Install the translator.library "
	 "version for use with an Amiga ROM version " name
	 " or better.")
 (help "Install the translator shared library file")
 (newname "translator.library"))


;; Install accent files



(if (not (exists "Locale:"))
    ((if (not (exists "sys:Locale"))
	 (makedir "SYS:Locale"
		  (prompt "Creating directory SYS:Locale")
		  (help "SYS:Locale is needed by the locale library "
			"and the translator library")
		  (infos)
		  (safe)))
     
     (makeassign "Locale" "Sys:Locale" (safe))
     (startup "Translator"
      (prompt "Modify S:User-startup?")
      (command "Assign Locale: SYS:Locale"))
     ))

(if (not (exists "Locale:Accents"))
    (makedir "Locale:Accents"
		  (prompt "Creating directory Locale:Accents")
		  (help "Locale:Accents is needed by "
			"the translator library")
		  (infos)
		  (safe)))

(copyfiles
 (help "Select which Accent files you wish installed "
       "into the Locale:Accents/ directory.\n\n"
       "These files specify how words should be pronounced in each "
       "language. At least one needs to be installed if the translator "
       "library is to work.")
 
 (prompt "Which accent files do you wish to install?\n"
	 "Note that at least one is needed for the translator "
	 "library to work.")
 (source "Accents")
 (dest "Locale:Accents/")
 (pattern "#?.accent")
 (files)
 (confirm))

;; Install environment variables


(if (= @user-level 2)
    (set accent-file
	 (askfile (prompt "Which accent do you wish to use by default?")
		  (default "Locale:Accents/american.accent")
		  (help "Specify the accent file that contains the default "
			"pronuciation rules for the translator library. "
			"This will be saved in your ENVARC: and ENV: but "
			"can be changed later with the Translator "
			"preferences program.")))
  (set accent-file "Locale:Accents/american.accent"))

(if (exists "ENVARC:")
    (textfile
     (dest "ENVARC:Sys/translator.prefs")
     (append accent-file))
  (startup
   (prompt "Modify S:User-Startup")
   (command ("IF NOT EXISTS ENV:Sys\nMakeDir ENV:Sys\nEndIf\n"
	     "Setenv Sys/translator.prefs"))))

(if (not (exists "ENV:Sys/")) (makedir ("ENV:Sys")))
(run "Utilities/accent set " accent-file)

;; Install utilities


(copyfiles
     (help "Select the Utilities that you wish installed.\n"
	   "You may also specify the directory in which "
	   "they are to be installed.\n\n"
	   "The \"Accent\" command allows you to specify and load "
	   "accent files.\n\n"
	   "\"Flushlib\" allows you to remove shared libraries from "
	   "memory. "
	   "This can be useful when programming or messing around "
	   "with libraries. (2.04 systems only)\n\n"
	   "The \"Translate\" command will translate text to phonemes. "
	   "These are then printed to the console. (2.04 systems only)\n")
     
     (prompt "Which utilities do you wish to install?\nand where?")
     (source "Utilities")
     (dest (if (exists "SYS:Bin/") "SYS:Bin/" "C:"))
     (choices "accent" "flushlib" "translate" "extract")
     (files)
     (confirm))

;; Install preferences editor (Only for V37 systems and above)

(if (>= OS-Version 37)
    (copyfiles
     (help "The translator library preferences editor allows you "
	   "to select the current language and to test translation and speech.")
     
     (prompt "Install the translator preferences editor?")
     (source "")
     (dest "SYS:Prefs")
     (choices "Translator")
     (infos)
     (files)
     (confirm)))


;; The end!
