@echo off
pushd %~dp0
REM ====================Check FW Version And Update==============================
REM ===============================Config========================================

set "UpdateVersion=9.0"
set "FWBin=9v3.bin"
set "Tool=bin\TypeCDump.exe"
set "FileName=bin\TypeCDump.log"

REM ===============================Script========================================
set "CurVersion="

if exist %FileName% (
	del %FileName%
)

%Tool% -v -t 1
if %ERRORLEVEL% NEQ 0 (
	goto Exit
) 

setlocal EnableDelayedExpansion

for /f "tokens=2 delims=()" %%a in ('findstr /i "Current FwVersion is" "%FileName%"') do (
    set "CurVersion=%%a"
)

if defined CurVersion (
    REM echo !CurVersion!
	if !CurVersion! gtr %UpdateVersion% (
		echo Current version matches the main chipset, update starting
		goto Update
    ) else (
		echo Current version doesn't match the main chipset, update stopped
		goto Exit
	)
) else (
    echo Version not found.
	goto Exit
)

:Update
%Tool% -x -f 0 -t 1 %FWBin%

:Exit
pause