# WINE - Print the list of winetricks verbs that should be applied during the WINE prefix initialization.
# USAGE: wine_winetricks_verbs
# RETURN: A list of winetricks verbs,
#         the list can be empty.
wine_winetricks_verbs() {
	local winetricks_verbs
	winetricks_verbs=$(context_value 'WINE_WINETRICKS_VERBS')

	# Fall back on the default list of winetricks verbs for the current game engine
	if [ -z "$winetricks_verbs" ]; then
		local game_engine
		game_engine=$(game_engine)
		case "$game_engine" in
			('unrealengine3')
				winetricks_verbs=$(wine_winetricks_verbs_unrealengine3)
			;;
			('unrealengine4')
				winetricks_verbs=$(unrealengine4_wine_winetricks_verbs_default)
			;;
		esac
	fi

	# Append the verb used to set a virtual desktop, if required
	local virtual_desktop
	virtual_desktop=$(wine_virtual_desktop)
	case "$virtual_desktop" in
		('none') ;;
		('auto')
			winetricks_verbs="$winetricks_verbs vd=\"\$(screen_resolution)\""
		;;
		(*)
			winetricks_verbs="$winetricks_verbs vd=$virtual_desktop"
		;;
	esac

	printf '%s' "$winetricks_verbs"
}

# WINE - Set winetricks wrapper.
# USAGE: wine_winetricks_wrapper
wine_winetricks_wrapper() {
	# TODO: $WINEBOOT is not used, $WINESERVER is probably not required.
	cat <<- 'EOF'
	# Apply winetricks verbs, spawning a terminal if required
	winetricks_wrapper() {
	    # Export custom path to WINE command
	    # so winetricks use it instead of the default path.
	    WINE=$(wine_command)
	    export WINE

	    # Run winetricks, spawning a terminal if required
	    # to ensure it is not silently running in the background
	    if [ -t 0 ] || command -v zenity kdialog >/dev/null; then
	        winetricks "$@"
	    else
	        $(terminal_wrapper) -e \
	            env \
	            WINE="$WINE" \
	            WINEARCH="$WINEARCH" \
	            WINEDEBUG="$WINEDEBUG" \
	            WINEPREFIX="$WINEPREFIX" \
	            winetricks "$@"
	    fi

	    # Wait a bit for lingering WINE processes to terminate
	    sleep 1s
	}

	EOF
}

