echo off

cd /d "%~dp0"

call installEx\check_av_banned_configs.cmd
if %ERRORLEVEL% NEQ 0 goto failed

iisreset
call :Copy_  FPatch2019 AlertViewer
if %ERRORLEVEL% NEQ 0 goto failed

cd /d "%~dp0"
call installEx\create_av_banned_configs.cmd
if %ERRORLEVEL% NEQ 0 goto failed
iisreset

cd /d "%~dp0"

call :Copy_  FPatch2019 Internal
if %ERRORLEVEL% NEQ 0 goto failed
cd /d "%~dp0"


:: ------------------finish.all.ok---------------------------
call :EchoColor "FPatch2019:install ok" Green
exit /b 0


:: ------------------finish.all.failed-----------------------
:failed
cd /d %~dp0
call :EchoColor "FPatch2019:failed" Red

exit /b 1

:EchoColor [text] [color]
powershell "'%~1'.GetEnumerator()|%%{Write-Host $_ -NoNewline -ForegroundColor %~2}"
exit /B

:CheckErrorLevel [errlevel] [emessage] 
echo ELEVEL:%~1
rem if %~1 NEQ 0 goto :failed
if %~1 EQU  0 exit /b
call :EchoColor "%~2" Red
echo .
exit /b 1

:Copy_ [patchName] [subdir]
cd /d "%~dp0"
echo %1:%2...
xcopy /a /r /y /I /E /Q .\%2 "C:\Program Files (x86)\Prospero\%2"
call :CheckErrorLevel %ERRORLEVEL% "failed:copy %2"
if %ERRORLEVEL% NEQ 0 exit /b 1
exit /b 0

:go_sql [sql_cmd]
echo go.sql:%1.cmd
cd /d "%~dp0"
cd /d SQL
call %1.cmd
call :CheckErrorLevel %ERRORLEVEL% "failed:execute %1.cmd"
if %ERRORLEVEL% NEQ 0 exit /b 1
exit /b 0

:go_sql_dm [sql_cmd]
echo go.sql_dm:%1.cmd
cd /d "%~dp0"
cd /d SQL\datamart
call %1.cmd
call :CheckErrorLevel %ERRORLEVEL% "failed:execute %1.cmd"
if %ERRORLEVEL% NEQ 0 exit /b 1
exit /b 0