#!/usr/bin/env bash
# Author: Castro-Fidel (linux-gaming.ru)
########################################################################
export LAUNCH_PARAMETERS=("/silent" "/repair" )
export PW_AUTOINSTALL_EXE="${PW_USER_TEMP}/EAappInstaller.exe"
export PORTWINE_CREATE_SHORTCUT_NAME="EALauncher"
export PW_VULKAN_USE="2"
export PW_WINE_USE="PROTON_LG"
export PW_PREFIX_NAME="EAAPP"
export PW_USE_EAC_AND_BE="1"

start_portwine
if try_download_no_mirror "https://origin-a.akamaihd.net/EA-Desktop-Client-Download/installer-releases/EAappInstaller.exe" "${PW_AUTOINSTALL_EXE}"
then
    pw_start_progress_bar_block "${loc_gui_installing_the} EA Launcher. ${loc_gui_please_wait} "
    pw_kill_autostart EABackgroundSer 5 please &
    mkdir -p "$WINEPREFIX/drive_c/Program Files/Electronic Arts/EA Desktop/EA Desktop"
    pw_run "${PW_AUTOINSTALL_EXE}"
    portwine_exe="$WINEPREFIX/drive_c/Program Files/Electronic Arts/EA Desktop/EA Desktop/EALauncher.exe"
    pw_stop_progress_bar
    try_remove_file "${PW_AUTOINSTALL_EXE}"
    try_remove_file "${portwine_exe}.ppdb"
    kill_portwine
    portwine_create_shortcut
fi
stop_portwine 
