; Denna script installerar Lexikon med hjälp av installer.

; Kopiera Lexikon till valfri plats
; Kopiera Words till valfri plats
; Välja hur man anger katalog:
; från WB, från CLI eller med assign.

(complete 0)

(set lex_dest
	(askdir
		(prompt "Choose where Lexikon is to be installed\n\n"
		        "A drawer for Lexikon is created here.")
		(help @askdir-help)
		(default @default-dest)
	)
)

(complete 10)

(set lex_dir (tackon lex_dest "Lexikon"))
(set @deafult-dest lex_dir)

; Skapa katalogen. kolla om den redan finns

(set extype (exists lex_dir))
(if (= extype 1) (abort "The drawer \"Lexikon\" already exists, remove it and try again."))
(if (= extype 2)
    (
        (if (exists (tackon lex_dir "Lexikon"))
            (
                (message
                    (cat " A copy of Lexikon is installed."
                         " If you coninue this is updated."
                         " Certain files will be overwritten."
                    )
                )
            )
        )
    )
    (makedir lex_dir (infos))
)

(complete 20)

(copyfiles
	(prompt "Installing Lexikon.")
	(help @copyfiles-help)
	(source "Lexikon")
	(dest lex_dir)
	(infos)
)

(complete 30)

(set word_dest
	(askdir
		(prompt "In what drawer should the dictionary be installed (the drawer Words)?")
		(help @askdir-help)
		(default lex_dir)
	)
)

(set worddrw
	(tackon
		(word_dest) ("words"))
)

(complete 40)
	
(copyfiles
	(prompt "Installing the dictionary")
	(help @copyfiles-help)
	(source "Words")
	(dest worddrw)
	(all)
)

(complete 50)

(set Guidedir
	(askdir
		(prompt "Installing onlinehelp")
		(help (cat "When Lexikon.guide is installed you have online-help"
			   "on the HELP-key."))
		(default lex_dir)
	)
)

(complete 60)

(copyfiles
	(source "help/English/Lexikon.guide")
	(dest Guidedir)
	(infos)
)

(complete 70)

(set start
	(askchoice
		(prompt "How do you want to give drawer for the dictionary?")
		(help @askchoice-help)
		(choices "From WorkBench" "From CLI" "With assign LEXIKON:")
	)
)

(complete 80)

(copyfiles
        (prompt "Installing registrationfile...")
        (source "Registration")
        (dest lex_dir)
        (infos)
        (help @copyfiles-help)
)

(complete 90)

(if (= start 1)
	(tooltype
		(prompt "Install the drawer as tooltype")
		(help "You only have to click at the icon to start Lexikon.")
		(dest (tackon lex_dest "Lexikon"))
		(noposition)
		(settooltype "KATALOG" lex_dest)
		(confirm)
	)
)

(complete 95)

(if (= start 2)
	(if(askbool
			(prompt "Do you want to make a scriptfile to set the arguments to Lexikon?")
			(help "If you answer no you have to write the drawer in the Shell.\n"
			      "Otherwise you just start a scriptfile in S: to start Lexikon.")
			(default 1)
			(choices "Yes" "No")
		)

		(
		(set kommando
			(tackon lex_dest "Lexikon "))
		(set kommando
			(cat kommando word_dest))

		(set batchfile
			(askstring
				(prompt "Write the filename to start Lexikon!")
				(help "The file contain commands to start Lexikon with the right arguments.")
				(default "Lex"))
		)
		(textfile
			(dest (tackon "S:" batchfile))
			(append kommando)
		)
		(protect
			(tackon "S:" batchfile) 64)
		)
	)
)

(if (= start 3)
	(startup "Lexikon"
		(prompt "A assign is done in S:Userstartup")
		(help @startup-help)
		(command "Assign LEXIKON: \"" word_dest "\"\n")
	)
)

(complete 100)
