# Copyright 1999-2006 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

MOD_DESC="Unreal Forever additional weapons & monsters"
MOD_NAME="U4E"
INI_FILE_POS=".ut2004/System/UT2004.ini"

inherit games games-mods

HOMEPAGE="http://u4e.beyondunreal.com/"
SRC_URI="mirror://beyondunreal/u4e/u4ev${PV}-zip.zip"

LICENSE="as-is"

RDEPEND=">=games-fps/ut2004-3369-r1
	games-fps/ut2004-bonuspack-ece"

src_unpack() {
	# The zipfile has a problem with "/" vs "\", which can be ignored
	unzip "${DISTDIR}/${A}"
}

pkg_postinst() {
	games-mods_pkg_postinst

	ewarn "To complete the installation, run:"
	ewarn "   emerge --config ${PN}"
	ewarn "to automatically patch ~/${INI_FILE_POS} for all users."
	echo
}

pkg_config() {
	local dir ini_file

	for dir in /home/* ; do
		ini_file=${dir}/${INI_FILE_POS}
		if [[ -e "${ini_file}" ]] ; then
			# Check whether the ini file has already been patched
			if [[ $(grep -c "/u4e/" "${ini_file}") -lt 5 ]] ; then
				# Patch the ini file
				echo "Adding u4e to ${ini_file}"
				sed -i \
					-e 's:\[Core.System\]:\[Core.System\]\nPaths=../u4e/*.utx\nPaths=../u4e/*.uax\nPaths=../u4e/*.umx\nPaths=../u4e/*.usx\nPaths=../u4e/*.ukx:' \
					"${ini_file}" || echo "sed failed on ${ini_file}"
			fi
		fi
	done
}