echo off

set "SCRIPTROOT=%~dp0"
set "SCRIPTROOT=%SCRIPTROOT:~0,-1%"

rem ----- Reset values to defaults -----
set "VCVER=vc14"
set "ARCH=64"
set "CASDEB="

if not ["%1"]    == [""]      set "VCVER=%1"
if not ["%2"]    == [""]      set "ARCH=%2"
if /I ["%ARCH%"] == ["win32"] set "ARCH=32"
if /I ["%ARCH%"] == ["win64"] set "ARCH=64"
if /I ["%3"]     == ["debug"] set "CASDEB=d"
if /I ["%3"]     == ["d"]     set "CASDEB=d"
if /I ["%3"]     == ["i"]     set "CASDEB=i"
if /I ["%3"]     == ["relwithdeb"] set "CASDEB=i"

if exist "%~dp0custom.bat" (
  call "%~dp0custom.bat" %VCVER% %ARCH% %CASDEB%
)

rem for compatability with external application using CASROOT
if ["%CASROOT%"] == [""] set "CASROOT=%SCRIPTROOT%"
set "PRODROOT="

if not ["%TCL_DIR%"] == [""]           set "PATH=%TCL_DIR%;%PATH%"
if not ["%TK_DIR%"] == [""]            set "PATH=%TK_DIR%;%PATH%"
if not ["%FREETYPE_DIR%"] == [""]      set "PATH=%FREETYPE_DIR%;%PATH%"
if not ["%FREEIMAGE_DIR%"] == [""]     set "PATH=%FREEIMAGE_DIR%;%PATH%"
if not ["%FREEIMAGEPLUS_DIR%"] == [""] set "PATH=%FREEIMAGEPLUS_DIR%;%PATH%"
if not ["%GL2PS_DIR%"] == [""]         set "PATH=%GL2PS_DIR%;%PATH%"
if not ["%TBB_DIR%"] == [""]           set "PATH=%TBB_DIR%;%PATH%"
if not ["%VTK_DIR%"] == [""]           set "PATH=%VTK_DIR%;%PATH%"

rem ----- Set path to 3rd party and OCCT libraries -----
if not "%CSF_OCCTBinPath%" == "" (
  set "PATH=%CSF_OCCTBinPath%;%PATH%"
)

if not ["%TK_DIR%"] == ["%TCL_DIR%"] (
  if not ["%TK_DIR%"] == [""]  set "TK_LIBRARY=%TK_DIR%/../lib/tk%TK_VERSION_WITH_DOT%"
  if not ["%TCL_DIR%"] == [""] set "TCL_LIBRARY=%TCL_DIR%/../lib/tcl%TCL_VERSION_WITH_DOT%"
)

rem ----- Set envoronment variables used by OCCT -----
set  CSF_LANGUAGE=us
set  MMGT_CLEAR=1
set "CSF_SHMessage=%CSF_OCCTResourcePath%\SHMessage"
set "CSF_MDTVTexturesDirectory=%CSF_OCCTResourcePath%\Textures"
set "CSF_ShadersDirectory=%CSF_OCCTResourcePath%\Shaders"
set "CSF_XSMessage=%CSF_OCCTResourcePath%\XSMessage"
set "CSF_TObjMessage=%CSF_OCCTResourcePath%\TObj"
set "CSF_StandardDefaults=%CSF_OCCTResourcePath%\StdResource"
set "CSF_PluginDefaults=%CSF_OCCTResourcePath%\StdResource"
set "CSF_XCAFDefaults=%CSF_OCCTResourcePath%\StdResource"
set "CSF_TObjDefaults=%CSF_OCCTResourcePath%\StdResource"
set "CSF_StandardLiteDefaults=%CSF_OCCTResourcePath%\StdResource"
set "CSF_UnitsLexicon=%CSF_OCCTResourcePath%\UnitsAPI\Lexi_Expr.dat"
set "CSF_UnitsDefinition=%CSF_OCCTResourcePath%\UnitsAPI\Units.dat"
set "CSF_IGESDefaults=%CSF_OCCTResourcePath%\XSTEPResource"
set "CSF_STEPDefaults=%CSF_OCCTResourcePath%\XSTEPResource"
set "CSF_XmlOcafResource=%CSF_OCCTResourcePath%\XmlOcafResource"
set "CSF_MIGRATION_TYPES=%CSF_OCCTResourcePath%\StdResource\MigrationSheet.txt"

rem Draw Harness special stuff
if exist "%CSF_OCCTResourcePath%\DrawResources" (
  set "DRAWHOME=%CSF_OCCTResourcePath%\DrawResources"
  set "CSF_DrawPluginDefaults=%CSF_OCCTResourcePath%\DrawResources"

  if exist "%CSF_OCCTResourcePath%\DrawResources\DrawDefault" (
    set "DRAWDEFAULT=%CSF_OCCTResourcePath%\DrawResources\DrawDefault"
  )
)
