(complete 0)
(welcome)

(message
	"\n\n\n\n"
	"Welcome to Ordering installation script.\n"
)


(set @default-dest
	(askdir (prompt "Please select destination directory for Ordering")
		(help @askdir-help)
		(default "SYS:")
	)
)

(copyfiles
	(prompt "\nCopying Ordering...\n")
	(help @copyfiles-help)
	(source "Ordering")
	(dest   @default-dest)
	(files)
)


(complete 15)

(copyfiles
	(prompt "\nCopying Ordering Preferences Editor...\n")
	(help @copyfiles-help)
	(source "OrderingPrefs")
	(dest   @default-dest)
	(files)
)


(complete 30)

(set icons
	(askchoice
		(prompt "Which icons do you want to install ?")
		(help "MagicWB icons need at least 8 colours.\n\n" @askchoice-help)
		(choices "Normal style" "MagicWB style")
		(default 0)
	)
)

(set iconsdir "\0")
(if (= icons 1)
   (set iconsdir "MWBIcons")
)

(copyfiles
	(prompt "\nCopying Ordering icon...\n")
	(help @copyfiles-help)
   (source (tackon iconsdir "Ordering.info"))
	(dest   @default-dest)
	(files)
)

(copyfiles
	(prompt "\nCopying OrderingPrefs icon...\n")
	(help @copyfiles-help)
   (source (tackon iconsdir "OrderingPrefs.info"))
	(dest   @default-dest)
	(files)
)


(complete 40)

(set wert1 (/ (getversion "libs/reqtools.library") 65536))
(set wert2 (BITAND (getversion "libs/reqtools.library") 65535))

(set flag 1)
(if	(exists "Libs:reqtools.library" (noreq))
	(
		(set oldwert1 (/ (getversion "libs:reqtools.library") 65536))
		(set oldwert2 (BITAND (getversion "libs:reqtools.library") 65535))
		(if	(NOT(askbool
				(prompt "\nReqTools.library version "oldwert1"."oldwert2"\nis currently installed.\n\nDo you want to replace it by version "wert1"."wert2" ?\n")
				(help "If the installed version of ReqTools.library is older than the provided one, you should replace it.\n\n" @askbool-help)
				(default 1)
			))
			(set flag 0)
		)
	)
	(if	(NOT(askbool
		(prompt "\nDo you want to install\nReqTools.library version "wert1"."wert2" ?\n")
		(help "Several functions of Ordering are not available if ReqTools.library is not installed. So you should install it.\n\n" @askbool_help)
		(default 1)
		))
		(set	flag 0)
	)

)

(if	(= flag 1)
	(copylib
		(prompt "\nCopying ReqTools.library...\n")
		(help @copylib-help)
		(source "Libs/reqtools.library")
		(dest   "Libs:")
	)
)


(complete 50)

(set wert1 (/ (getversion "libs/powerpacker.library") 65536))
(set wert2 (BITAND (getversion "libs/powerpacker.library") 65535))

(set	flag 1)
(if	(exists "Libs:powerpacker.library" (noreq))
	(
		(set oldwert1 (/ (getversion "libs:powerpacker.library") 65536))
		(set oldwert2 (BITAND (getversion "libs:powerpacker.library") 65535))
		(if	(NOT(askbool
				(prompt "\nPowerPacker.library version "oldwert1"."oldwert2"\nis currently installed.\n\nDo you want to replace it by version "wert1"."wert2" ?\n")
				(help "If the installed version of PowerPacker.library is older than the provided one, you should replace it.\n\n" @askbool-help)
				(default 1)
			))
			(set	flag 0)
		)
	)
	(if	(NOT(askbool
		(prompt "\nDo you want to install\nPowerPacker.library version "wert1"."wert2" ?\n")
		(help "Ordering can not decrunch powerpacked files without PowerPacker.library.\n\n" @askbool_help)
		(default 1)
		))
		(set	flag 0)
	)

)

