#!/usr/bin/env bash
# Author: Castro-Fidel (linux-gaming.ru)
# type: games
# name: Epic Games Launcher
# image: epicgames
# info_en: Launcher for the Epic Games game library.
# info_ru: Лаунчер для библиотеки игр Epic Games.
########################################################################
export LAUNCH_PARAMETERS="/q"
export PW_AUTOINSTALL_EXE="${PORT_WINE_TMP_PATH}/EpicGamesLauncherInstaller.msi"
export PW_USE_D3D_EXTRAS="1"
export PORTWINE_CREATE_SHORTCUT_NAME="Epic Games Launcher"
export PW_WINE_USE="PROTON_LG"
export PW_USE_ESYNC="1"
export PW_USE_FSYNC="1"
export PW_PREFIX_NAME="DEFAULT"

pw_clear_pfx
start_portproton

if try_download "https://launcher-public-service-prod06.ol.epicgames.com/launcher/api/installer/download/EpicGamesLauncherInstaller.msi" "${PW_AUTOINSTALL_EXE}" no_mirror
then
    try_remove_file "${WINEPREFIX}/drive_c/ProgramData/Epic/EpicGamesLauncher/EpicOnlineServicesInstaller.exe"
    try_remove_dir "${WINEPREFIX}/drive_c/ProgramData/Epic/EpicOnlineServices"
    try_remove_dir "${WINEPREFIX}/drive_c/Program Files (x86)/Epic Games/Epic Online Services/"
    try_remove_dir "${WINEPREFIX}/drive_c/Program Files (x86)/Epic Games/Launcher/"
    # try_remove_dir "${WINEPREFIX}/drive_c/ProgramData/Epic"
    pw_run msiexec /i "${PW_AUTOINSTALL_EXE}"
    PW_EXE_FILE="${WINEPREFIX}/drive_c/Program Files/Epic Games/Launcher/Portal/Binaries/Win64/EpicGamesLauncher.exe"
    try_remove_file "${PW_AUTOINSTALL_EXE}"
    try_remove_file "${PW_EXE_FILE}.ppdb"
    kill_portwine
    portwine_create_shortcut
fi

stop_portproton
