@echo off

EXIT

CALL C:\LiveDigital\config.bat

CD "C:\LiveDigital\tools\coretemp\"

IF "%var_is64%"=="1" (
	taskkill /im "CoreTemp64.exe" /F
) ELSE (
	taskkill /im "CoreTemp.exe" /F
)

FOR /f "tokens=5,6,7* delims= " %%G IN ('dir /s "C:\LiveDigital\tools\coretemp\*.csv" ^| find "/"') DO (
	SET filename=%%G %%H %%I
)

IF NOT "%filename%"=="" (
	DEL "C:\LiveDigital\tools\coretemp\%filename%"
)

IF "%var_is64%"=="1" (
	START /B /MIN C:\LiveDigital\tools\coretemp\CoreTemp64.exe
) ELSE (
	START /B /MIN C:\LiveDigital\tools\coretemp\CoreTemp.exe
)



ping 127.0.0.1 -n 10 -w 100

IF "%var_is64%"=="1" (
	taskkill /im "CoreTemp64.exe" /F
) ELSE (
	taskkill /im "CoreTemp.exe" /F
)

ping 127.0.0.1 -n 2 -w 100

FOR /f "tokens=5,6,7* delims= " %%G IN ('dir /s "C:\LiveDigital\tools\coretemp\*.csv" ^| find "/"') DO (
	SET filename=%%G %%H %%I
)

IF NOT "%filename%"=="" (
	for /f "tokens=1* delims=:" %%a in ('findstr /n .* "C:\LiveDigital\tools\coretemp\%filename%"') do (
		if "%%a"=="9" (
			SET SystemHeaders=%%b
		)
	)
	
	for /f "tokens=1* delims=:" %%a in ('findstr /n .* "C:\LiveDigital\tools\coretemp\%filename%"') do (
		if "%%a"=="10" (
			SET SystemValues=%%b
		)
	)
	
	SET %SystemHeaders=%SystemHeaders: (°)=%
	SET SystemHeaders=%SystemHeaders:(°)=%
	SET SystemHeaders=%SystemHeaders:.=%
	SET SystemHeaders=%SystemHeaders: =%
	SET SystemHeaders=%SystemHeaders:(=%
	SET SystemHeaders=%SystemHeaders:)=%

	Setlocal EnableDelayedExpansion
	SET SystemHeaders=!SystemHeaders:%%=!
	Setlocal DisableDelayedExpansion

	DEL "C:\LiveDigital\tools\coretemp\%filename%"

	IF "%var_is64%"=="1" (
		wget64.exe --delete-after "%var_pingaddress%%var_pingscript%?clientid=%var_client%&serverip=%var_supportip%&type=system-health&headers=%SystemHeaders%&values=%SystemValues%"
	) ELSE (
		wget.exe --delete-after "%var_pingaddress%%var_pingscript%?clientid=%var_client%&serverip=%var_supportip%&type=system-health&headers=%SystemHeaders%&values=%SystemValues%"
	)
)

EXIT