@echo off

:: Set INSTALLDIR
set INSTALLDIR="D:\TWS"

IF NOT EXIST %INSTALLDIR% set INSTALLDIR="E:\TWS"
IF NOT EXIST %INSTALLDIR% set INSTALLDIR="%ProgramFiles%\TWS"
IF NOT EXIST %INSTALLDIR% set INSTALLDIR="%ProgramFiles(x86)%\TWS"
IF NOT EXIST %INSTALLDIR% (

	echo TWS install directory not found
	pause
	exit

)


:: Go to the script path

cd /D %~dp0


:: Set Patch Version
set PATCH_VERSION=5.2.2314.28a

echo -----------------------------------------
echo            PATCH %PATCH_VERSION%
echo -----------------------------------------
echo.
pause

echo.
echo ------------------ APPLYING PATCH ...
echo.

REM net stop TWS$TWS_BrowserServices 2>NUL
net stop TWS$TWS_GenericServices
REM net stop TWS$TWS_AppSharingRouterServices
REM net stop TWS$TWS_CloudServices
REM net stop TWS$TWS_ConferenceServices
REM net stop TWS$TWS_CSTAServices
REM net stop TWS$TWS_EventServices
REM net stop TWS$TWS_ESearchServices
REM net stop TWS$TWS_FlashServices
REM net stop TWS$TWS_MediaServices
REM net stop TWS$TWS_MediaSIPServices
net stop TWS$TWS_PJSIPServices
REM net stop TWS$TWS_UCCServices
REM net stop TWS$TWS_ScriptServices
REM net stop TWS$TWS_ToolkitWebServices
REM net stop TWS$TWS_VTIXMLServices
REM net stop TWS$TWS_WebAPIServices
net stop TWS$TWS_WebServices
REM net stop TWS$TWS_ASTARIServices
REM net stop TWS$TWS_FilesServices
REM net stop TWS$TWS_Database
REM net stop TWS$TWS_DatabaseFS

taskkill /F /IM TWS_GenericServices.exe 2>NUL
REM taskkill /F /IM TWS_BrowserServices.exe 2>NUL
REM taskkill /F /IM TWS_AppSharingRouterServices.exe 2>NUL
REM taskkill /F /IM TWS_CloudServices.exe 2>NUL
REM taskkill /F /IM TWS_ConferenceServices.exe 2>NUL
REM taskkill /F /IM TWS_CSTAServices.exe 2>NUL
REM taskkill /F /IM TWS_EventServices.exe 2>NUL
REM taskkill /F /IM TWS_FlashServices.exe 2>NUL
REM taskkill /F /IM TWS_MediaServices.exe 2>NUL
REM taskkill /F /IM TWS_MediaSIPServices.exe 2>NUL
taskkill /F /IM TWS_PJSIPServices.exe 2>NUL
REM taskkill /F /IM TWS_UCCServices.exe 2>NUL
REM taskkill /F /IM TWS_ScriptServices.exe 2>NUL
REM taskkill /F /IM TWS_ToolkitWebServices.exe 2>NUL
REM taskkill /F /IM TWS_VTIXMLServices.exe 2>NUL
REM taskkill /F /IM TWS_WebAPIServices.exe 2>NUL
taskkill /F /IM TWS_WebServices.exe 2>NUL
REM taskkill /F /IM TWS_ASTARIServices.exe 2>NUL
REM taskkill /F /IM TWS_FilesServices.exe 2>NUL

del /F /Q %INSTALLDIR%\TWS_Services\TWS_GenericServices\*.dll
REM del /F /Q %INSTALLDIR%\TWS_Services\TWS_EventServices\*.dll
REM del /F /Q %INSTALLDIR%\TWS_Services\TWS_WebAPIServices\*.dll
del /F /Q %INSTALLDIR%\TWS_Services\TWS_WebServices\*.dll
REM del /F /Q %INSTALLDIR%\TWS_Services\TWS_ToolkitWebServices\*.dll
REM del /F /Q %INSTALLDIR%\TWS_Services\TWS_CloudServices\*.dll
REM del /F /Q %INSTALLDIR%\TWS_Services\TWS_CSTAServices\*.dll
REM del /F /Q %INSTALLDIR%\TWS_Services\TWS_VTIXMLServices\*.dll

:: Copy files
xcopy "%CD%\data\*" %INSTALLDIR%\ /S /Y /Q
::xcopy "%CD%\tools\*" %INSTALLDIR%\TWS_Common\ /S /Y /Q

::Change version
ChangeVersion XmlServer %INSTALLDIR% %PATCH_VERSION%
::ChangeVersion XmlAddon %INSTALLDIR% %PATCH_ADDON_VERSION%

::CorFlags.exe /32BITREQ+ %INSTALLDIR%\TWS_Services\TWS_VTIXMLServices\TWS_VTIXMLServices.exe

REM iisreset

REM RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 16

REM net start TWS$TWS_Database
REM net start TWS$TWS_DatabaseFS
net start TWS$TWS_GenericServices


echo.
echo ------------------ PATCH APPLIED
echo.

pause
