@echo off

set _EXECJAVA=java
set JAVA_OPTS=-Xmx768M

rem If running JDK, uncomment to run server environment (faster)
rem set JAVA_OPTS=%JAVA_OPTS% -server

rem Uncomment to force Java to use specific language settings
rem set JAVA_OPTS=%JAVA_OPTS% -Duser.language=en -Duser.country=US -Dfile.encoding=Cp1252

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

set WMSMGRENVOK="false"

rem Guess WMSMGR_HOME if not defined
set CURRENT_DIR=%cd%
if not "%WMSMGR_HOME%" == "" goto gotAppHome
set WMSMGR_HOME=%CURRENT_DIR%
if exist "%WMSMGR_HOME%\bin\startmgr.bat" goto okAppHome
cd ..
set WMSMGR_HOME=%cd%
cd %CURRENT_DIR%
:gotAppHome
if exist "%WMSMGR_HOME%\bin\startmgr.bat" goto okAppHome
if "%~1"=="service" (
      echo setmgrenv.bat: The WMSMGR_HOME environment variable is missing or not defined correctly: "%WMSMGR_HOME%". This environment variable is needed to run the Wowza Streaming Engine Manager. >> batch.log
   ) else (
      %EXECCSCRIPT% "displaymsg.vbs" "The WMSMGR_HOME environment variable is missing or not defined correctly (%WMSMGR_HOME%). This environment variable is needed to run the Wowza Streaming Engine Manager."
   )
goto end
:okAppHome

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 JAVA_OPTS=%JAVA_OPTS%  -Dcom.wowza.wms.ConfigURL="" -Dcom.wowza.wms.ConfigHome="%WMSMGR_HOME%" -Djava.io.tmpdir="%WMSMGR_HOME%\temp" -Dlog4j.configuration="file:///%WMSMGR_HOME%\conf\winstone.properties" -Djava.net.preferIPv4Stack=true
set _EXECJAVA=%JAVA_HOME%\bin\java.exe
set WMSMGRENVOK="true"

:end
