#!/bin/bash
#______________________________________________________________
#Author: 	Xray99
#Liscence: 	GPLv2.1 http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
#Inspired by: 	Red_Lion http://www.linux.org.ru/view-message.jsp?msgid=2323348
#Thank you dude, although I didnt understand a goddamn word :P
#______________________________________________________________

#script which allows you to save your Baldur's Gate 2 & Throne of Bhall
#without crashes
#let the script begin!

echo "~~~Baldur's Gate 2~~~"
echo "~~~~~~Save-Patch~~~~~"
echo ""
echo "Is this the correct installation directory: Programme\\Black Isle\\BGII - SvA [y/n]"

read install_dir

#check input 
if [[ "${install_dir}" == y || "${install_dir}" == '' ]]

#if he entered y or nothing this will take place
then

	#if u like to, u can change the path to your installation yourself
	#so that u don't have to type in the path at every gamestart
	delfile="/home/$(whoami)/.wine/drive_c/Programme/Black Isle/BGII - SvA/temp/default.tot"
	baldurexe="C:\Programme\Black Isle\BGII - SvA\baldur.exe"

#if not, enter your install path
else

	#the path must be entered like this: Program Files\\Black Isle\\BGII - SoA
	#be sure to use 2 backslashes!
	#this could be improved
	echo "Enter installation path: [path\\\\path\\\\path]"
	read alt_install_dir
	baldurexe="C:\\$alt_install_dir\baldur.exe"
	alt_install_dir=`echo $alt_install_dir|tr '\' '/'`
	delfile="/home/$(whoami)/.wine/drive_c/$alt_install_dir/temp/default.tot"

fi

echo "___________________________________"
echo ""
echo "Starting Baldur's Gate 2"
echo "Have Phun and don't forget to save!"
echo ""
echo "Script can be quit by pressing Ctrl + c"
echo "___________________________________"

#removes the file /temp/default.tot every second
DISPLAY=:0.0 wine "${baldurexe}" &
while [[ 1 ]]; do
        [[ -e "${delfile}" ]] && rm -f "${delfile}"
        sleep 1
done

#would be nice if someone fixed that the cursor is replaced by 
#the standard baldur's gate cursor

exit 0

