#!/bin/bash
LAUNCHDIR="$(dirname "$(readlink -f "$0")")"
fsst=`stat -f -c %T "$LAUNCHDIR"`

if [ "$fsst" = "msdos" ]; then
zenity --info --title="Sorry" --text="Sorry, this won't work 
as this seems to be a FAT filesystem 
which doesn't support symlinks. Exiting..."
exit 1
fi
WINEDIR=$(dirname "$LAUNCHDIR")
export LD_LIBRARY_PATH="$LAUNCHDIR/usr/lib:${LD_LIBRARY_PATH}"
if [ -z "$WINEPREFIX" ]; then
prefix="$WINEDIR/.wine"
else
prefix="$WINEPREFIX"
fi
export WINEPREFIX="$prefix"
if [ ! -e "$prefix/drive_c/users/$USER" ]; then
  mkdir -p "$prefix/drive_c/users"
fi
cd "$prefix/drive_c/users"
   if [ ! -e "wineuser" ]; then
  mkdir "wineuser"
fi
if [ -d "$USER" ]; then
   if [ -L "$USER" ]; then
    :
   else
     cp -rf "$USER/." "wineuser"
     rm -rf "$USER"
     ln -snf "wineuser" "$USER"
  fi
fi
   if [ ! -L "$USER" ]; then
ln -snf "wineuser" "$USER"
fi
if [ ! -e "$prefix/Wineuser" ]; then
   mkdir -p "$prefix/Wineuser/My Documents"
   mkdir -p "$prefix/Wineuser/Desktop"
fi

  cd "$prefix/drive_c/users/wineuser"
      ln -snf "../../../Wineuser/Desktop" "Desktop"
      ln -snf "../../../Wineuser/My Documents" "My Documents"
if [[ $prefix != "$WINEDIR/.wine" ]]
then

cd "$prefix/drive_c"
if [ ! -d "windows" ] 
then
ln -snf "$WINEDIR/.wine/drive_c/windows" "windows"

elif [[ $prefix == "$WINEDIR/.wine" ]]
then
:
fi
fi

cd "$LAUNCHDIR/usr"
export PATH=./bin/:./games/:"${PATH}"
unset LANG # otherwise the .wine gets foreign language directory names

if [ "${1}x" = "x" ] ; then
    wine explorer
else
    wine "$@"
fi
if [ ! -e "$prefix/cdrom" ]; then
   mkdir -p "$prefix/cdrom"
fi

  cd "$prefix/dosdevices"
      ln -snf "../Wineuser/My Documents" "x:"
      ln -snf "../cdrom" "w:"
      ln -snf "/dev/cdrom" "w::"
      ln -snf "/dev/cdrom" "d::"
      ln -snf "$HOME" "y:"
  cd "$prefix/drive_c/users/wineuser"
rm -f "My Music" "My Pictures" "My Videos"