#!/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" 

install_bis_menu () 
{
	if [ ! -e "$REPERTOIRE/configurations/options/work" ]
	then
		installbis=$(menu "$LNG_APP_CHOOSE" "$LNG_MAIN_INSTALL_GAME $LNG_MAIN_INSTALL_EXPANSION $LNG_MAIN_INSTALL_PATCH LiveInstall" "$LNG_APP_CHOOSE3" 1 2 1 "wizard.png");
	else
		installbis=$(menu "$LNG_APP_CHOOSE2" "$LNG_MAIN_INSTALL_GAME~$LNG_MAIN_INSTALL_EXPANSION~$LNG_MAIN_INSTALL_PATCH~WorkOnLinux~LiveInstall" "$LNG_APP_CHOOSE3" 1 2 1 "wizard.png" "~");
	fi
	if [ "$installbis" = "$LNG_MAIN_INSTALL_GAME" ]
	then
		install_menu "jeux"
	fi
	if [ "$installbis" = "$LNG_MAIN_INSTALL_PATCH" ]
	then
		install_menu "patchs"
	fi
	if [ "$installbis" = "$LNG_MAIN_INSTALL_EXPANSION" ]
	then
		install_menu "expansions"
	fi
	if [ "$installbis" = "WorkOnLinux" ]
	then
		install_menu "work"
	fi
	if [ "$installbis" = "LiveInstall" ]
	then
		bash $PLAYONLINUX/bash/LiveInstall
	fi
}
install_menu () 
{
	verifier_jeux
	menu=$(menu "$LNG_MAIN_INSTALL_MENU" "$(cat liste_$1)" "$LNG_APP_CHOOSE" 2 2 1 "wizard.png" "--cut-line" "$LNG_MAIN_MENU_ITEM_INSTALL");
	if [ "$?" != 0 ]
	then
		install_bis_menu
		exit	
	fi
	check_network "playonlinux.com" --quiet
	if [ $? == 0 ]
	then
		menu=${menu//" "/"%20"}
		attendre "$LNG_DOWNLOADING_INSTALLER" "wget $SITE/liste_v2/recuperer.php?id=$menu -O install -q" "" 0 0 0 "" 1
		bash $REPERTOIRE/install
	fi
}

install_bis_menu
