@echo off
verify # 2>nul
setlocal enableextensions enabledelayedexpansion
if errorlevel 1 goto CANT_SWITCH_ON_EXTENDED_CMD_PROCESSING
call #SETTINGS.cmd
if !errorlevel! neq 0 goto ERROR

if "%~0"=="!OPEN_IN_BROWSER_DEBUG.cmd" goto START
cls
echo OPENING APPLICATION IN BROWSER (DEBUG MODE):
echo ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß
echo.

:START
if not defined ProgramFiles goto PROGRAMFILES_NOT_DEF

call :EXEC_CMD start /max "" "!ProgramFiles!\Google\Chrome\Application\chrome.exe" --remote-debugging-port=9222 "!#URL_D!"
if %errorlevel% neq 0 goto ERROR

::==================================================================================================

if "%~0"=="!OPEN_IN_BROWSER_DEBUG.cmd" goto FINISH
echo.
echo ÜÜÜ DONE ÜÜÜ
goto FINISH

::==================================================================================================

:CANT_SWITCH_ON_EXTENDED_CMD_PROCESSING
echo.
echo ## Can not switch on extended command processing.
goto ERROR

:PROGRAMFILES_NOT_DEF
echo.
echo ## Environment variable not defined: "ProgramFiles".
goto :ERROR

::==================================================================================================

:EXEC_CMD
verify # 2>nul
setlocal enableextensions disabledelayedexpansion
if errorlevel 1 goto CANT_SWITCH_ON_SIMPLE_CMD_PROCESSING_RETURN_ERROR
echo ^>^> %* ...
%*
if %errorlevel% neq 0 goto END_LOCAL_RETURN_ERROR
goto END_LOCAL_RETURN_SUCCESS

:CANT_SWITCH_ON_SIMPLE_CMD_PROCESSING_RETURN_ERROR
echo.
echo ## Can not switch on simple command processing (without delayed expansion).
goto RETURN_ERROR

::==================================================================================================
:RESET_ERROR
set errorlevel=0
set errorlevel=
goto :EOF
::==================================================================================================
:RETURN_SUCCESS
set errorlevel=0
set errorlevel=
goto :EOF
:RETURN_ERROR
verify # 2>nul
goto :EOF
:END_LOCAL_RETURN_SUCCESS
endlocal
goto RETURN_SUCCESS
:END_LOCAL_RETURN_ERROR
endlocal
goto RETURN_ERROR
::==================================================================================================
:ERROR
if not "%~0"=="!OPEN_IN_BROWSER_DEBUG.cmd" (
echo 
if not "%$cmd_plain%"=="1" pause )
endlocal
verify # 2>nul
goto :EOF
:FINISH
if not "%~0"=="!OPEN_IN_BROWSER_DEBUG.cmd" if "%$cmd_plain%"=="1" echo.
endlocal
call :RESET_ERROR
goto :EOF
::==================================================================================================
