#!/bin/sh

[ -e $HOME/.config/ ] || mkdir $HOME/.config/

cp -ru "%GAMES_DATADIR%/higan" $HOME/.config/

i=0
# Check for profiles and prompt user with a GUI
[ -e "%GAMES_BINDIR%/higan-accuracy" ] && tags="${tags} accuracy"
[ -e "%GAMES_BINDIR%/higan-balanced" ] && tags="${tags} balanced"
[ -e "%GAMES_BINDIR%/higan-performance" ] && tags="${tags} performance"

tags=${tags# }

word_count=$(echo ${tags} | wc -w)

if [ ${word_count} -gt 1 ] ; then
	for i in ${tags} ; do
		xdialog_options="${xdialog_options} ${i} ${i} off"
	done
		profile="$(Xdialog --stdout --no-tags --title "higan" --radiolist "Choose a profile" 0 0 0 ${xdialog_options})"
		if [ "${profile}" = "accuracy" ] \
			|| [ "${profile}" = "balanced" ] \
			|| [ "${profile}" = "performance" ]
		then
			echo "Executing higan-${profile}"
			exec higan-${profile} "$@"
		else
			echo "No profile chosen, exiting..."
			exit
		fi
else
	echo "Executing higan-${tags}"
	exec higan-${tags} "$@"
fi
