REM Script Version: UK CCaaS 2026-02-16 
@echo off
setlocal

rem This script is supplied by Enghouse Interactive for installing Enghouse Cloud Client Services from the command prompt.

:version
    set ccspVersion=7.4.1.4
    set wcfHttpPort=8000
    set wcfHttpsPort=8001
    set usingSSL=true
    set protocol=https
    echo.
    echo ******* Version *******
    echo Offline TouchPoint Client Services Installation for Enghouse Cloud %ccspVersion%
    echo.
    goto check_Permissions

:check_Permissions

    echo.
    echo ******* Phase 1 *******
    echo Detecting permissions to run this batch file...

    net session >nul 2>&1
    if %errorLevel% == 0 (
        echo Success: Administrator Command Prompt is confirmed.
    ) else (
        echo Failure: Administrator Command Prompt is required.
        echo Please contact your IT administrator for assistance.
        goto errorExit
    )
    echo Detecting permissions to run this batch file done.
    echo.

:checkInstallerFiles

    echo.
    echo ******* Phase 2 *******
    echo Checking all files are available...
    set fileToCheck="CCSPClientInstallationService.msi"
    if exist %fileToCheck% (
        echo Reqired file is found:   %fileToCheck%
    ) else (
        echo Reqired file is missing: %fileToCheck%
        set errorlevel=-1
        goto errorExit
    )
    set fileToCheck="CCSPClientReportingService.msi"
    if exist %fileToCheck% (
        echo Reqired file is found:   %fileToCheck%
    ) else (
        echo Reqired file is missing: %fileToCheck%
        set errorlevel=-1
        goto errorExit
    )
    set fileToCheck="CCSPSIPService.msi"
    if exist %fileToCheck% (
        echo Reqired file is found:   %fileToCheck%
    ) else (
        echo Reqired file is missing: %fileToCheck%
        set errorlevel=-1
        goto errorExit
    )
    set fileToCheck="vcredist_x86.exe"
    if exist %fileToCheck% (
        echo Reqired file is found:   %fileToCheck%
    ) else (
        echo Reqired file is missing: %fileToCheck%
        set errorlevel=-1
        goto errorExit
    )
    set fileToCheck="CCSPScreenRecordingService.msi"
    if exist %fileToCheck% (
        echo Reqired file is found:   %fileToCheck%
    ) else (
        echo Reqired file is missing: %fileToCheck%
        set errorlevel=-1
        goto errorExit
    )
    set fileToCheck="Encoder_en.exe"
    if exist %fileToCheck% (
        echo Reqired file is found:   %fileToCheck%
    ) else (
        echo Reqired file is missing: %fileToCheck%
        set errorlevel=-1
        goto errorExit
    )
    set fileToCheck="CCSPTouchPointConnector.msi"
    if exist %fileToCheck% (
        echo Reqired file is found:   %fileToCheck%
    ) else (
        echo Reqired file is missing: %fileToCheck%
        set errorlevel=-1
        goto errorExit
    )
    set fileToCheck="CCSPClientUploadsService.msi"
    if exist %fileToCheck% (
        echo Reqired file is found:   %fileToCheck%
    ) else (
        echo Reqired file is missing: %fileToCheck%
        set errorlevel=-1
        goto errorExit
    )
    set fileToCheck="CCSPClientTrayApp.msi"
    if exist %fileToCheck% (
        echo Reqired file is found:   %fileToCheck%
    ) else (
        echo Reqired file is missing: %fileToCheck%
        set errorlevel=-1
        goto errorExit
    )
    set fileToCheck="CCSPClientCommunicator.msi"
    if exist %fileToCheck% (
        echo Reqired file is found:   %fileToCheck%
    ) else (
        echo Reqired file is missing: %fileToCheck%
        set errorlevel=-1
        goto errorExit
    )
    echo Checking all files are available done.
    echo.

:uninstall

    echo.
    echo ******* Phase 3 *******
    echo Uninstalling existing Enghouse Cloud Client Services...

    echo Stopping Enghouse Cloud Client Services
    set wmicCmd=wmic service where "PathName like '%%Enghouse.CCSP%%'" call StopService
    start /wait %wmicCmd%>nul
    if not "%errorlevel%" == "0" goto errorExit

    echo Uninstalling Enghouse Cloud Client Services
    set wmicCmd=wmic product where "caption like 'CCSP%%'" call uninstall
    start /wait %wmicCmd%>nul
    if not "%errorlevel%" == "0" goto errorExit
    echo Uninstalling existing Enghouse Cloud Client Services done.
    echo.

