; $VER: Install BoardsLib 3.xx (20.04.2014)
; Installer curtesy by Michael Malyshev
; updated by Marcus Gerards

;(effect "center" "horizontal" $000000 $00FF00)

(set #exitmsg "\n\nIf you are a developer and wish to use\nboards.library, check out the included\ndocumentation, includes and autodocs.")

; Welcome screen

(welcome "\nThis installer script will install boards.library and tools.\nboards.library is a universal library for identifying your hardware...\n\n")

; Flush

(message "\nBefore proceeding, you must quit all programs using boards.library, so that the old version can be flushed from memory.")
(run "Avail FLUSH")


; Copy boards.library

(copylib
    (prompt "\nInstalling boards.library")
    (help @copyfiles-help)
    (source "libs/boards.library")
    (dest "Libs:")
    (confirm)
    (optional "nofail" "force" "askuser")
)

; Ask OpenPCI-library

(set #openpci
	(askbool
		(prompt "\nboards.library can detect PCI-cards via \nopenpci.library by Benjamin Vernoux.\n\nUseful, if your computer has a PCI busboard \n(Mediator, Prometheus, GRex).\n\nWould you like to install openpci.library?")
		(help "Yes, you really need this for PCI busboards only.\n\n")
		(default 1)
	)
)

(if #openpci
	(
		(copylib
    		(prompt "\nInstalling openpci.library")
    		(help @copyfiles-help)
    		(source "libs/openpci.library")
    		(dest "Libs:")
    		(confirm)
    		(optional "nofail" "force" "askuser")
		)
	)
)
	

(set destination
	(askdir 
		(prompt "\Where do you want to install ShowBoards?\n")
		(default "Sys:Utilities")
		(help "\nYou should place this tool in your system's path.\nRecommended are c: or sys;utilities (if you're using it via Workbench).")
	)
)	

(message "\nPlease remove older versions manually,\nif you've just chosen a path other than c: or sys:c!")

(copylib
    (prompt "\nInstalling ShowBoards")
    (help @copyfiles-help)
    (source "Utilities/ShowBoards")
    (dest destination)
    (confirm)
    (optional "nofail" "force" "askuser")
)
(copyfiles
	(source "Utilities/ShowBoards.info")
	(dest destination)
)

(copyfiles
	(prompt "\nInstalling documentation")
	(help @copyfiles-help)
	(source "BoardsLib.guide")
	(dest "SYS:Locale/Help/english/")
	(infos)
	(noposition)
)

; Copy catalogs (locale support)
;
;(set #catSourceDir (tackon "Catalogs" @language))
;(set #catDestDir (tackon "Locale:" (tackon "Catalogs" @language)))
;(if (= (and (= (exists (#catSourceDir)) 2) (= (exists (#catDestDir)) 2)) 1)
;    (foreach #catSourceDir "#?"
;        (copylib
;            (source (tackon #catSourceDir @each-name))
;            (dest #catDestDir)
;        )
;    )
;)
;


; Ask ENV variable setting

 (set #boardsenvvar
           (askbool
		(prompt "\nSome ACA turbocards by IComp can only be detected \nvia custom detection routines.\n\nWould you like to enable these for boards.library? \n\n(See help for further info).")
		(help "\nYou should only enable these routines if you're using an ACA turbocard with your machine.\n\nThey will cause (harmless) Enforcer hits, which might annoy you when using Enforcer/MuForce, etc.\n")
		(default 1)
           )
  )

  (if #boardsenvvar
	(
;       Set environment variable to 1
	(run "Echo 1 >ENV:BOARDS_CUSTOMCHECK")
	(run "Echo 1 >ENVARC:BOARDS_CUSTOMCHECK")
	)
  )

  (if (not #boardsenvvar)
	(
;       Clear environment variable (or delete it for good, uncomment both lines!)
	(run "Echo 0 >ENV:BOARDS_CUSTOMCHECK")
	(run "Echo 0 >ENVARC:BOARDS_CUSTOMCHECK")
	)
  )

(set #guide "Boards.guide")
(message "\nPlease consult the Guide and modify the \ntooltypes of showboards according to your needs.")
(run ("Run >NIL: SYS:Utilities/Multiview %s" #guide) (safe))

; Exit

(exit #exitmsg (quiet))
