#!/bin/bash



VAROUT=`kdialog --icon /usr/share/pixmaps/aiso2.png --caption "Select Database Folder" --getexistingdirectory $HOME/ `

if test -z $VAROUT
then 
exit
else
echo continua
fi


rm -rf $HOME/virtual-drives/.database
> $HOME/virtual-drives/.database
echo "$VAROUT" > $HOME/virtual-drives/.database
cd "$VAROUT"
rm -rf $HOME/virtual-drives/.database2
#ls -1 *.iso *.mdf *.img *.bin *.nrg | tee > $HOME/virtual-drives/.database2


if `kdialog --title "AcetoneISO2 warning dialog" --warningyesno "Do You want me to scan also Sub-Directories?\nPlease note that recursive scanning can take some time depending on how big sub-folders are."`
  	then
  	 
find . -name "*.bin" -o -name "*.iso" -o -name "*.nrg" -o -name "*.mdf" -o -name "*.img" | tee > $HOME/virtual-drives/.database2

	> $HOME/virtual-drives/db-recursive
							

  	else
	rm -rf $HOME/virtual-drives/db-recursive
	ls -1 *.iso *.mdf *.img *.bin *.nrg | tee > $HOME/virtual-drives/.database2
  	fi



if test -e $HOME/virtual-drives/.database2
then
kdialog --caption "AcetoneISO" --msgbox "Database Succesfully Created"
else
kdialog --caption "AcetoneISO" --msgbox "There was a problem generating Database"
fi

exit