@ECHO OFF
SETLOCAL

REM Skip this script as a pre-build command if running under Jenkins.
IF "%~1" == "" IF NOT "%JENKINS_SERVER_COOKIE%" == "" EXIT /B 0

SET T=%TEMP%\%RANDOM%

ECHO Checking for new test files...
CD /D "%~dp0"
MD %T%
FIND "TEST" ..\Win32LibTest\*.cpp | cscript //nologo PreBuild.js %T%
IF EXIST main.h (
	COPY *.h+main.inl %T%\old > nul
	COPY %T%\*.h+%T%\main.inl %T%\new > nul
	FC %T%\old %T%\new > nul
	IF ERRORLEVEL 1 (
		ECHO Updating test files
		DEL /F /Q %T%\old
		DEL /F /Q %T%\new
		MOVE /Y %T%\*
	)
) ELSE (
	ECHO Creating test files
	MOVE /Y %T%\*
)
RD /Q /S %T%
EXIT /B 0
