#!/bin/sh
PROJECTNAME=wine-powerpoint_viewer_97
APPPATH="Program Files/PowerPoint Viewer"
APPEXE="PPVIEW32.EXE"
INSTALLABLE=1
SETUPEXENAME="Microsoft Powerpoint Viewer 97.exe"
SETUPOPTIONS="/q:1"
SETUPOPTIONS2="/c:setup.exe /qt"
# 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

	if [ -n "$INSTALLABLE" ] ; then
	    cp -r $PROJECTDIR/root $DEV/c:
	    ln -s $PROJECTDIR/install $DEV/c:/install
	    ln -s $HOME $DEV/d:
	else
	    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
	
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

if [ -n "$INSTALLABLE" -a ! -d "$DEV/c:/$APPPATH" ]; then
    $WINELOADER "c:\\install\\$SETUPEXENAME" "$SETUPOPTIONS" "$SETUPOPTIONS2"
fi


if [ -n "$1" ]
then
    #Non-browsable directories workaround
    basefilename=$(basename "$1")
    tmpfilename=$(mktemp  "$HOME/tmp/$basefilename"____XXXXX)
    ln -sf "$1" "$tmpfilename" 
    document=`winepath -l "$tmpfilename"`

    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

rm -f "$tmpfilename"
exit $RES
