#!/bin/bash

# Copyright (C) 2010 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

mkdir -p "$REPERTOIRE/configurations/plugins_conf/Offline PlayOnLinux/"
export CFILE="$REPERTOIRE/configurations/plugins_conf/Offline PlayOnLinux/plugin.cfg"
source "$CFILE"

if [ "$MODE" = "" ] && [ "$POLOFF_LOADED" = "" ]
then
	POL_SetupWindow_Init
	POL_SetupWindow_message "Offline PlayOnLinux is not configured ! Go to options menu to configure it"
	POL_SetupWindow_Close
else
	[ "$POLOFF_LOADED" = "" ] && message_one "Offline PlayOnLinux is now running\nDon't forget to disable the plugin if you want to get the latest scripts online" "" "offline_pol" 0 "warning.png" "Ok"
fi






if [ "$MODE" == "1" ]
then
	if [ "$POLOFF_LOADED" = "" ]
	then
		cd "$REPERTOIRE/configurations/plugins_conf/Offline PlayOnLinux"
		cd "PlayOnLinux_Server"
		./PlayOnLinux_Server.py &
	fi
	export SITE="http://localhost:8050"
fi

if [ "$MODE" == "2" ]
then
	if [ "$POLOFF_LOADED" = "" ]
		then
		cd "$REPERTOIRE/configurations/plugins_conf/Offline PlayOnLinux"
		cd "PlayOnLinux_Server"
		if [ "$RUN_SERVER" == "TRUE" ]
		then
			./PlayOnLinux_Server.py &
		fi
	fi
	export SITE="http://$SERVER_HOST:$SERVER_PORT"
fi

export POLOFF_LOADED="TRUE"

