#!/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="${PW_USER_TEMP}/Battle.net-Setup.exe"
export PW_WINE_USE="WINE_LG"
export WINEDLLOVERRIDES="locationapi="
export PW_PREFIX_NAME="BATTLE_NET"

start_portwine
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_start_progress_bar_install_game "Battle Net."
    portwine_exe="$(find "$WINEPREFIX/drive_c/" -type f -name "Battle.net.exe" | grep "Battle.net/Battle.net.exe")"
    pw_stop_progress_bar
    portwine_create_shortcut
    try_remove_file "${PW_AUTOINSTALL_EXE}"
    try_remove_file "${portwine_exe}.ppdb"
fi
stop_portwine
