@echo OFF

rem This tool can be used to check if your login ticket is valid on your 3DExperience server
rem
rem When using this tool you are asked for the 3DExperience server url and for the login ticket.
rem When used without arguments, this tool uses the default 3DExperience environment file:
rem ..\config\XCI_3DX_BATCH_Env.txt
rem To use a different environment file you can pass the full path of the environment file as
rem as argument. It is also possible to drag and drop the environment file on this utility. 
rem
rem use 3DX tool CATPLMxLoginTest to check if the login ticket is valid

setlocal  enabledelayedexpansion 

cls
echo.


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%
echo.   Log file:
echo.   %temp%\XCIInstallationCheck.log 

echo.


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

echo Check login to server using LoginTicket 
set /p url=type server url: 
set /p loginTicket=type LoginTicket: 


echo.
catstart -env "%envFileName%" -run "CATPLMxLoginTest -err=%temp%\CATPLMxLoginTest_err.txt -pid=%temp%\CATPLMxLoginTest_pid.txt -url=%url% -tk=%loginTicket% -reconnect"

echo.
echo.
pause
endlocal

exit /b

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