#!/usr/bin/env bash
# Author: Castro-Fidel (linux-gaming.ru)
# type: games
# name: HoYoPlay
# image: hoyoplay
# info_en:
# info_ru:
########################################################################
export PW_VULKAN_USE=2
export PW_AUTOINSTALL_EXE="${PW_USER_TEMP}/Hoyolauncher_installer.exe"
export PW_PREFIX_NAME="HO_YO_PLAY"
export PORTWINE_CREATE_SHORTCUT_NAME="HoYoPlay"

start_portwine

if try_download "https://sg-public-api.hoyoverse.com/event/download_porter/trace/hyp_global/hyphoyoverse/default?url=https%3A%2F%2Fhoyoplay.hoyoverse.com%2F" "${PW_AUTOINSTALL_EXE}" no_mirror
then
    pw_start_progress_bar_install_game "HoYoPlay Launcher."
    pw_kill_autostart HYP.exe &
    export PATH_TO_GAME="${PW_USER_TEMP}"
    pw_run "${PW_AUTOINSTALL_EXE}"
    export portwine_exe="$WINEPREFIX/drive_c/Program Files/HoYoPlay/launcher.exe"
    pw_run reg add "HKEY_CURRENT_USER\Software\Wine\X11 Driver" /v "Decorated" /t REG_SZ /d "N" /f
    pw_create_unique_exe "hoyoplay_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
