#!/bin/sh

function displayError()
{
/usr/bin/osascript <<zzzEOFzzz

tell application "System Events"
    activate
    display dialog "Java non trovato. Installa Java e riprova." buttons "OK" default button "OK" with title "Java non trovato" with icon stop
end tell

zzzEOFzzz
}

#
# resolve symlinks
#

PRG=$0

while [ -h "$PRG" ]; do
    ls=`ls -ld "$PRG"`
    link=`expr "$ls" : '^.*-> \(.*\)$' 2>/dev/null`
    if expr "$link" : '^/' 2> /dev/null >/dev/null; then
	PRG="$link"
    else
	PRG="`dirname "$PRG"`/$link"
    fi
done

progdir=`dirname "$PRG"`
APPNAME=`basename "$PRG"`

cd "$progdir/../Resources/thegate"
which java > /dev/null 2>&1
found=$?
if [ $found -ne 0 ]
then
  displayError
  exit
fi
#Mostriamo le cartelle log ed errori all'esterno del bundle, se ci sono
if [ -d log ]; then
  ln -s TheGate.app/Contents/Resources/thegate/log ../../../../log
fi
if [ -d errori ]; then
  ln -s TheGate.app/Contents/Resources/thegate/errori ../../../../errori
fi
#java -jar avenger.jar
java autoPatcher
