#!/usr/bin/env bash
# info_ru: Универсальная программа для создания различных отчетов, в том числе подаваемых в таможенные органы таможенными представителями.
########################################################################
export PROG_NAME="СТМ-Отчет"
export PROG_ICON="ctmreport"

export WH_WINE_USE="wine_x_tkg_10-0_amd64"
export WINEPREFIX="ved_ctm"
export BASE_PFX="ved_ctm_pfx_x86_v04"
export WINEARCH="win32"
export WH_WINDOWS_VER="7"
export INSTALL_DLL="vb6run art2kmin mdac27 mdac28 arial jet40 dotnet452 dotnet46 msxml3 ie8"

prepair_wine

AUTOINSTALL_EXE="${WH_TMP_DIR}/setup_rp.exe"
AUTOINSTALL_UNPACK="${WH_TMP_DIR}/setup_rp"
AUTOINSTALL_SETUP="${WH_TMP_DIR}/setup_rp/setup.exe"

if try_download "https://ftp.ctm.ru/REPORT/SFX/setup_rp.exe" "${AUTOINSTALL_EXE}" ; then
    7z x -y "${AUTOINSTALL_EXE}" -o"${AUTOINSTALL_UNPACK}"
    try_remove_file "$AUTOINSTALL_EXE"

    wine_run_install "${AUTOINSTALL_SETUP}" /cd /targetdir="C:\\\\Program Files\\\\CTM\\\\REPORT" /auto /hide
    try_remove_dir "$AUTOINSTALL_UNPACK"

    WIN_FILE_EXEC="$DRIVE_C/Program Files/CTM/REPORT/Report.exe"
    create_desktop "$PROG_NAME" "$WIN_FILE_EXEC" "$PROG_ICON"

    if [[ "$USE_CTMBAR" == "1" ]] ; then
        if [[ -f "$DRIVE_C/Program Files/CTM/COMMON/CTMBAR.EXE" ]]
        then WIN_FILE_EXEC1="$DRIVE_C/Program Files/CTM/COMMON/CTMBAR.EXE"
        elif [[ -f "$DRIVE_C/Program Files/CTM/COMMON/ctmbar.exe" ]]
        then WIN_FILE_EXEC1="$DRIVE_C/Program Files/CTM/COMMON/ctmbar.exe"
        else WIN_FILE_EXEC1="$DRIVE_C/Program Files/CTM/Common/ctmbar.exe"
        fi
        create_desktop "CTM-Офис" "$WIN_FILE_EXEC1" "wedctmbar"
    fi
fi
