@echo off
rem
rem Find the application home.
rem
if "%OS%"=="Windows_NT" goto nt

echo This is not NT, so please edit this script and set _APP_HOME manually
set _APP_HOME=..

goto conf

:nt
rem %~dp0 is name of current script under NT
set _APP_HOME=%~dp0
rem : operator works similar to make : operator
set _APP_HOME=%_APP_HOME:\bin\=%
echo %_APP_HOME%

rem
rem Decide on the specific Wrapper binary to use
rem
if "%PROCESSOR_ARCHITEW6432%"=="AMD64" goto amd64
if "%PROCESSOR_ARCHITECTURE%"=="AMD64" goto amd64
set _WRAPPER_L_EXE=%_APP_HOME%\bin\wrapper-windows-x86-32.exe
goto search
:amd64
set TEMP_FILE=%TEMP%\javaCheck%RANDOM%%TIME:~9,5%.txt 
java -version 2>%TEMP_FILE% 
FOR /F "tokens=*" %%i in (%TEMP_FILE%) do (
   echo %%i | find "HotSpot" >nul
   if not errorlevel 1 (
    echo %%i | find "64-Bit" >nul
    if not errorlevel 1 (
      set _WRAPPER_L_EXE=%_APP_HOME%\bin\wrapper-windows-x86-64.exe     
    ) else (
      set _WRAPPER_L_EXE=%_APP_HOME%\bin\wrapper-windows-x86-32.exe     
    )   
   )
)   
del %TEMP_FILE% 
goto search
:search
set _WRAPPER_EXE=%_WRAPPER_L_EXE%
if exist "%_WRAPPER_EXE%" goto conf
set _WRAPPER_EXE=%_APP_HOME%\bin\Wrapper.exe 
if exist "%_WRAPPER_EXE%" goto conf
echo Unable to locate a Wrapper executable using any of the following names:
echo %_WRAPPER_L_EXE%
echo %_WRAPPER_EXE%
pause
goto :eof

rem
rem Find the wrapper.conf
rem
:conf
set _WRAPPER_CONF="%~f1"
if not %_WRAPPER_CONF%=="" goto startup
set _WRAPPER_CONF="%_APP_HOME%\conf\wrapper.conf"


rem
rem Run the application.
rem At runtime, the current directory will be that of Wrapper.exe
rem
:startup
echo Punch MW (WebApps) Started
"%_WRAPPER_EXE%" -c %_WRAPPER_CONF%
if not errorlevel 1 goto end
pause

:end
set _APP_HOME=
set _WRAPPER_CONF=

