@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"=="START_SERVER_DX.cmd" goto START
cls
echo STARTING THE SERVER (DEBUG-EXPOSE):
echo ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß

:START
if not exist "!#TargetModulePath_D!" goto TARGET_MODULE_NOT_FOUND

set ASPNETCORE_ENVIRONMENT=DebugExpose
call :EXEC_CMD start!#StartCmdKeys! "!#BaseTitle! (DebugExpose)" /D "!CD!" "!#TargetModulePath_D!"!#StartArgs_Auto! %*
rem call :EXEC_CMD start!#StartCmdKeys! "!#BaseTitle! (Debug)" /D "!CD!" dotnet run -c Debug "!#TargetModulePath_D!"!#StartArgs_Auto! %*
if !errorlevel! neq 0 goto ERROR

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

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

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

:TARGET_MODULE_NOT_FOUND
echo.
echo ## Target module not found: "!#TargetModulePath_D!".
goto ERROR

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

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

:EXEC_CMD
verify # 2>nul
setlocal enableextensions disabledelayedexpansion
if errorlevel 1 goto CANT_SWITCH_ON_SIMPLE_CMD_PROCESSING_RETURN_ERROR
echo.
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"=="START_SERVER_DX.cmd" (
echo 
if not "%$cmd_plain%"=="1" pause )
endlocal
verify # 2>nul
goto :EOF
:FINISH
if not "%~0"=="START_SERVER_DX.cmd" if "%$cmd_plain%"=="1" echo.
endlocal
call :RESET_ERROR
goto :EOF
::==================================================================================================
