@echo off
Setlocal EnableDelayedExpansion
set LOGFOLDER=flashlogs

set WORKDIR=%~dp0
cd %WORKDIR%
for /f "tokens=*" %%i in ('dir /b *.tar') do (
	set TARFILE=%%i
	break
)
for /f "tokens=*" %%i in ('dir /b *.image') do (
	set IMAGE=%%i
	break
)
mkdir %LOGFOLDER% >nul 2>&1

:loop 
cls 
color 0F 
echo Please connect FRITZ!Box via LAN and press ENTER 
pause >nul  
 
echo. 
echo Please connect the power plug of FRITZ!Box now...   

echo.
for /f %%I in ('wmic os get localdatetime ^|find "20"') do set DATETIME=%%I
set DATETIME=!DATETIME:~0,8!_!DATETIME:~8,6!

avmprovidermanager.exe -t %TARFILE% sign.sha256.bs64 %IMAGE% -to60  

if %ERRORLEVEL%==0 (
     color 0A     
     move out.txt %LOGFOLDER%\%DATETIME%_OK.txt >nul 2>&1 
) else (
     color 0E    
	 move out.txt %LOGFOLDER%\%DATETIME%_ERROR.txt >nul 2>&1 
) 
del out.codec >nul 2>&1

echo.
echo To flash another FRITZ!Box press any key. 
pause >nul   

goto loop 