@echo off

color 0b
call bin\update.cmd
set url=https://s1.rg-adguard.net/dl/decrypt/
for /f "tokens=3 delims=:. " %%f in ('bitsadmin.exe /CREATE /DOWNLOAD "Update esd-decrypter-online-wimlib" ^| findstr "Created job"') do set GUID=%%f
echo Searching for updates...&&bitsadmin>nul /transfer %GUID% /download /priority foreground %url%/up/info_s.txt "%~dp0info.cmd"
call info.cmd
erase /s /q info.cmd >nul 2>&1
cls
if %v_ver_decrypt% NEQ %s_ver_decrypt% set udecrypt=1
if %v_ver_dism% NEQ %s_ver_dism% set udism=1
if %v_ver_wimlib% NEQ %s_ver_wimlib% set uwimlib=1
if %v_ver_keys% NEQ %s_ver_keys% set ukeys=1
if %v_ver_revision% NEQ %s_ver_revision% set urevision=1
echo  =================================================
echo  ^|  Name      ^| You version  ^|  Server version   ^|
echo  =================================================
echo  ^|  decrypt   ^|   %v_ver_decrypt%    ^|      %s_ver_decrypt%      ^|
echo  ^|  dism      ^|  %v_ver_dism%   ^|     %s_ver_dism%     ^|
echo  ^|  wimlib    ^|   %v_ver_wimlib%    ^|      %s_ver_wimlib%      ^|
echo  ^|  keys      ^|   %v_ver_keys%    ^|      %s_ver_keys%      ^|
echo  ^|  revision  ^|   %v_ver_revision%    ^|      %s_ver_revision%      ^|
echo  =================================================
if not defined udecrypt if not defined udism if not defined uwimlib if not defined ukeys if not defined urevision (color 0a&echo.  No new updates were found.&pause>nul&exit /b)
echo  Do you want to upgrade to the latest version^?
echo  Press any button to continue.
pause>nul
cls
mkdir temp
if defined udecrypt call :down7 decrypt.7z
if defined udism call :down7 dism.7z
if defined uwimlib call :down7 wimlib.7z
if defined ukeys call :downt key
if defined urevision call :downt revision
rmdir /s /q temp\ >nul 2>&1
bitsadmin>nul /transfer %GUID% /download /priority foreground %url%/up/info_v.txt "%~dp0bin\update.cmd"

:good
cls
color 0a
echo.
echo.
echo.
echo  The data was all updated to the new version.
echo.
echo.
echo.
echo  Press any key to exit.
pause >nul
exit /b

:down7
echo  Download file - %1
bitsadmin>nul /transfer %GUID% /download /priority foreground %url%/up/%1 "%~dp0temp\%1"
echo  Extrack file - %1
bin\7z.exe>nul 2>&1 x -r "%~dp0temp\%1" -o"%~dp0" -y
exit /b

:downt
echo  Update file - %1.cmd
bitsadmin>nul /transfer %GUID% /download /priority foreground %url%/up/%1.txt "%~dp0bin\%1.cmd"
exit /b