#!/usr/bin/env bash
# Author: Castro-Fidel (linux-gaming.ru)
# type: games
# name: Battle.net Launcher
# image: battle_net
# info_en: Launcher for Activision and Blizzard studio games.
# info_ru: Лаунчер для игр Activision и Blizzard.
########################################################################
export PW_AUTOINSTALL_EXE="${PORT_WINE_TMP_PATH}/Battle.net-Setup.exe"
export PW_WINE_USE="PROTON_LG"
export WINEDLLOVERRIDES="locationapi="
export PW_PREFIX_NAME="BATTLE_NET"
export WINE_SIMULATE_WRITECOPY="1"

start_portproton
if try_download "https://battle.net/download/getInstallerForGame?os=win&version=LIVE&gameProgram=BATTLENET_APP" "${PW_AUTOINSTALL_EXE}" no_mirror
then
    try_remove_dir "$WINEPREFIX/drive_c/ProgramData/Battle.net"
    pw_kill_autostart Battle.net.exe &
    pw_run "${PW_AUTOINSTALL_EXE}"
    PW_EXE_FILE="$(find "$WINEPREFIX/drive_c/" -type f -name "Battle.net.exe" | grep "Battle.net/Battle.net.exe")"
    portwine_create_shortcut
    try_remove_file "${PW_AUTOINSTALL_EXE}"
    try_remove_file "${PW_EXE_FILE}.ppdb"
fi
stop_portproton
