#!/bin/sh
PROJECTNAME=wine-7zip
APPPATH="Program Files/7-Zip"
APPEXE="7zFM.exe"
#WRITABLE=1
# Launcher for Windows prepacked program (only for legal prepacked one)
# Copyright (c) Etersoft 2005
# Any questions: wine@etersoft.ru
# http://winehq.org.ru
# You have to set in begin of the file follow variables:
# Project name
#PROJECTNAME=wine-myprog
# Path to program directory
#APPPATH="Program Files/Your application/"
# Name of executable file
#APPEXE=Application.exe
# Set if the application needs in writable program directory
#WRITABLE=1

# WINE loader
export WINELOADER=/usr/bin/wine-glibc

# WINE home for config and so...
export WINEPREFIX=$HOME/.wine/$PROJECTNAME
DEV=$WINEPREFIX/dosdevices
PROJECTDIR=/usr/lib/$PROJECTNAME

if [ ! -d $WINEPREFIX ] ; then
	mkdir -p $WINEPREFIX/var $DEV
	cp -f $PROJECTDIR/config/* $WINEPREFIX

	ln -s $PROJECTDIR/root $DEV/c:
	ln -s $HOME $DEV/d:
	ln -s $WINEPREFIX/var $DEV/y:
	cp -rp $PROJECTDIR/root/windows/profiles $DEV/y:
	( cd $DEV/y:/profiles && mv tester $USER)
	ln -s $HOME/tmp $DEV/z:

	if [ -n "$WRITABLE" ] ; then
		# make links if needs writeable program dir
	        APPDIR=$(basename "$APPPATH")
		# Note: -s is a GNU extension
	        cp -rs "$PROJECTDIR/root/$APPPATH" $WINEPREFIX/var/
	        ( cd $WINEPREFIX/var && mv "$APPDIR" Application )
	fi
fi

echo "It is log output window for testing purposes. Do not close it."
echo
if [ -n "$WRITABLE" ] ; then
	EXENAME="Y:\\Application\\$APPEXE"
else
	EXENAME="C:\\$APPPATH\\$APPEXE"
fi
echo
test -f $PROJECTDIR/customconfig.sh && . $PROJECTDIR/customconfig.sh
document=`winepath -l "$1"`
if [ -n "$document" ]
then
	echo "Open $1 as '$document'"
	$WINELOADER "$EXENAME" "$document"
else
	$WINELOADER "$EXENAME"
fi
RES=$?
if [ ! $RES == "0" ] ; then
    echo "Crashed with $RES. Press Ctrl-C or close the console window"
    pause
fi
exit $?
