#!/bin/bash

# Copyright (C) 2007 Pâris Quentin
#  		     Cassarin-Grand Arthur

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 

if [ "$PLAYONLINUX" = "" ]
then
exit 0
fi
source "$PLAYONLINUX/lib/sources"
cfg_check
message "$LNG_LI_PRESENTATION"

create_shortcut()
{
	reponse=$(question "$LNG_LI_SHORTCUT")
	if [ "$reponse" = "0" ]
	then
		cd $REPERTOIRE/wineprefix/$GAMENAME/drive_c/

		EXEC=$(selectionner_fichier "$LNG_LI_EXEC")
		EXECDIR=$(dirname "$EXEC")
	
		EXECDIR=${EXECDIR//"$REPERTOIRE/wineprefix/$GAMENAME/drive_c/"/""}
		LAUNCHER=$(champ "$LNG_LAUNCHER")
		if [ ! "$EXECDIR" = "" ]
			then
			if [ ! "$LAUNCHER" = "" ]
			then
				creer_lanceur "$GAMENAME" "$REPERTOIRE" "$EXEC" "playonlinux.png" "$LAUNCHER"
			fi
		fi
		create_shortcut
	fi
}
menu=$(menu "$LNG_ACTION" "$LNG_LI_NEW $LNG_LI_PATCH")
if [ "$menu" = "" ]
then
	exit 0
fi
if [ "$menu" = "$LNG_LI_NEW" ]
then
	GAMENAME=$(champ "$LNG_LI_CODENAME")
else
	cd $REPERTOIRE/wineprefix/
	GAMENAME=$(menu "$LNG_CHOICE" "$(ls -1)" "" 0 0 1 "" "--cut-line")
fi

if [ "$GAMENAME" = "" ]
then
	exit 1
fi

select_prefixe "$REPERTOIRE/wineprefix/$GAMENAME"
creer_prefixe

cd $HOME
INSTALLDIR=$(selectionner_fichier "$LNG_LI_INSTALLFILE")
if [ "$INSTALLDIR" = "" ]
then
	erreur "$LNG_LI_CHOOSEFILE"
	exit 1
fi
WORKINGINSTALLDIR=$(dirname "$INSTALLDIR")
cd $WORKINGINSTALLDIR
wine "$INSTALLDIR"

sur_installed
create_shortcut

end_install
