REM UPDATE SCRIPT
cd /d "${INSTALL_PATH}${FILE_SEPARATOR}syracuse"

if exist update rmdir /S /Q update\

Call "${INSTALL_PATH}${FILE_SEPARATOR}syracuse${FILE_SEPARATOR}servicestop.cmd"
Call "${INSTALL_PATH}${FILE_SEPARATOR}syracuse${FILE_SEPARATOR}servicedelete.cmd"
call taskkill /im Agentw.exe /f /t

rem sleep 5		
ping -n 5 127.0.0.1 > null		

rem check if syracuse services are still present		
		
rem test running syracuse service 		
sc query "Sage_Syracuse_-_${component.node.name}" | find /i "RUNNING" > res.tmp		
set /p f=<res.tmp		
if "%f%" NEQ "" goto failService		
		
rem test stopping state syracuse service 		
sc query "Sage_Syracuse_-_${component.node.name}" | find /i "STOPPING" > res.tmp		
set /p f=<res.tmp		
if "%f%" NEQ "" goto failService		
		
rem test running agent service 		
sc query "Agent_Sage_Syracuse_-_${component.node.name}" | find /i "RUNNING" > res.tmp		
set /p f=<res.tmp		
if "%f%" NEQ "" goto failService		


rem test stopping state agent service 		
sc query "Agent_Sage_Syracuse_-_${component.node.name}" | find /i "STOPPING" > res.tmp		
set /p f=<res.tmp		
if "%f%" EQU "" goto ok		
		
:failService		
rem we still have the service running and test more than 3 times to stop it		
echo "services Sage_Syracuse_-_${component.node.name} or Agent_Sage_Syracuse_-_${component.node.name} can't be stopped. please stop the services manually and run again the setup" > %tmp%${FILE_SEPARATOR}exitfail.txt		
exit 1		
		
:ok		
del /F /Q res.tmp				
rem ===SAM 111711 - delete content of streamline cache folder 		
rem ===list all cache directory should look like that pattern <cacheDir>/<user> and delete the content of that dir 		
for /D %%s in ("${INSTALL_PATH}${FILE_SEPARATOR}syracuse${FILE_SEPARATOR}cache\") do (		
	rem ===delete all file in the cache/user directory		
	del /F /S /Q "%%s\*.*"  > nul 
	rem ===delete all folder under cache/user directory	
    for /f %%b IN ('dir /b /s /a:d "%%s"') DO (
		rmdir /S /Q "%%b" 
		)		
)

cd /d "${INSTALL_PATH}${FILE_SEPARATOR}syracuse"

if exist "SAGE ERP"*.txt del /F /Q "SAGE ERP"*.txt
if exist "SAGE ERP"*.htm del /F /Q "SAGE ERP"*.htm

if not exist update_backup mkdir update_backup

set tddt=%date:~6,4%%date:~3,2%%date:~0,2%%time:~0,2%%time:~3,2%%time:~6,2%%time:~9,2%

copy /Y "${syracuse.dir.binpath}${FILE_SEPARATOR}nodelocal.js" "update_backup${FILE_SEPARATOR}nodelocal.js.%tddt%"
copy /Y "${syracuse.dir.binpath}${FILE_SEPARATOR}nodelocal.js" "update_backup${FILE_SEPARATOR}nodelocal.js"

cd /d "${INSTALL_PATH}"

echo Windows Registry Editor Version 5.00 > removereg.reg
echo. >> removereg.reg
echo [-HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Syracuse - ${component.node.name}] >> removereg.reg
echo. >> removereg.reg

regedit /s removereg.reg

del /F /Q removereg.reg

exit 0