#!/usr/bin/env bash
# Author: Cefeiko
########################################################################
export PW_PREFIX_NAME="DOTNET"
export PW_AUTOINSTALL_EXE="${PW_USER_TEMP}/wos_client.exe"
export LAUNCH_PARAMETERS=("/S")
export PW_DLL_INSTALL="faudio dotnet48"
export PW_VULKAN_USE=1

WOSB_VERSION="$(curl -s --list-only --connect-timeout 3 https://www.worldofseabattle.com/download2 2>/dev/null | grep 'installer.exe' | awk -F'xsolla-launcher-update/' '{print $2}' | awk -F'/' '{print $1}')"
[[ ! -z "$WOSB_VERSION" ]] && print_info "Found version: $WOSB_VERSION" || yad_error "Error while get version of WOSB INSTALLER."

start_portwine
if try_download_no_mirror "https://installer.launcher.xsolla.com/xlauncher-builds/xsolla-launcher-update/${WOSB_VERSION}/bin/installer.exe" "${PW_AUTOINSTALL_EXE}"
then
    pw_start_progress_bar_block "Installing World of Sea Battle. ${loc_gui_please_wait} "
    pw_run "${PW_AUTOINSTALL_EXE}" 
    try_remove_file "${PW_AUTOINSTALL_EXE}"
    pw_stop_progress_bar
    kill_portwine

    if [[ "${update_loc}" == "RUS" ]] ; then
        export portwine_exe="$WINEPREFIX/drive_c/users/$USER/AppData/Local/Wosb Launcher/launcher.exe"
        export PORTWINE_CREATE_SHORTCUT_NAME="World of Sea Battle RU"
        pw_create_unique_exe "wosb_launcher_ru"
        try_remove_file "${portwine_exe}.ppdb"
        export PW_SKIP_RESTART_STEAM=1
        portwine_create_shortcut block_name
    fi

    export portwine_exe="$WINEPREFIX/drive_c/users/$USER/AppData/Local/Wosb Launcher/launcher.exe"
    export PORTWINE_CREATE_SHORTCUT_NAME="World of Sea Battle EN"
    pw_create_unique_exe "wosb_launcher_en"
    try_remove_file "${portwine_exe}.ppdb"
    portwine_create_shortcut block_name

fi
stop_portwine
