#/bin/bash

javacmd=""
jarfile=""

for line in `cat framework.ini`
do
	if [ "$(echo "$line" | grep CMD)" != "" ]; then
		javacmd=${line#*=}
	elif [ "$(echo "$line" | grep CORE)" != "" ]; then
		jarfile=${line#*=}
	fi
done

function startcmd() {
	javacmd=$1
	if [ ! -f "${jarfile}" ]; then
		jarfile=program.jar
	fi
	echo "#Java runtime framework settings" > framework.ini
	echo "CMD=${javacmd}" >> framework.ini
	echo "CORE=${jarfile}" >> framework.ini
	${javacmd} -jar ${jarfile} $2 $3 $4 $5 $6 $7 $8 $9
}

if [ -z "${javacmd}" ]; then
	javacmd=java
fi
if which "${javacmd}" 2>/dev/null; then
	startcmd "${javacmd}" $@
elif which java 2>/dev/null; then
	startcmd "java" $@
else
	echo "未能找到Java命令，请先安装Java，或在配置文件 framework.ini 中修正Java安装路径。"
	echo "#Java runtime framework settings" > framework.ini
	echo "CMD=java" >> framework.ini
	echo "CORE=program.jar" >> framework.ini
	exit
fi

