#!/bin/bash
# The wine wrapper

# Kindly distributed by Martin Schlemmer <azarah@gentoo.org>
# Modified by phoen][x <phoenix@gentoo.org>

export INSTALLDIR="/usr/lib/nwwine"

export WINEPREFIX="$HOME/.nwwine"

export LD_LIBRARY_PATH="$INSTALLDIR/lib/wine:$INSTALLDIR/lib:$LD_LIBRARY_PATH"
export WINEDLLPATH="$LD_LIBRARY_PATH"

export WINE_LOADER=wine

export RUNWINE="${INSTALLDIR}/bin/wine" 

if [ ! -f $WINEPREFIX/config ]
then
	echo "!! ~/.nwwine/config misses"
	echo "!! Setting up a config file"

	mkdir -p ${WINEPREFIX}/fake_windows

	# First copy in the new config file.
	cp "${INSTALLDIR}/.data/config" "${WINEPREFIX}/config"

	echo "!! Setting up ~/.nwwine/fake_windows/"
	cp -R ${INSTALLDIR}/.data/fake_windows/* ${WINEPREFIX}/fake_windows

	echo "!! Setting up default registry."	
	/usr/bin/regedit-nwwine "${INSTALLDIR}/.data/winedefault.reg" &> /dev/null
	sleep 2

	echo "!! Installation complete."
	echo "!! Set your drives in ~/.nwwine/config"
	exit
fi

# Force the use of the more memory-efficient MSVC 5 allocator with
# any programs that use MSVCRT.  This reduces memory consumption
# significantly.
export __MSVCRT_HEAP_SELECT=__GLOBAL_HEAP_SELECTED,2


PATH="$INSTALLDIR/bin:$PATH"

"$RUNWINE" --debugmsg -all "$@"
