@Echo off
REM #New: 12.12.2013/J.Fes
REM #LUp: 19.11.2020/J.Fes add template %BinPublic_DP_lp%\ConnectNetUnc.cmd
REM #LUp: 04.12.2020/J.Fes add :UseDrive  :JobMgrLSet
REM #LUp: 20.04.2021/J.Fes add :setCustomEnvironment

REM #Doc: in this script Customer can define own variables
REM #Doc: befor PLMJobManagerComponents are starting
REM #Doc: with variable JobMgr_RootL_DP you can define
REM       where JobManager put Software Component localy on JobComputers
REm #Doc

rem #New : 18.02.2024 default JobMgr UserName
rem #ToDo: setup JobMgr_UserName if required #Exa: addPLM:J.Fes addPLM:A.Stein addPLM:S.Gueth
if not defined JobMgr_UserName set JobMgr_UserName=addPLM

set BinPublic_DP_lp=%~dp0..\03-BinPublic
call "%BinPublic_DP_lp%\ColorSet.cmd" Init

rem call :UseDrive "%~1"
call :JobMgrLSet
rem Call :setCustomEnvironment

if /I "%~1" equ "Init" pause

goto :eof

rem ----------------------------------------------------------------------------
:UseDrive
 rem #todo set environment for set JobMgr environment
 set JobMgr_Root_D=J:
 set JobMgr_Root_UNC=\\#CustomServer#\#PLMJobMgrRoot#
 set JobMgr_Root_TP=JobManagerV3_T
 set JobMgr_Root_DP=%JobMgr_Root_D%\%JobMgr_Root_TP%
 set JobMgr_Root_Toolbar_DP=%JobMgr_Root_DP%\_%JobMgr_Root_TP%

 REM -- #Doc: map drive
 Call "%BinPublic_DP_lp%\ConnectNetUnc.cmd" "JobMgr Root %JobMgr_Root_D% to %JobMgr_Root_DP%" %JobMgr_Root_D% "%JobMgr_Root_UNC%" . . JobMgr_RootDrive_ConnectStatus

 if /I "%JobMgr_RootDrive_ConnectStatus%" neq "OK" (
  set JobMgr_Root_DP=
 )

 if /I "%~1" equ "Init" (
   call "%BinPublic_DP_lp%\ColorSet.cmd" %JobMgr_RootDrive_ConnectStatus%
   Echo ----------------------------------------------------------------------------
   Echo JobMgr Base...........................: Initialisation
   Echo JobMgr RootDrive ConnectStatus........: %JobMgr_RootDrive_ConnectStatus%
   Echo JobMgr Root UNC.......................: %JobMgr_Root_UNC%
   Echo JobMgr Root DP........................: %JobMgr_Root_DP%
   Echo JobMgr Toolbar Info...................: please add JobMgr Toolbar to your windwos taskbar
   Echo JobMgr Toolbar location...............: %JobMgr_Root_Toolbar_DP%
   Echo JobMgr Toolbar location value is in...: your windows clipboard
   Echo %JobMgr_Root_Toolbar_DP%|Clip
 )

goto :eof

rem ----------------------------------------------------------------------------
:setCustomEnvironment
 REM -- #New: 20.04.2021/J.Fes
 Echo -- Set Custom Environment ------------------------------------------------
 rem if not defined UGII_SITE_DIR Call :setEnv UGII_SITE_DIR "S:\nx\ugii"
 goto :eof

rem ----------------------------------------------------------------------------
:setEnv
 Echo set %1=%~2
 set %1=%~2
 rem call "%CmdCurRoot_DP$tmp%\setx.exe" %1 "" -m
 rem call "%CmdCurRoot_DP$tmp%\setx.exe" %1 %~2 -m
 rem Echo call "%CmdCurRoot_DP$tmp%\setx.exe" %1 %~2
 if /I "%Mode%" neq "BATCH"  (
    call setx.exe %1 "%~2"
 )
 goto :eof

rem ----------------------------------------------------------------------------
:JobMgrLSet
REM Set JobMgr local workspace directory

REM #Exa: 1
REM set JobMgr_RootL_DP=C:\tmp\JobMgrL_T
REM if exist D: set JobMgr_RootL_DP=D:\JobMgrL_T

REM #Exa: 2 for defined computers
REM if /I "%ComputerName%" equ "ComputerName01" set JobMgr_RootL_DP=C:\tmp\JobMgrL_T
REM if /I "%ComputerName%" equ "ComputerName02" set JobMgr_RootL_DP=C:\tmp\JobMgrL_T

REM #Exa: 3 first try use D: then second try use C:
if not defined JobMgr_RootL_DP Call "%~dp0..\03-BinPublic\DirChkCreate.cmd" D: "JobMgrL_T" JobMgr_RootL_DP
if not defined JobMgr_RootL_DP Call "%~dp0..\03-BinPublic\DirChkCreate.cmd" C: "JobMgrL_T" JobMgr_RootL_DP
goto :eof

