echo off

cd /d "%~dp0"

call :summary_ok FPatch1956 "start..."

cd /d "%~dp0"
::call InstallEx\check1956.cmd
if %ERRORLEVEL% NEQ 0 goto failed


call :summary_ok FPatch1956 "copy Namechecking ..."
call :Copy_  FPatch1956 Namechecking
if %ERRORLEVEL% NEQ 0 goto failed
cd /d "%~dp0"

::call :go_sql sql1956




call :summary_ok FPatch1956 "copy Internal..."
call :Copy_  FPatch1956 Internal
if %ERRORLEVEL% NEQ 0 goto failed
cd /d "%~dp0"

call :summary_ok FPatch1956 "install ok"
call :EchoColor "FPatch1956:install ok" Green
exit /b 0

:failed
call :summary_failed Patch1956 "install:failed"
echo FPatch1956:failed >&2
echo FPatch1956:failed 
cd /d "%~dp0"
call :EchoColor "FPatch1956: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

:summary_ok [patchname] [comment] [subsystem]
echo %1.%2...
echo %1.%2... >&2

if "%~3"=="" (
  set "s_subsystem=install"
) else (
  set "s_subsystem=%~3"
)

call "%prospero_root%\Internal\Utils\runsql.cmd" AmlWeb "exec [TestsReports_insert_short] '%s_subsystem%.system','%~1','%s_subsystem%',0,'%~2','%PROSPERO_HOST%'"
exit  /b 0

:summary_failed [patchname] [comment] [subsystem]
echo %1.%2...
echo %1.%2... >&2
if "%~3"=="" (
  set "s_subsystem=install"
) else (
  set "s_subsystem=%~3"
)

call "%prospero_root%\Internal\Utils\runsql.cmd" AmlWeb "exec [TestsReports_insert_short] '%s_subsystem%.system','%~1','%s_subsystem%',70,'%~2','%PROSPERO_HOST%'"
exit  /b 0


: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






















