#!/usr/bin/env bash
# Author: chal55rus
########################################################################
export PW_PREFIX_NAME="CALIBER"
export LAUNCH_PARAMETERS=("/VERYSILENT")
export PW_AUTOINSTALL_EXE="${PW_USER_TEMP}/CaliberSetup.exe"
export PW_WINE_USE=PROTON_LG
export DISABLE_CP_DEFPFX=1
export PORTWINE_CREATE_SHORTCUT_NAME="CALIBER"

gui_proton_downloader silent "${PW_WINE_USE}"

start_portwine
if try_download "https://caliber-files.gcdn.co/caliber-s3/p1/a88c3b70f76a0e56b1e08b62c9895cfe/launcher/setup/CaliberSetup.exe" "${PW_AUTOINSTALL_EXE}" no_mirror
then
    pw_start_progress_bar_install_game "CALIBER."
    pw_kill_autostart VC_redist.x64.exe 3 &
    pw_run "${PW_AUTOINSTALL_EXE}"
    portwine_exe="$WINEPREFIX/drive_c/Program Files (x86)/1C Game Studios/Caliber/Launcher.exe"
    pw_create_unique_exe "caliber_launcher_pp"
    try_remove_file "${PW_AUTOINSTALL_EXE}"
    try_remove_file "${portwine_exe}.ppdb"
    kill_portwine
    pw_stop_progress_bar
    portwine_create_shortcut
fi
stop_portwine
