#!/bin/bash

#
resolution="1280,1024"

# File containing all desktops currently in use
desktopfile=/tmp/${USER}.evedesktops


# Remove prefs.ini (every time eve.exe is run, it sets bitsCancelled=1 which
# makes the client unable to start.
rm "${HOME}/.wine/drive_c/windows/profiles/${USER}/Local Settings/Application Data/CCP/EVE/c_program_files_ccp_eve_tranquility/settings/prefs.ini"

sleep 1

# Get desktopnumber
desktopnumber=$(awk '{j[$1]} END { for (i=1; i in j; i++); print i++; }' \
        $desktopfile)
echo $desktopnumber >> $desktopfile

env WINEPREFIX="/home/${USER}/.wine" \
    wine explorer \
    /desktop=EVE${desktopnumber},${resolution} \
    "C:\Program Files\CCP\EVE\eve.exe"

# Free the desktop number
tmpfile=$(mktemp)
grep -v $desktopnumber $desktopfile > $tmpfile
mv $tmpfile $desktopfile
