@ECHO OFF
SETLOCAL

REM Validate the arguments.
IF "%~1" == "" EXIT /B 2
IF NOT "%~3" == "" EXIT /B 2

REM Configure the environment variables.
SET SOURCE_FILE_PATH="%~dp0version.txt"
SET LANGUAGE=%1
SET TARGET_FILE_PATH=%2
PATH %PATH%;%ProgramFiles%\Windows Kits\10\bin\10.0.16299.0\x86
FOR /F %%I IN ('uuidgen') DO SET T="%TEMP%\%%I"

REM Create or update the version file, if necessary.
cscript "%~dpn0.js" %LANGUAGE% %SOURCE_FILE_PATH% %T%
IF EXIST %TARGET_FILE_PATH% (
	FC %T% %TARGET_FILE_PATH% > nul
	IF ERRORLEVEL 1 (
		ECHO Updating version file
		MOVE /Y %T% %TARGET_FILE_PATH%
	)
) ELSE (
	ECHO Creating version file
	MOVE /Y %T% %TARGET_FILE_PATH%
)
IF EXIST %T% DEL /F /Q %T%
EXIT /B 0
