@echo off
call check-for-admin
if %ERRORLEVEL% neq 0 exit /b

set OPT=..\optional
set SOFTWARE=..\software
set MSI=emclient-setup.msi
set EMSERVERIP=104.22.21.185,172.67.15.154,104.22.20.185

if NOT EXIST %SOFTWARE%\%MSI% (
  echo ERROR: %SOFTWARE%\%MSI% not found!
  exit /b
)

echo ####### %0 #######

echo installing em-Client ...
cd %SOFTWARE%
@echo on
msiexec /i %MSI% /quiet
@echo off
cd %OPT%

echo removing autostart for em-Client ...
reg delete "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" ^
  /v "eM Client" /f

taskkill /F /IM SystemSettings.exe 2>nul

echo copying link to desktop ...
copy /Y "%PROGRAMDATA%\Microsoft\Windows\Start Menu\Programs\eM Client.lnk" ^
  %PUBLIC%\Desktop

echo refreshing desktop ...
ie4uinit.exe -show

echo disabling automatic updates via W10 firewall ...
rem delete old rule ...
netsh advfirewall firewall delete rule name="block_emclient_updates" 2>nul

rem create new rule ...
netsh advfirewall firewall add rule name="block_emclient_updates" ^
  dir=out action=block protocol=tcp localip=any remoteip=%EMSERVERIP% ^
  remoteport=80,443 program="%ProgramFiles(x86)%\eM Client\MailClient.exe" 1>nul 2>nul

rem show new rule ...
netsh advfirewall firewall show rule name="block_emclient_updates"

echo ####### %0 #######

rem set filetypes ...
if EXIST ..\scripts\set-filetypes.cmd (
  call ..\scripts\set-filetypes.cmd
)

pause

