@echo off

set _EXECJAVA=java

rem Setting of JAVA_OPTS has moved to conf/Tune.xml

set EXECCSCRIPT=cscript
if not exist "%SystemRoot%\SysWOW64\cscript.exe" goto skip64bitcscript
set EXECCSCRIPT="%SystemRoot%\SysWOW64\cscript.exe"
:skip64bitcscript

set WMSENVOK="false"

rem Guess WMSAPP_HOME if not defined
set CURRENT_DIR=%cd%
if not "%WMSAPP_HOME%" == "" goto gotAppHome
set WMSAPP_HOME=%CURRENT_DIR%
if exist "%WMSAPP_HOME%\bin\startup.bat" goto okAppHome
cd ..
set WMSAPP_HOME=%cd%
cd %CURRENT_DIR%
:gotAppHome
if exist "%WMSAPP_HOME%\bin\startup.bat" goto okAppHome

if "%~1"=="service" (
      echo setenv.bat: The WMSAPP_HOME environment variable is missing or not defined correctly: "%WMSAPP_HOME%". This environment variable is needed to run the server. >> batch.log
   ) else (
      %EXECCSCRIPT% "displaymsg.vbs" "The WMSAPP_HOME environment variable is missing or not defined correctly (%WMSAPP_HOME%). This environment variable is needed to run the server."
   )
goto end
:okAppHome

rem Guess WMSCONFIG_HOME if not defined
set CURRENT_DIR=%cd%
if not "%WMSCONFIG_HOME%" == "" goto gotConfigHome
set WMSCONFIG_HOME=%WMSAPP_HOME%
if exist "%WMSCONFIG_HOME%\conf\Server.license" goto okConfigHome
cd ..
set WMSCONFIG_HOME=%cd%
cd %CURRENT_DIR%
:gotConfigHome
if exist "%WMSCONFIG_HOME%\conf\Server.license" goto okConfigHome
if "%~1"=="service" (
      echo setenv.bat: The WMSCONFIG_HOME environment variable is missing or not defined correctly: "%WMSCONFIG_HOME%". This environment variable is needed to run the server. >> batch.log
   ) else (
      %EXECCSCRIPT% "displaymsg.vbs" "The WMSCONFIG_HOME environment variable is missing or not defined correctly (%WMSCONFIG_HOME%). This environment variable is needed to run the server."
   )
goto end
:okConfigHome

if "%~1"=="service" (
      if "%JAVA_HOME%"=="" (
            echo setenv.bat: JAVA_HOME is not set. "%JAVA_HOME%" >> batch.log
            goto end
         )
      if NOT EXIST "%JAVA_HOME%\bin\java.exe" (
            echo setenv.bat: JAVA_HOME is set incorrectly?.  "%JAVA_HOME%" >> batch.log
            goto end
         )
      echo setenv.bet: JAVA_HOME is: "%JAVA_HOME%" >> batch.log
   ) else ( 
      %EXECCSCRIPT% "checkjavahome.vbs" //Nologo
      if not %errorlevel% == 0 goto end
   )

set WMSENVOK="true"
set _EXECJAVA=%JAVA_HOME%\bin\java.exe

:end
