#!/bin/bash

defitem=1

while true; do
load_configs
dialog_menu_item $defitem "\Z6Wine prefix settings" "" \
	"1" "\Z6Remove prefix" \
	"2" "\Z6Change wine esync mode"
defitem=$?
case $defitem in
1)
	dialog_yesno "Do You Want to Continue And remove prefix?"
	if [ "$?" = "0" ]; then
		rm -rf $WINEPREFIX
	fi
;;
2)
	if [[ ! "$WINE_PATH" = *"Wine GE-Custom 8.25"* ]] || [ ! -e "$WINE_PATH" ]; then
		echo "WINEESYNC is disabled due to outdated wine selected now."
		echo "Do you want to install and enable Wine GE-Custom 8.25 automatically? (Y/n)"
		read i
		if [ "$i" = "Y" ] || [ "$i" = "y" ]; then
			load_package-manager
			if [ "$?" = "1" ]; then
				continue
			fi
			sync-package wine-ge-custom-8-25
			echo "export WINE_PATH=\$PREFIX/glibc/wine-ge-custom-8-25
export WINEPREFIX=\$PREFIX/glibc/wine-ge-custom-8-25/.wine">$PREFIX/glibc/opt/conf/wine_path.conf
		fi
		continue
	fi
	while true; do
	load_configs
	dialog_menu "\Z6WINEESYNC settings" "\ZbCurrent settings:\Zn
	\Z6WINEESYNC\Z6 =\Z5$WINEESYNC
	\Z6WINEESYNC no root mode\Z6 =\Z5$WINEESYNC_TERMUX" \
	"1" "\Z6Disable esync" \
	"2" "\Z6Enable esync without root \Z5(fast)" \
	"3" "\Z6Enable esync with root \Z5(may be faster)"
	case $? in
	1) echo "export WINEESYNC=0
export WINEESYNC_TERMUX=0">$PREFIX/glibc/opt/conf/wineesync.conf ;;
	2) echo "export WINEESYNC=1
export WINEESYNC_TERMUX=1">$PREFIX/glibc/opt/conf/wineesync.conf ;;
	3) echo "export WINEESYNC=1
export WINEESYNC_TERMUX=0">$PREFIX/glibc/opt/conf/wineesync.conf ;;
	255) break ;;
	esac
	done
;;
255)
	break
;;
esac
done
