@echo off
setlocal

if "%~0"=="SAVE_OUTPUT_X86_R.cmd" goto START
cls
echo SAVING OUTPUT (X86/RELEASE):
echo ßßßßßßßßßßßßßßßßßßßßßßßßßßßß

:START
call #SETTINGS.cmd
if %errorlevel% neq 0 goto FAILURE

if not exist "%#TargetModulePath_x86_R%" goto TARGET_MODULE_NOT_FOUND

call :DELETE_FILE "%#OutputFileName%"
if %errorlevel% neq 0 goto FAILURE

echo.
echo * Saving console output to: "%#OutputFileName%" ...

call $PREPARE_UNICODE_OUTPUT.cmd "%#OutputFileName%"
if %errorlevel% neq 0 goto FAILURE

"%#TargetModulePath_x86_R%" %* >> "%#OutputFileName%"
if %errorlevel% neq 0 goto FAILURE

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

:SUCCESS
if "%~0"=="SAVE_OUTPUT_X86_R.cmd" goto FINISH
echo.
echo ÜÜÜ SAVE OUTPUT (RELEASE) ÄÄ SUCCESS ÜÜÜ
goto FINISH

:FAILURE
if "%~0"=="SAVE_OUTPUT_X86_R.cmd" goto ERROR
echo.
echo ÜÜÜ ## SAVE OUTPUT (RELEASE) ÄÄ FAILURE ÜÜÜ
goto ERROR

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

:TARGET_MODULE_NOT_FOUND
echo.
echo ## Target module not found: "%#TargetModulePath_x86_R%".
goto ERROR

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

:DELETE_FILE
call :RESET_ERROR
if not exist "%~1" goto :EOF
echo.
echo * Deleting file: "%~1" ...
del /q "%~1"
if not exist "%~1" goto :EOF
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
rem :END_LOCAL_RETURN_SUCCESS
rem endlocal
rem goto RETURN_SUCCESS
rem :END_LOCAL_RETURN_ERROR
rem endlocal
rem goto RETURN_ERROR
::==================================================================================================
:ERROR
endlocal
if not "%~0"=="SAVE_OUTPUT_X86_R.cmd" (
echo 
if not "%$cmd_plain%"=="1" pause )
:FINISH
endlocal
if not "%~0"=="SAVE_OUTPUT_X86_R.cmd" (
echo.
if not "%$cmd_plain%"=="1" pause )
call :RESET_ERROR
goto :EOF
::==================================================================================================
