#!/bin/csh -f
#
#

# ARGS
set _conf_file		= $argv[1]
set _genesis_edir		= $argv[2]
set _temp_dir		= $argv[3]
set odb_config_dir	= $argv[4]
set _os			= $argv[5]


set ext = ""
if ( $_os =~ *WIN* ) set ext = ".exe"

if ($_genesis_edir !~ /* && $_genesis_edir !~ ?:*) then
	set _genesis_edir = "$_genesis_root/$_genesis_edir"
endif

# LOCAL
set gui_bin = $_genesis_edir/all/gui{$ext}
set gui_resp = $_temp_dir/gui_resp.$$
set gui_file = $_temp_dir/gui_file.$$

alias GUI 'echo \!:* >> $gui_file'
if ( -f $_conf_file ) then
	alias get_param 'set \!:1 = `cat $_conf_file | grep \!:1 | cut -d "=" -f2-100`'
	get_param JAVA_BIN
	get_param CONFIG_DIR
	set _java_bin = "${JAVA_BIN}"
endif

set _gui_action = 1
if (! $?_java_bin ) set _java_bin = ""

while ( $_gui_action == 1 )
	touch $gui_file
	GUI WIN 200 200 
	GUI BG 186479 
	GUI FG 000000 
	GUI LABEL "The configuration file :"
	GUI LABEL "$conf_file"
	GUI LABEL "contains incorrect information."
	GUI LABEL "In order to use the ODB++ Messenger "
	GUI LABEL "please provide the following information:"
	GUI TEXT _java_bin 40 "Java bin dir :"
	GUI DTEXT _java_bin $_java_bin
	GUI RADIO _gui_action "' '" H 1 880000
	GUI Continue
	GUI Exit
	GUI END
	GUI END
	$gui_bin $gui_file > $gui_resp

	if ( $status != 0 ) then
		PAUSE "ODB++ Comm Error : Loading error - could not run gui util"
		set _exit = 1
		exit 1
	endif

	source $gui_resp
	rm -f $gui_resp
	rm -f $gui_file
	if ( $_gui_action == 2 ) then
		set _exit = 1
		exit 1
	endif

	unset msg
	if (! -e "${_java_bin}/java${ext}") then
		set msg = "ODB++ Comm Error : Java Bin file does not exist "
	endif
	if ( $?msg ) then
		GUI WIN 200 200
		GUI BG 186479 
		GUI FG 000000 
		GUI LABEL $msg
		GUI END

		$gui_bin $gui_file > $gui_resp
		rm -f $gui_file
		rm -f $gui_resp
	else
		echo "CONFIG_DIR=$odb_config_dir" > $_conf_file
		echo "JAVA_BIN=${_java_bin}" >> $_conf_file
		exit 0
	endif
end


