#!/usr/bin/env bash
# Author: cefeiko
# type: games
# name: EVE Online Launcher
# image: eve
# info_en: Launcher for the EVE Online game. A vast multiplayer online game where players explore an endless cosmos, engage in trading, manufacturing, and combat with other players in a unique sandbox environment. The game is known for its complex economy, political intrigue, and the ability to form alliances among players to conquer galactic territories.
# info_ru: Лаунчер для игры EVE Online. Масштабная многопользовательская онлайн-игра, в которой игроки исследуют бескрайний космос, занимаются торговлей, производством и ведением космических боев с другими игроками в уникальной песочнице. Игра известна своей сложной экономикой, политическими интригами и возможностью создания альянсов между игроками для завоевания галактических территорий.
########################################################################
export PW_WINDOWS_VER="10"
export PW_WINE_USE="WINE_LG"
export PW_USE_WINE_DXGI="0"
export PW_VULKAN_USE="2"
export PW_USE_GSTREAMER="0"
export PW_PREFIX_NAME="EVE_ONLINE"
export PW_WINE_FULLSCREEN_FSR="0"
export PW_USE_GAMEMODE="0"
export PW_USE_D3D_EXTRAS="1"
export PW_USE_SHADER_CACHE="0"
export PW_USE_EAC_AND_BE="1"
export PW_DLL_INSTALL="vcrun2022 d3dcompiler_47 arial tahoma" # msdelta
export WINEDLLOVERRIDES="msvcp140,msvcp140_1=n"
export PW_AUTOINSTALL_EXE="${PW_USER_TEMP}/eve-online-latest+Setup.exe"

start_portwine
if try_download "https://launcher.ccpgames.com/eve-online/release/win32/x64/eve-online-latest+Setup.exe" "${PW_AUTOINSTALL_EXE}" no_mirror
then
    pw_start_progress_bar_install_game "EVE Online Launcher."
    EVE_LAUNCHER_DIR="${WINEPREFIX}/drive_c/users/steamuser/AppData/Local/eve-online"

    $pw_7z x "${PW_USER_TEMP}/eve-online-latest+Setup.exe" -o"${EVE_LAUNCHER_DIR}" -y
    EVE_VERSION="$(cat "${EVE_LAUNCHER_DIR}/RELEASES" | awk '{print $2}' | awk -F"-" '{print $3}')"

    $pw_7z x "${EVE_LAUNCHER_DIR}/eve-online-${EVE_VERSION}-full.nupkg" -o"${EVE_LAUNCHER_DIR}/tmp" -y


    create_new_dir "${EVE_LAUNCHER_DIR}/app-$EVE_VERSION"
    create_new_dir "${EVE_LAUNCHER_DIR}/packages/SquirrelTemp"

    cp -r "${EVE_LAUNCHER_DIR}/tmp/lib/net45/." "${EVE_LAUNCHER_DIR}/app-$EVE_VERSION"
    cp "${EVE_LAUNCHER_DIR}/eve-online-${EVE_VERSION}-full.nupkg" "${EVE_LAUNCHER_DIR}/packages"
    mv "${EVE_LAUNCHER_DIR}/app-${EVE_VERSION}/eve-online_ExecutionStub.exe" "${EVE_LAUNCHER_DIR}/eve-online.exe"
    cp "${EVE_LAUNCHER_DIR}/RELEASES" "${EVE_LAUNCHER_DIR}/packages"
    mv "${EVE_LAUNCHER_DIR}/setupIcon.ico" "${EVE_LAUNCHER_DIR}/app.ico"
    rm -rf  "${EVE_LAUNCHER_DIR}/background.gif" "${EVE_LAUNCHER_DIR}/eve-online-${EVE_VERSION}-full.nupkg" "${EVE_LAUNCHER_DIR}/RELEASES" "${EVE_LAUNCHER_DIR}/tmp"

    pw_stop_progress_bar

    portwine_exe="${EVE_LAUNCHER_DIR}/eve-online.exe"
    try_remove_file "${PW_AUTOINSTALL_EXE}"
    try_remove_file "${portwine_exe}.ppdb"
    
    export PORTWINE_CREATE_SHORTCUT_NAME="EVE Online Launcher"
    portwine_create_shortcut

fi
stop_portwine
