#!/bin/bash
# Date : (2013-12-04)
# Last Revision : (2013-12-04)
# Wine version used : 1.5.22
# Distribution used to test : Mint
# Author : MrTrip (phys1ks@gmail.com)
# Script licence : GPL v.2
# Program licence : Abandonware
# Depend :

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

TITLE="Tribes 2: TribesNEXT"
PREFIX="TribesNEXT"

POL_SetupWindow_Init
POL_Debug_Init
  
POL_SetupWindow_presentation "$TITLE" "Dynamix and TribesNEXT" "http://www.tribesnext.com" "MrTrip" "$PREFIX"

POL_Wine_SelectPrefix "$PREFIX"
POL_Wine_PrefixCreate "1.5.22"

POL_System_TmpCreate "$PREFIX"

POL_SetupWindow_wait "Installing Required Libraries and such" "$TITLE"
POL_Call POL_Install_d3dx9
POL_Call POL_Install_corefonts
POL_Wine_InstallFonts
Set_Managed off
POL_SetupWindow_message "I will now install Tribes 2 for you and apply all updates. Please use all defaults! Do not register (the website is gone anyway). and DirectX 8 is optional but not needed." "$TITLE"
POL_SetupWindow_InstallMethod "LOCAL,DOWNLOAD"
 if [ "$INSTALL_METHOD" = "LOCAL" ]
	then
		POL_SetupWindow_browse "Please select your Tribes2gsi.exe" "$TITLE"
		POL_SetupWindow_wait "Running installer - please use all defaults!" "$TITLE"
		POL_Wine "$APP_ANSWER"
 elif [ "$INSTALL_METHOD" = "DOWNLOAD" ]
	then
		cd "$POL_System_TmpDir"
		POL_Download "http://xfer1.the-construct.net/tribes2/tribes2gsi.exe" "93460541ddd3bdff9b30829ba04f2186"
		POL_SetupWindow_wait "Downloading Installer - Please wait..." "$TITLE"
		POL_Wine "$APP_ANSWER"
 fi
 
POL_Wine_WaitExit "$TITLE"

POL_SetupWindow_wait "Downloadnig Required Updates" "$TITLE"

#Download files
cd "$POL_System_TmpDir"
POL_Download "http://www.tribesnext.com/files/TribesNext_rc2a.exe" "3bec757215cd29b37d85b567edf8d693"
POL_Download "ftp://ftp.ruby-lang.org/pub/ruby/binaries/mswin32/unstable/ruby-1.9.0-2-i386-mswin32.zip" "01169969aae6e466f0c72f21ee77caf3"

POL_SetupWindow_pulsebar "Installing Updates" "$TITLE"
POL_SetupWindow_set_text "Installing TribesNEXT"
POL_Wine start /unix "$POL_System_TmpDir/TribesNEXT_rc2a.exe"
POL_Wine_WaitExit "$TITLE"
POL_SetupWindow_pulse "25"

POL_SetupWindow_set_text "Applying Ruby fix"
cd "$POL_System_TmpDir"
unzip ruby-1.9.0-2-i386-mswin32.zip
mv "$WINEPREFIX/drive_c/Dynamix/Tribes2/GameData/msvcrt-ruby190.dll" "$WINEPREFIX/drive_c/Dynamix/Tribes2/GameData/msvcrt-ruby190.old"
cd bin
mv "msvcrt-ruby190.dll" "$WINEPREFIX/drive_c/Dynamix/Tribes2/GameData/"
POL_SetupWindow_pulse "75"

POL_SetupWindow_set_text "Overriding DLLs"
POL_Wine_OverrideDLL_App "Tribes2.exe" "native" "msvcrt"
POL_SetupWindow_pulse "90"

POL_SetupWindow_set_text "Removing temporary installer files"
#This fixes a stupid ass bug with POL selecting the Tribes2.exe from the tempinstall directory. I don't even know why T2 leaves that behind. Dumb dumb dumb.
cd $WINEPREFIX/drive_c/users/$USER/Temp/
rm -rf tempinstall
POL_SetupWindow_pulse "100"

POL_SetupWindow_message "The main setup is complete! Thanks to the community at TribesNEXT for making this possible! Special thanks to Dark Dragon DX, Plexor and Liukcairo for their testing and help in getting this running on Wine." "$TITLE"

POL_System_TmpDelete
POL_Shortcut "Tribes2.exe" "Tribes 2: TribesNEXT Online" "" "-online"
POL_Shortcut_InsertBeforeWine "Tribes 2: TribesNEXT Online" "taskset 0x00000001"
POL_SetupWindow_Close
exit