:install

    echo.
    echo ******* Phase 4 *******
    echo Enghouse Cloud Client Services installation starts...

    echo Installing CCSPClientInstallationService
    set installCmd=msiexec /i CCSPClientInstallationService.msi /qn /l*v CCSPClientInstallationService.log USING_HTTPS=%usingSSL% WCF_HTTP_PORT=%wcfHttpPort% WCF_HTTPS_PORT=%wcfHttpsPort% INSTALLATIONCONNECTORURL="%protocol%://localhost:49074"
    echo run command: %installCmd%
    start /wait %installCmd%
    if not "%errorlevel%" == "0" goto installError

    echo Installing CCSPClientReportingService
    set installCmd=msiexec /i CCSPClientReportingService.msi /qn /l*v CCSPClientReportingService.log WCF_HTTP_PORT=%wcfHttpPort% WCF_HTTPS_PORT=%wcfHttpsPort%
    echo run command: %installCmd%
    start /wait %installCmd%
    if not "%errorlevel%" == "0" goto installError

    echo Installing CCSPSIPService
    set installCmd=msiexec /i CCSPSIPService.msi /qn /l*v CCSPSIPService.log SIPCONNECTORURL="%protocol%://localhost:49073" WCF_HTTP_PORT=%wcfHttpPort% WCF_HTTPS_PORT=%wcfHttpsPort%
    echo run command: %installCmd%
    start /wait %installCmd%
    if not "%errorlevel%" == "0" goto installError

    echo Installing Microsoft Visual C++ Redistributable Package
    set installCmd=vcredist_x86.exe /q /l "%CD%\vcredist_x86.log"
    echo run command: %installCmd%
    start /wait %installCmd%
	REM We can continue if a later version is already installed
	IF "%errorlevel%" == "1638" goto CCSPScreenRecordingService
	if not "%errorlevel%" == "0" goto installError

	:CCSPScreenRecordingService
    echo Installing CCSPScreenRecordingService
    set installCmd=msiexec /i CCSPScreenRecordingService.msi /qn /l*v CCSPScreenRecordingService.log TOUCHPOINTCONNECTORURL="%protocol%://localhost:49071"
    echo run command: %installCmd%
    start /wait %installCmd%
    if not "%errorlevel%" == "0" goto installError

    echo Installing CCSPTouchPointConnector
    set installCmd=msiexec /i CCSPTouchPointConnector.msi /qn /l*v CCSPTouchPointConnector.log TOUCHPOINTCONNECTORURL="%protocol%://localhost:49071"
    echo run command: %installCmd%
    start /wait %installCmd%
    if not "%errorlevel%" == "0" goto installError

    echo Installing CCSPClientUploadsService
    REM adjusted for 7.3.0.1195 package U1
    REM   added msi property TOUCHPOINTCONNECTORURL
    set installCmd=msiexec /i CCSPClientUploadsService.msi /qn /l*v CCSPClientUploadsService.log TOUCHPOINTCONNECTORURL="%protocol%://localhost:49071"
    echo run command: %installCmd%
    start /wait %installCmd%
    if not "%errorlevel%" == "0" goto installError

    echo Installing CCSPClientTrayApp
    set installCmd=msiexec /i CCSPClientTrayApp.msi /qn /l*v CCSPClientTrayApp.log TOUCHPOINTCONNECTORURL="%protocol%://localhost:49071"
    echo run command: %installCmd%
    start /wait %installCmd%
    if not "%errorlevel%" == "0" goto installError

    echo Installing CCSPClientCommunicator
    set installCmd=msiexec /i CCSPClientCommunicator.msi /qn /l*v CCSPClientCommunicator.log TOUCHPOINTCONNECTORURL="%protocol%://localhost:49071"
    echo run command: %installCmd%
    start /wait %installCmd%
    if not "%errorlevel%" == "0" goto installError

    echo Installing Microsoft Expression Encoder 4
    echo If a reboot is required first, reboot and then run the Encoder_en.exe again with Administrative Privileges
    set installCmd=Encoder_en.exe -q
    echo run command: %installCmd%
    start /wait %installCmd%
    if not "%errorlevel%" == "0" goto installError

    echo Enghouse Cloud Client Services installation ends.
    echo.
    goto errorExit

:installError

    echo Enghouse Cloud Client Services installation failed.
    echo.
    goto errorExit

:errorExit

    echo.
    echo ******* Phase 5 *******
    echo Error level: %errorlevel%
    if not "%errorlevel%" == "0" (
        echo This script had failed to install some or all Enghouse Cloud Client Services and/or dependencies.
    ) else (
        echo This script had installed Enghouse Cloud Client Services and dependencies successfully.
    )
    echo.
    exit /b %errorlevel%
