#!/usr/bin/env bash
# info_ru: Комплект плагинов «Сметная система АВС» к BIM-системам.
########################################################################
export WH_WINE_USE="wine-9.0.14-alt1-amd64"
export WINEPREFIX="abc"
export PROG_NAME="ABC-BIM-Plugins-RU"
export BASE_PFX="none"
export WH_WINDOWS_VER="10"
export WINEARCH="win64"
# export INSTALL_DLL=""

prepair_wine
print_info "Загрузка страницы..."
ABC_FILE="${WH_TMP_DIR}/ABC-BIM-Plugins-RU.html"
curl -o "$ABC_FILE" -A "Mozilla/5.0 (compatible; Konqueror/2.1.1; X11)" "https://abccenter.ru/download-ru/"

if [[ ! -f "$ABC_FILE" ]] \
|| grep -q "Forbidden" "$ABC_FILE"
then
    fatal "Страница сайта не доступна, или превышено количество запросов к странице."
fi

VERSION=$(grep -oP 'ABC-BIM-Plugins-RU_\K\d+[._]\d+[._]\d+' "$ABC_FILE" | sed -E 's/[._]/./g')
AUTOINSTALL_EXE="${WH_TMP_DIR}/ABC-BIM-Plugins-RU_${VERSION}.exe"

if try_download "https://abccenter.ru/wp-content/soft/ABC-BIM-Plugins-RU_${VERSION}_Setup.exe" "${AUTOINSTALL_EXE}" ; then
    wine_run_install "${AUTOINSTALL_EXE}" /VERYSILENT /SUPPRESSMSGBOXES /NORESTART /SP-
    try_remove_file "$AUTOINSTALL_EXE"
    try_remove_file "$ABC_FILE"
fi
