#!/bin/sh
set -e
cd "$(dirname "$0")"
set_machine() {
conf_dir=$1
conf="$conf_dir/yape.conf"
mkdir -p "$conf_dir"
if [ -f "$conf" ]; then
  grep -v -e '^EmulationLevel' -e '^DisplayFrameRate' "$conf" > "$conf.tmp" || true
  mv "$conf.tmp" "$conf"
else
  printf '[Yape configuration file]\n' > "$conf"
fi
printf 'DisplayFrameRate = 0\n' >> "$conf"
printf 'EmulationLevel = 2\n' >> "$conf"
}
set_machine "${XDG_DATA_HOME:-$HOME/.local/share}/Gaia/yapeSDL"
if ! ldconfig -p 2>/dev/null | grep -q "libSDL2-2\.0\.so\.0"; then
  export LD_LIBRARY_PATH="$PWD/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
fi
exec ./yapesdl "$PWD/thread-of-ariadne.prg"
