@Echo off
 REM #New: 03.12.2018 Script to run NXCheckBox extract

 set CmdCurRoot_DP=%~dp0
 set CmdCurRoot_DP=%CmdCurRoot_DP:~0,-1%

 call :InfoEnv "#DeleteLog#"
 call :InfoEnv UG
 call :InfoEnv JobMgr
 call :InfoEnv NXCB
 call :InfoEnv CB
 call :InfoEnv ""


if /i "%JobMgr_Debug%" neq "ON" goto :JumbOverDebug
 REM set toRun=%toRun% -verbose -pauseOnEnd
 set toRunForPrint=%toRun:"='%
 call Echo "---------------------------------------------------------------------------"
 call Echo "#Debug..........................: %~0"
 call Echo "#JobMgr_CBMgrUsesCBVerDef.......: %JobMgr_CBMgrUsesCBVerDef%"
 call Echo "#JobMgr_NX_VerUse...............: %JobMgr_NX_VerUse%"
 call Echo "#NXCB_UseLoadOpt_p..............: %NXCB_UseLoadOpt_p%"
 call Echo "#NxCB_ResData_DP................: %NxCB_ResData_DP%"
 call Echo "#CBConfigXml....................: %CBConfigXml%"
 pause
:JumbOverDebug

REM  set temp=%JobMgr_Log_DP%
REM  set tmp=%temp%
REM  goto :next


:next

 rem -- #Doc: goto requested CB Version
 rem -- #Step: verzweigen in die jeweilige version des CB Vorgangs
 if /i "%JobMgr_CBMgrUsesCBVerDef%" equ "CB1" call :JobMgr_CBMgrUsesCB1
 if /i "%JobMgr_CBMgrUsesCBVerDef%" equ "CB2" call :JobMgr_CBMgrUsesCB2

 goto :eof
rem ============================================================================
:JobMgr_CBMgrUsesCB1
 setlocal
 REM #Doc.: Get CBData-1 with NX?? Version
 if /i "%JobMgr_Debug%" neq "ON" goto :JumbOver
  Echo #Debug:
  Echo Start executing: [JobMgr_CBMgrUsesCBVerDef_Ver1]
  pause
:JumbOver
  rem -- #Doc: setup NX environment
  call :JobMgr_NX_VerUseSet "%JobMgr_NX_VerUse%"

  rem -- #Doc: now extract CB Data with VER1
  Call "%CmdCurRoot_DP%\NXCB_Execute.cmd"

 if /i "%JobMgr_Debug%" neq "ON" goto :JumbOverDebug
  call Echo "---------------------------------------------------------------------------"
  call Echo "#Debug..........................: After CBRun"
  pause
:JumbOverDebug

endlocal
goto :eof

rem ============================================================================
:JobMgr_CBMgrUsesCB2
setlocal
 REM #Doc.: Get CBData-2 with NX?? Version

 if /i "%JobMgr_Debug%" neq "ON" goto :JumbOver
  Echo #Debug:
  Echo Start executing: [JobMgr_CBMgrUsesCBVerDef_Ver2]
  Pause
:JumbOver

  rem -- #Doc: setup NX environment
  call :JobMgr_NX_VerUseSet "%JobMgr_NX_VerUse%"

  rem -- #Doc: now extract CB Data with VER2
  Call "%CmdCurRoot_DP%\NXCB_Execute.cmd"

 if /i "%JobMgr_Debug%" neq "ON" goto :JumbOverDebug
  call Echo "---------------------------------------------------------------------------"
  call Echo "#Debug..........................: After CBRun"
  pause
:JumbOverDebug

endlocal
goto :eof

rem ----------------------------------------------------------------------------
:JobMgr_NX_VerUseSet
  REM -- set Custom.Environ
  if /i "%JobMgr_NX_VerUse%" equ "NX075" call :JobMgr_NX_VerUse1
  if /i "%JobMgr_NX_VerUse%" equ "NX110" call :JobMgr_NX_VerUse2
 goto :eof

:JobMgr_NX_VerUse1
  rem Call "%CmdCurRoot_DP%\NX075_SetEnv_Custom.cmd"
 goto :eof

:JobMgr_NX_VerUse2
  rem Call "%CmdCurRoot_DP%\NX110_SetEnv_Custom.cmd"
 goto :eof

rem ----------------------------------------------------------------------------
:InfoEnv
  setlocal
  set P1=%~1
  set P2=%~2
  set JobMgr_$Log_DPNE=%JobMgr_Log_DP%\90-EnvStart.txt
  if "%P1%" equ "#DeleteLog#" goto :DeleteFile

  if not defined P2 set P2=%P1%
  if not defined P2 set P2=All Variables
  Echo ## - - - - - - - - ## %P2% ## - - - - - - - - ##>>"%JobMgr_$Log_DPNE%"
  set %P1%>>"%JobMgr_$Log_DPNE%"
  goto :MyEnd

  :DeleteFile
   del "%JobMgr_$Log_DPNE%"

  :MyEnd
  endlocal
 goto :eof
