#!/usr/bin/env bash
# info_ru: Удобная многофункциональная программа для ведения электронных журналов. Позволяет автоматизировать документооборот участников ВЭД, таможенных представителей и пр.
########################################################################
export PROG_NAME="СТМ-Журналы"
export PROG_ICON="ctmjournals"

export WH_WINE_USE="wine_x_tkg_10-0_amd64"
export WINEPREFIX="ved_ctm"
export BASE_PFX="ved_ctm_pfx_x86_v05"
export WINEARCH="win32"
export WH_WINDOWS_VER="7"
export INSTALL_DLL="vb6run art2kmin mdac27 mdac28 arial jet40 dotnet452 dotnet46 msxml3 ie8 vcrun2019 dotnet7 dotnetdesktop7 renderer=gdi"

prepair_wine

# фикс постоянного запроса обновления Windows
get_and_set_reg_file --add 'Software\CTM\CTMSETUP' 'SkipKBCheck' 'REG_DWORD' "1" "userdef"

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

if try_download "https://files.ctm.ru/JOURNALS/SFX/setup_jr.exe" "${AUTOINSTALL_EXE}" ; then
    unpack "${AUTOINSTALL_EXE}" "${AUTOINSTALL_UNPACK}"
    try_remove_file "$AUTOINSTALL_EXE"

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

    WIN_FILE_EXEC="$DRIVE_C/Program Files/CTM/JOURNALS/journals.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
