:	'(c) Copyright	Empress Software Inc.	1983, 2000'

#*************************************************************
#	This script is used to restore Win32 Registry key.
#
#	If the value you want to restore for particular key
#	has $NO_NAME_FOUND, that means this key's name was 
#	created, we will remove this key's name, otherwise 
#	just update one.
#*************************************************************
USAGE="*** Usage ***  ./regRestoreKey registry_key_name value [-s silent]"


SHOW_USAGE=false
case $# in
 3)	;;
 4)	test "$4" != "-s" && SHOW_USAGE=true ;;
 *)	SHOW_USAGE=true ;;
esac

if test "$SHOW_USAGE" = "true" 
then
	echo "$USAGE"
	exit 1
fi


. $EMPRESSPATH/common/sys_bin/win32/regConfig || exit 1

KEY=$1
NAME=$2
VALUE=$3
test "$4" = "-s" && SILENT=true


RESTORE_NAME=$NAME
test "$NAME" = "(Default)" && RESTORE_NAME=""

OK=true
ACTION=restore
if test "$VALUE" = "$NO_NAME_FOUND"
then
	# Remove key's name
	ACTION=remove
	test "$SILENT" = "true" || echo "   removing  $NAME..."
	registry -d -k "$KEY" -n "$RESTORE_NAME" > nul 2>&1 || OK="false"
else
	# Update key's name
	test "$SILENT" = "true" || echo "   restoring $NAME..."
	registry -s -k "$KEY" -n "$RESTORE_NAME" -v "$VALUE" > nul 2>&1 || OK="false"
fi

RES=0
if test "$OK" != "true"
then
	echo "Can't $ACTION $KEY\\$NAME"
	RES=1
fi

return $RES
