#!/usr/bin/env bash
# Author: Castro Fidel
########################################################################
export LAUNCH_PARAMETERS=("/VERYSILENT")
export PW_PREFIX_NAME="GW2"
export WINEDLLOVERRIDES="mscoree,mshtml="
export PW_MUST_HAVE_DLL=""

start_portwine
mkdir -p "${WINEPREFIX}/drive_c/Program Files/Guild Wars 2/"
export PW_AUTOINSTALL_EXE="${WINEPREFIX}/drive_c/Program Files/Guild Wars 2/Gw2Setup-64.exe"

if try_download "https://s3.amazonaws.com/gw2cdn/client/branches/Gw2Setup-64.exe" "${PW_AUTOINSTALL_EXE}" no_mirror
then
    pw_start_progress_bar_install_game "Guild Wars 2."
    pw_kill_autostart Gw2.exe 3 &
    pw_run "${PW_AUTOINSTALL_EXE}"
    portwine_exe="${WINEPREFIX}/drive_c/Program Files/Guild Wars 2/Gw2.exe"
    try_remove_file "${PW_AUTOINSTALL_EXE}"
    try_remove_file "${portwine_exe}.ppdb"
    kill_portwine
    mv -f "${WINEPREFIX}/drive_c/users/steamuser/Temp/"* "${WINEPREFIX}/drive_c/Program Files/Guild Wars 2/"
    pw_stop_progress_bar
    export PORTWINE_CREATE_SHORTCUT_NAME="Guild Wars 2"
    portwine_create_shortcut
fi
stop_portwine
