#!/usr/bin/env bash

# This file contains functions for data burning

# Checks number of devices
dev_check()
{
	if [[ "${BBNUMDEV}" == 1 ]]; then
  		insert_new_CD
		continue
	fi
}

#This function lets you swap cds if NUMDEV is set to 1
insert_new_CD()
{
	while true; do
  		echo $bb_dm_newcd
		read temp
		if [[ "$temp" = "" ]]; then
			break
		else
			continue
		fi
	done
}

copy_data_cd()
{
	if [[ ${BBNUMDEV} == 2 ]]; then
  		mkfifo BBCDCOPY
		${BB_READCD} dev=${BBCDROM} f=BBCDCOPY | ${BB_CDBURNCMD} dev=${BBCDWRITER} ${BBDTAO} -v -data -eject BBCDCOPY
		echo $bb_dm_ch2_5
		rm BBCDCOPY
		wait_for_enter
		break
	elif 	$(find ${BBBURNDIR} -iname *iso) =! "" &> /dev/null; then	# Does an ISO file exist?
  		echo "$bb_dm_ch2_2${BBBURNDIR}.$bb_dm_ch2_3"
		echo $bb_dm_ch2_4
		wait_for_enter
		break
	else
  		echo "$bb_dm_cdcopy${BBBURNDIR}..."
		if eval "${BB_READCD} ${BB_READCD_OPTS} dev=$BBCDROM f=\"$BBBURNDIR\"/BashBurn.iso"; then
			insert_new_CD
			check_cd_status
			ask_for_blanking
			${BB_CDBURNCMD} dev=${BBCDWRITER} ${BBDTAO} -v -data -eject "$BBBURNDIR"/BashBurn.iso 
			rm ${BBBURNDIR}/BashBurn.iso
			echo $bb_dm_ch2_5
			wait_for_enter
			break
		else
			echo $bb_dm_cdcopy_err1
			echo $bb_dm_cdcopy_err2
			wait_for_enter
			break
		fi
	fi
}

