# Print the wrestool options string for the given icon.
# USAGE: icon_wrestool_options $icon
icon_wrestool_options() {
	local icon=$1

	local wrestool_options
	wrestool_options=$(get_value "${icon}_WRESTOOL_OPTIONS")

	# Fall back on a default value based on the game engine
	if [ -z "$wrestool_options" ]; then
		local game_engine
		game_engine=$(game_engine)
		case "$game_engine" in
			('unrealengine4')
				wrestool_options=$(unrealengine4_icon_wrestool_options_default)
			;;
			(*)
				wrestool_options='--type=14'
			;;
		esac
	fi

	printf '%s' "$wrestool_options"
}

# Extract .ico file(s) from the given icon, using wrestool.
# USAGE: icon_extract_ico_from_exe $icon $destination
icon_extract_ico_from_exe() {
	local \
		icon=$1 \
		destination=$2

	local icon_file wrestool_options
	icon_file=$(icon_full_path "$icon")
	wrestool_options=$(icon_wrestool_options "$icon")

	wrestool $wrestool_options --extract --output="$destination" "$icon_file"

	# Check that at least one .ico file has been extracted.
	local ico_files_number
	ico_files_number=$(find "$destination" -name '*.ico' | wc --lines)
	if [ "$ico_files_number" -lt 1 ]; then
		error_no_ico_file_extracted "$icon"
		return 1
	fi
}

