#!/bin/sh
export TEXTDOMAIN=pburn

# Burn from a .toc file
if [ "$TOC" = "true" ]; then
	TITLE="$(gettext 'Select a toc file')"
	. $APPDIR/box_chooser
	if [ "$EXIT" != "OK" ]; then exit; fi
	TMP="`echo $CHOOSER | grep -i '.toc'`"
	if [ "$TMP" = "" ]; then
		TXT1="$(gettext 'Not a valid file!') - $(gettext 'Select a toc file')"
		. $APPDIR/box -ok #error
		exit
	else
		DIRNAME="`dirname \"$CHOOSER\"`"
		FILENAME="`basename \"$CHOOSER\"`"
		IMAGE_FILE="`echo $CHOOSER | sed -e '/.toc//g'`" #cdrecord doesn't call the *.toc file, but its image
		IMG=cdrom
		FRAME="$(gettext 'Audio from TOC file')"
		TXT1="$(gettext 'Audio from TOC file') '$FILENAME'. ($BURNDEV)."
		TXT2="$(gettext 'Continue?')"
		. $APPDIR/box -yesno
		if [ $EXIT = Yes ]; then
			if [ "$CDSPEED" = "Auto" ]; then SPEED=""; else SPEED="-speed=$CDSPEED"; fi
			if type cdrdao > /dev/null 2>&1; then
				echo "cd \"$DIRNAME\"" > $WORKDIR/exec
				echo "cdrdao write --device $BURNDEV \"$FILENAME\"" >> $WORKDIR/exec
			else
				echo "$CDRECORD dev=$BURNDEV -raw96r $SPEED -clone -v \"$IMAGE_FILE\"" > $WORKDIR/exec
			fi
			. $APPDIR/func_exec
		fi
		exit
	fi
fi

# Burn from a .cue file
if [ "$CUE" = "true" ]; then
	TITLE="$(gettext 'Select a cue file')"
	. $APPDIR/box_chooser
	if [ "$EXIT" != "OK" ]; then exit; fi
	TMP="`echo $CHOOSER | grep -i '.cue'`"
	if [ "$TMP" = "" ]; then
		TXT1="$(gettext 'Not a valid file!') - $(gettext 'Select a cue file')"
		. $APPDIR/box -ok #error
		exit
	else
		DIRNAME="`dirname \"$CHOOSER\"`"
		FILENAME="`basename \"$CHOOSER\"`"
		IMG=cdrom
		FRAME="$(gettext 'Audio from CUE file')"
		TXT1="$(gettext 'You are about to create a CD using the file') '$FILENAME'. ($BURNDEV)."
		TXT2="$(gettext 'Continue?')"
		. $APPDIR/box -yesno
		if [ $EXIT = Yes ]; then
			if [ "$CDSPEED" = "Auto" ]; then SPEED=""; else SPEED="-speed=$CDSPEED"; fi
			echo "$CDRECORD dev=$BURNDEV -dao $SPEED -v -text cuefile=\"$CHOOSER\"" > $WORKDIR/exec
			. $APPDIR/func_exec
		fi
		exit
	fi
fi
