REM UPDATE SCRIPT
setlocal enabledelayedexpansion


cd /d "${INSTALL_PATH}${FILE_SEPARATOR}syracuse"
rem try to move the bin folder to bin2 if it works we remove the bin2 folder else we raise an error 

for  %%v in ( 10 9 8 7 6 5 4 3 2 1) do (
  move "${syracuse.dir.binpath}"  "${syracuse.dir.binpath}2" 
  if !ERRORLEVEL! equ 0 goto :STEP1
  echo wait 5s more : service starts
  ping -n 5 127.0.0.1 >nul
)
echo "can't move ${syracuse.dir.binpath} directory, please check if a process or syracuse services are still running or use this directory, and run again the setup" > %tmp%${FILE_SEPARATOR}exitfail.txt
exit /b 1


:STEP1
rem Waiting 5s before verify bin deleted 
for  %%v in (20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1) do (
	if not exist "${syracuse.dir.binpath}" goto :DELBIN
	echo wait 5s more : service starts
	ping -n 20 127.0.0.1 >nul
)
move "${syracuse.dir.binpath}2\*" "${syracuse.dir.binpath}\"
echo "can't delete ${syracuse.dir.binpath} directory, please check if a process or syracuse services are still running or use this directory, and run again the setup" > %tmp%${FILE_SEPARATOR}exitfail.txt
exit /b 2

:DELBIN
rem else
mkdir vide
rem rmdir /S /Q "${syracuse.dir.binpath}2\"
robocopy /mir vide  "${syracuse.dir.binpath}2" >nul 2>&1
rmdir /S /Q "${syracuse.dir.binpath}2\"
rmdir /S /Q vide
for  %%v in (20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1) do (
	if not exist "${syracuse.dir.binpath}2" goto :DELBIN2
	echo wait 5s more : service starts
	ping -n 5 127.0.0.1 >nul
)
echo "can't delete ${syracuse.dir.binpath}2 directory, please check if a process or syracuse services are still running or use this directory, and run again the setup" > %tmp%${FILE_SEPARATOR}exitfail.txt
exit /b 3

:DELBIN2
rem normal behavior exit 0
exit 0
