#!/usr/bin/env bash

# Copyright (C) 2007-2010 PlayOnLinux Team
# Copyright (C) 2007 Pâris Quentin

# 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. 

[ "$PLAYONLINUX" = "" ] && exit 0
source "$PLAYONLINUX/lib/sources" 

menu="$1"

if ! POL_Notice_IsAck "KEEP_DEFAULT_INSTALLER_OPTIONS" || ! POL_Notice_IsAck "DONT_BOTHER_WINEHQ"; then
    POL_SetupWindow_Init
    POL_SetupWindow_notice "$(eval_gettext "When $APPLICATION_TITLE installs a Windows program: \n\n - Leave the default location\n - Do not tick the checkbox 'Run the program' if asked.")" "KEEP_DEFAULT_INSTALLER_OPTIONS" "$(eval_gettext 'Please read this')"
    # Distro packagers: please keep this message on your package. It's a real pain for wine devs
    POL_SetupWindow_notice "$(eval_gettext "$APPLICATION_TITLE is not related to WineHQ.\n\nTo ensure that the results will be comparable from one computer to another and to avoid regressions, we specify a working Wine version for each program. This Wine version will quickly become out to date, but we won't change the installer until new tests are made and it takes time.\n\nFor those reason, please do NOT send any bug report or ask any support on WineHQ forums if you are using $APPLICATION_TITLE.\n\nIf you want to help the project to make some tests in order to avoid using out of date Wine versions, do not hesitate to go on our website.\n\nThank you.")" "DONT_BOTHER_WINEHQ" "$(eval_gettext 'Please read this')"
    POL_SetupWindow_Close
fi

if [ "$menu" = "ExecLiveInstall" ]
then
	exec bash "$PLAYONLINUX/bash/manual_install"
	exit
fi

if [ ! "$menu" = "" ]
then
	export TITLE="$menu"
	export SCRIPTID="$menu"
	type="$(echo "$menu" | cut -d ':' -f1)"
	if [ "$type" = "get" ]
	then
		id=$(echo "$menu" | cut -d ":" -f2)
		rm "$POL_USER_ROOT/install"
		$POL_WGET "$SITE/V4_data/repository/get_file_n.php?version=PlayOn$POL_OS-$VERSION&id=$id" -O "$POL_USER_ROOT/install"
		[ -e "$POL_USER_ROOT/install" ] && POL_Bash "$POL_USER_ROOT/install"
		exit
	fi
	rm "$POL_USER_ROOT/install"
	$POL_WGET "$SITE/V4_data/repository/get_file.php?version=PlayOn$POL_OS-$VERSION&id=$(POL_Website_urlparse "$menu")" -O "$POL_USER_ROOT/install"
	[ -e "$POL_USER_ROOT/install" ] && POL_Bash "$POL_USER_ROOT/install"
fi

