@echo off

rem ---------------------------------------------------------------------------
rem Please customize following variables for your environment.
rem
rem Installation directory of COMReconV5.
rem Example: C:\TCI\170823_COMReconV5_R27
set COMRECONV5_INSTALL_DIR=
rem 
rem Installation directory of CATIA.
rem Example: C:\Program Files\Dassault Systemes\B27
set CATIA_BASEDIR=
rem
rem Directory where to find CATIA env-files.
rem Example: C:\TSI\CATEnv
set CONVERTER_ENVDIR=
rem
rem Filename (without extension) that will be used by CATIA batch client.
rem Example: COMReconV5_R27
set CONVERTER_ENVFILE=
rem
rem STOP EDIT HERE
rem ---------------------------------------------------------------------------

rem ----------------------------------------------------
rem Script to start COMReconV5 utility 
rem
rem =============
rem GENERAL NOTES 
rem =============
rem
rem    This script can be used to run COMReconV5 in order to synchronize a V5 structure
rem    from an XPDM file 
rem 
rem      Usage: COMReconV5.bat <Full path of option file>"
rem
rem    NOTE : If a file name or path contains blanks, please quote it with (") as follows:
rem 
rem             COMReconV5.bat "<path with blanks>"
rem 
rem    NOTE : Please use the correct upper/lower casing for the input parameter!
rem
rem    IT IS HIGHLY RECOMMENDED TO HAVE CATIA INSTALLED IN A PATH NOT CONTAINING BLANKS !
rem
rem ===============
rem TROUBLESHOOTING
rem ===============
rem
rem    In case of errors
rem    1) Please carefully read the output of the utility
rem    2) If the executable ('CxpBatch.exe') does not start at all,
rem       gives license issues, or any other issues show up
rem
rem       COMReconV5 can start/finish successfully if the following console output shows up:
rem
rem       @@ INFO    : Starting V5 Processing via COMReconV5 (R289)
rem       .....
rem       @@ INFO    : Finished deleting  the CATIA V5 session
rem
rem ----------------------------------------------------

set USAGE1="@@ INFO    : Usage: COMReconV5 <Full path of option file>"
set USAGE2="@@ INFO    : Please quote 'blanky' paths and avoid uppercase/lowercase differences !"

if EXIST %1% GOTO CONTINUE1
echo %USAGE1%
echo %USAGE2%
echo "@@ WARNING : >%1%< does not exist"
set retval=250

GOTO END
:CONTINUE1

set RELEASE=B25

rem ----------------------------------------------------
rem Platform settings
rem ----------------------------------------------------
set OS=win_b64

rem ----------------------------------------------------
rem Setup the path INSTALL_DIR to the COMReconV5 install path
rem ----------------------------------------------------
set INSTALL_DIR=%COMRECONV5_INSTALL_DIR%

rem ----------------------------------------------------
rem Setup the path EXECUTABLE_DIR to the CxpBatch.exe executable
rem ----------------------------------------------------
set EXECUTABLE_DIR=%INSTALL_DIR%\%OS%
set EXECUTABLE=%EXECUTABLE_DIR%\CxpBatch.exe

IF EXIST %EXECUTABLE% GOTO CONTINUE5
echo "@@ WARNING : >%EXECUTABLE%< does not exist"
echo "@@ WARNING : please adjust the variable INSTALL_DIR in this script"
GOTO END
:CONTINUE5

set INFILE=%1%

set FULLSUBCOMMAND=%EXECUTABLE% %INFILE%

rem ----------------------------------------------------
rem Setup the V5 installation path, typically sth like >C:\Programs\DassaultSystemes\%RELEASE%<
rem IT IS HIGHLY RECOMMENDED TO HAVE CATIA INSTALLED IN A PATH NOT CONTAINING BLANKS !
rem ----------------------------------------------------

set CATIA_BASE_DIR=%CATIA_BASEDIR%
set CATSTART="%CATIA_BASE_DIR%\%OS%\code\bin\CATSTART.exe"

IF EXIST %CATSTART% GOTO CONTINUE3
echo "@@ WARNING : >%CATSTART%< does not exist"
echo "@@ WARNING : please adjust the variable CATIA_BASE_DIR in this script"
GOTO END
:CONTINUE3

rem ---------------------------------------------------
rem Extend the PATH to CATIA and COMReconV5 installation
rem ---------------------------------------------------
set PATH=%PATH%;%CATIA_BASE_DIR%\%OS%\code\bin;%CXP_BIN_FOLDER%;%EXECUTABLE_DIR%;

rem ---------------------------------------------------
rem PROSTEP toolkit configuration
rem ---------------------------------------------------
set COMFOX_TOOLKIT_DIR=%INSTALL_DIR%\resources\%OS%
set COMFOX_TOOLKIT_CONFIG=%INSTALL_DIR%\resources\%OS%\toolkit\config.txt
set CXP_TOOLKIT_DIR=%COMFOX_TOOLKIT_DIR%
set CXP_TOOLKIT_CONFIG=%COMFOX_TOOLKIT_CONFIG%
set CXP_CDA_LIB=catupdate_cdalib

rem ----------------------------------------------------
rem (by default, FULLCATIACOMMAND_NO_EXPLICIT_ENV below is used, so these ENVFILE* vars are not needed)
rem
rem ENVFILE_DIR : The CATIA environment file path
rem Typically, this is >C:\Documents and Settings\All Users\Application Data\DassaultSystemes\CATEnv<
rem 
rem ENVFILE     : The CATIA environment file name
rem Typically, this is >CATIA.V5R16.B16.txt< , and catstart does not need this setting explicitly
rem For test purposes you can also use the provided file CATIAB%RELEASE%env_%OS%.txt , 
rem BUT you will have to adapt the paths to the CATIA installation in it !!
rem ----------------------------------------------------

set ENVFILE_DIR=%CONVERTER_ENVDIR%
set ENVFILE=%CONVERTER_ENVFILE%

IF EXIST %ENVFILE_DIR%\%ENVFILE%.txt GOTO CONTINUE4
echo "@@ WARNING : >%ENVFILE%< does not exist"
echo "@@ WARNING : when using FULLCATIACOMMAND_WITH_EXPLICIT_ENV, you have to adjust the variables ENVFILE_DIR/ENVFILE in this script"
:CONTINUE4

set FULLCATIACOMMAND_WITH_EXPLICIT_ENV=%CATSTART% -direnv %ENVFILE_DIR% -env %ENVFILE% -run 
set FULLCATIACOMMAND_NO_EXPLICIT_ENV=%CATSTART% -run 

set FULLCOMMAND=%FULLCATIACOMMAND_WITH_EXPLICIT_ENV% "%FULLSUBCOMMAND%"

rem
rem ----------------------------------------------------
rem Finally do the deed!
rem ----------------------------------------------------
echo @@ INFO    : --------------------------------------
echo @@ INFO    : Starting the process: 
echo @@ INFO    : %FULLCOMMAND%
echo @@ INFO    : --------------------------------------

%FULLCOMMAND% 

set retval=%ERRORLEVEL%

:END
echo "@@ INFO    : Done with COMReconV5 ..."


exit /b %retval%
