@echo off
setlocal

set _WRAPPER_BASE=wrapper

set _WRAPPER_CONF_DEFAULT=config/wrapper.conf

rem Do not modify anything beyond this point
rem -----------------------------------------------------------------------------

if "%OS%"=="Windows_NT" goto nt
echo This script only works with NT-based versions of Windows.
goto :eof

:nt
rem
rem Find the application home.
rem
rem %~dp0 is location of current script under NT
set _REALPATH=%~dp0

if "%PROCESSOR_ARCHITECTURE%"=="AMD64" goto amd64
if "%PROCESSOR_ARCHITECTURE%"=="IA64" goto ia64
set _WRAPPER_L_EXE=%_REALPATH%%_WRAPPER_BASE%-windows-x86-32.exe
goto search
:amd64
set _WRAPPER_L_EXE=%_REALPATH%%_WRAPPER_BASE%-windows-x86-64.exe
goto search
:ia64
set _WRAPPER_L_EXE=%_REALPATH%%_WRAPPER_BASE%-windows-ia-64.exe
goto search
:search
set _WRAPPER_EXE=%_WRAPPER_L_EXE%
if exist "%_WRAPPER_EXE%" goto conf
set _WRAPPER_EXE=%_REALPATH%%_WRAPPER_BASE%.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="%_WRAPPER_CONF_DEFAULT%"

rem
rem Start the Wrapper
rem
:startup
"%_WRAPPER_EXE%" -i %_WRAPPER_CONF%


if not errorlevel 1 goto :startserv

echo *** ErrorLevel = %errorlevel% :
echo problem occurs, see the message above.
echo If you are using Windows Vista or above, please be sure you are running by:
echo   right click "InstallApp-NT.bat", choose "run as administrator"
pause
goto :eof

:startserv
NET START "Dragoncat BI Service"
if %errorlevel% == 0 goto :eof
echo *** ErrorLevel = %errorlevel% :
echo The Windows Service cannot be started. Please refer the message above & windows event log.
REM or you can use sc command to start the service:
REM sc config "Dragoncat BI Service" obj= LocalSystem\<UserName> password= <password>
REM sc start "Dragoncat BI Service"
pause