(if	(= flag 1)
	(copylib
		(prompt "\nCopying PowerPacker.library...\n")
		(help @copylib-help)
		(source "Libs/powerpacker.library")
		(dest   "Libs:")
	)
)


(complete 60)

(set	flag 1)
(if	(exists "Libs:whatis.library" (noreq))
	(if	(NOT(askbool
			(prompt "\nWhatIs.library is already installed.\n\nDo you want to replace it ?\n")
			(help "Please check if your version of WhatIs.library is newer than the provided one. Else you should replace it.\n\n" @askbool-help)
			(default 1)
		))
		(set	flag 0)
	)
	(if	(NOT(askbool
		(prompt "\nDo you want to install WhatIs.library ?\n")
		(help "Ordering may recognize lots of filetypes using WhatIs.library.\n\n" @askbool_help)
		(default 1)
		))
		(set	flag 0)
	)

)

(if	(= flag 1)
	(copylib
		(prompt "\nCopying WhatIs.library...\n")
		(help @copylib-help)
		(source "Libs/whatis.library")
		(dest   "Libs:")
	)
)


(complete 70)

(set	flag 1)
(if	(exists "S:FileTypes" (noreq))
	(if	(NOT(askbool
			(prompt "\nYou already have a 'FileTypes' file in S:.\n\nDo you want to replace it ?\n")
			(help "'S:FileTypes' contains the filetypes descriptions.\n\n" @askbool-help)
			(default 1)
		))
		(set	flag 0)
	)
)
(if	(= flag 1)
	(copyfiles
	  	(prompt "\nCopying 'FileTypes' to S:\n")
		(help @copyfiles-help)
  		(source "s/FileTypes")
	  	(dest	"S:")
		(files)
	)
)


(complete 80)

(if (exists "LOCALE:")
	(
		(set catlang
			(askchoice
				(prompt "Which catalogs do you want to install ?")
				(help "If you want Ordering to be in your own language, you should install the corresponding catalogs.\n\n" @askchoice-help)
				(choices "Dansk" "English (internal)" "Français" "Italiano" "Norsk" "Svenska")
				(default 1)
			)
		)
		(if (<> catlang 1)
			(
				(set language (select catlang "dansk" "english" "français" "italiano" "norsk" "svenska"))
				(makedir (tackon "LOCALE:Catalogs/" language))
				(copyfiles
					(source (tackon (tackon "Locale/Catalogs/" language) "Ordering.catalog"))
					(dest (tackon "LOCALE:Catalogs/" language))
				  	(prompt "\nCopying 'Ordering.catalog'\n")
					(help @copyfiles-help)
				)
				(copyfiles
					(source (tackon (tackon "Locale/Catalogs/" language) "OrderingPrefs.catalog"))
					(dest (tackon "LOCALE:Catalogs/" language))
				  	(prompt "\nCopying 'OrderingPrefs.catalog'\n")
					(help @copyfiles-help)
				)
			)
		)
	)

)


(complete 90)

(if 	(askbool
		(prompt "\n Do you want to install a documentation file ?\n")
		(help "You should install the documentation to get the online help" @askbool-help)
	)
	(
		(set doc
			(askchoice
				(prompt "Which documentation do you want to install ?")
				(help "Please select the language.\n\n" @askchoice-help)
				(choices "English documentation" "French documentation")
			)
		)

		(if (= doc 0)
			(set orddoc-source "Ordering_English.Guide")
			(set orddoc-source "Ordering_Français.Guide")
		)

		(set orddoc-dest
			(askdir
				(prompt "Select directory")
				(help @askdir-help)
				(default "HELP:")
			)
		)

		(copyfiles
			(prompt "\nCopying documentation...\n")
			(help @copyfiles-help)
			(source orddoc-source)
			(dest   orddoc-dest)
			(newname "Ordering.Guide")
			(files)
			(infos)
		)
	)
)

(complete 100)
