@echo OFF

setlocal  enabledelayedexpansion 

cls
set envFileName=..\config\XCI_3DX_BATCH_Env.txt
if not "%~1" == "" (
	set envFileName=%~1
)

if not exist "%envFileName%" (
	echo.
	echo. Cannot find %envFileName%
	echo.
	pause
	endlocal
	exit
)
echo.
set envFileNameAbsolute=""
call :ABSOLUTE_PATH envFileNameAbsolute "%envFileName%"

echo.   3DExperience environment file:
echo.   %envFileNameAbsolute%


for /f "usebackq tokens=*" %%i in (`FINDSTR "^PATH=" "%envFileName%"`) do (
	call set %%i
)

echo. 
echo Encrypt 3DEXPERIENCE password
set /p password=type password:
cls
echo.
echo Encrypt 3DExperience password
echo type password:
echo starting encryption ...
echo.

catstart -env "%envFileName%" -run "XCIInstallationCheck -pw %password%"

echo.
echo.
if %ERRORLEVEL% EQU 0 (
	echo Please insert encrypted password in TCIXpgConfig.xml
) ELSE (
	echo Check your installation
)
echo.
echo.
pause
endlocal

exit /b

:: Build absolute path out of relative path
:ABSOLUTE_PATH
SET %1=%~f2
exit /b