#!/bin/sh
#January, 2007 Nathan Fisher

# Determine the path to this application.
CURDIR="`pwd`"
APPDIR=`dirname "$0"`
cd "${APPDIR}"
APPDIR="`pwd`"
cd "${CURDIR}"

PROFILE=$HOME/.config/grafburnrc
. $PROFILE
[ ! -d "$TMPDIR" ] && mkdir -p "$TMPDIR"

#Explain to the user what to do
if [ ! "$OPENDIR" = "false" ];then
 rox $TMPDIR
 Xdialog --icon $APPDIR/icons/big/drive-optical.png \
 --left --title "Grafburn: ファイルとフォルダの追加" --msgbox \
"一時ディレクトリにファイラウィンドウを開きました。\n\
このディレクトリに含めたいどんなファイルや\n\
ディレクトリも置くことができます。\n\
\n\
注意: 空容量を節約するために、ファイルを\n\
一時ディレクトリにリンクすることができます。\n\
そしていつものようにISOイメージに入れられます。\n\
\n\
ここに置かれた全部のファイルは\n\
ディスクイメージに含まれます。\n\
終了するまで、このウィンドウは閉じないで下さい。\n\n\
終了したら「OK」ボタンを押して下さい。" 0 0

 #Close the filer window
 rox -D $TMPDIR
else
 Xdialog --icon $APPDIR/icons/big/drive-optical.png \
 --left --title "Grafburn: ファイルとフォルダの追加" --msgbox \
"GrafburnはISOイメージを作るために "$TMPDIR" にある\n\
全てのファイルやディレクトリを使います。空容量を節約する\n\
ためにファイルは一時ディレクトリにシムリンクされます。\n\
「OK」ボタンを押す前にディスクに含める全部がそこにあるか\n\
確認して下さい..." 0 0
fi

#Set file name and volume id
Xdialog --icon $APPDIR/icons/big/drive-optical.png --stdout --left --title \
"Grafburn: ディスクプロパティの設定" --2inputsbox "ここではディスク用に任意の\
ISOファイル名\nやボリュームIDを設定できます。" 0 0 "ファイル名" grafburn.iso \
"ボリュームID" "grafburn_project" > ~/.config/grafburntmp
[ ! $? -eq 0 ] && exit 0

#file name and volume id are stored in ~/.config/grafburntmp
#read it and then discard
NAME=`cat ~/.config/grafburntmp | cut -f 1 -d '/'`
VOLUME=`cat ~/.config/grafburntmp | cut -f 2 -d '/'`
rm -f ~/.config/grafburntmp

#create the iso
rxvt -bg black -fg green -geometry 60x8 -title "Grafburn: create iso" \
	-e mkisofs -D -f -J -R -o "$OUTDIR/$NAME" -V "$VOLUME" -p "$PREPARER" \
	-publisher "$PUBLISHER" "$TMPDIR"

#error dialog
#if [ ! $? -eq 0 ];then
#  gxmessage -center -buttons "GTK_STOCK_DIALOG_ERROR" -bg red \
#  "There was an error creating the iso file, exiting."
#  exit 1
#fi
#double check, make sure the iso file is there
if [ ! -f "$OUTDIR/$NAME" ];then
  gxmessage -center -buttons "GTK_STOCK_DIALOG_ERROR" -bg red \
  "There was an error creating the iso file, exiting."
  exit 1
fi


#everything OK, ask whether to burn or not
Xdialog --icon $APPDIR/icons/big/drive-optical.png --stdout --left --title \
"Grafburn: イメージを焼きますか?" --yesno "ISOファイルが作成されました。\n先に進み \
ディスクに\n焼きますか?" 0 0

if [ $? -eq 0 ];then
  exec $APPDIR/burn_iso $OUTDIR/$NAME
fi
