REM CMDOW @ /HID

CALL C:\LiveDigital\config.bat

SET var_restart=0
SET var_processfile=ftp-process.txt

IF EXIST C:\LiveDigital\%var_processfile% (
	PAUSE
	EXIT
)

@ECHO off

for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j
set ldt=%ldt:~0,4%-%ldt:~4,2%-%ldt:~6,2% %ldt:~8,2%:%ldt:~10,2%:%ldt:~12,6%

@ECHO %ldt%: Processing FTP>> C:\LiveDigital\%var_processfile%
MKDIR "%var_ftpdir%"
MKDIR "%var_ftpdir%\screen%var_screen0%"
IF %var_noscreens% GTR 1 (
	MKDIR "%var_ftpdir%\screen%var_screen1%"
)

IF %var_noscreens% GTR 2 (
	MKDIR "%var_ftpdir%\screen%var_screen2%"
)

IF %var_noscreens% GTR 3 (
	MKDIR "%var_ftpdir%\screen%var_screen3%"
)

IF %var_noscreens% GTR 4 (
	MKDIR "%var_ftpdir%\screen%var_screen4%"
)

IF %var_noscreens% GTR 5 (
	MKDIR "%var_ftpdir%\screen%var_screen5%"
)


DEL "%var_livedir%\copy.log"
DEL "%var_livedir%\copy-temp.log"

DEL %var_livedir%\ftplog-screen%var_screen0%.txt
DEL %var_livedir%\ftplog-screen%var_screen0%-parsed.txt

DEL %var_livedir%\ftp\data\screen%var_screen0%\publish.bat

IF %var_noscreens% GTR 1 (
	DEL %var_livedir%\ftplog-screen%var_screen1%.txt
	DEL %var_livedir%\ftplog-screen%var_screen1%-parsed.txt
	
	DEL %var_livedir%\ftp\data\screen%var_screen1%\publish.bat
)

IF %var_noscreens% GTR 2 (
	DEL %var_livedir%\ftplog-screen%var_screen2%.txt
	DEL %var_livedir%\ftplog-screen%var_screen2%-parsed.txt
	
	DEL %var_livedir%\ftp\data\screen%var_screen2%\publish.bat
)

IF %var_noscreens% GTR 3 (
	DEL %var_livedir%\ftplog-screen%var_screen3%.txt
	DEL %var_livedir%\ftplog-screen%var_screen3%-parsed.txt
	
	DEL %var_livedir%\ftp\data\screen%var_screen3%\publish.bat
)

IF %var_noscreens% GTR 4 (
	DEL %var_livedir%\ftplog-screen%var_screen4%.txt
	DEL %var_livedir%\ftplog-screen%var_screen4%-parsed.txt
	
	DEL %var_livedir%\ftp\data\screen%var_screen4%\publish.bat
)

IF %var_noscreens% GTR 5 (
	DEL %var_livedir%\ftplog-screen%var_screen5%.txt
	DEL %var_livedir%\ftplog-screen%var_screen5%-parsed.txt
	
	DEL %var_livedir%\ftp\data\screen%var_screen5%\publish.bat
)

CD %var_livedir%

for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j
set ldt=%ldt:~0,4%-%ldt:~4,2%-%ldt:~6,2% %ldt:~8,2%:%ldt:~10,2%:%ldt:~12,6%
@ECHO %ldt%: Downloading "/client_%var_client%/screen%var_screen0%/publish.bat" started>> C:\LiveDigital\%var_processfile%

ncftpget.exe -DD -u %var_username% -p %var_password% -R %var_server% "%var_ftpdir%\screen%var_screen0%" "/client_%var_client%/screen%var_screen0%/publish.bat

for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j
set ldt=%ldt:~0,4%-%ldt:~4,2%-%ldt:~6,2% %ldt:~8,2%:%ldt:~10,2%:%ldt:~12,6%
@ECHO %ldt%: Downloading "/client_%var_client%/screen%var_screen0%/publish.bat" complete>> C:\LiveDigital\%var_processfile%

CALL %var_livedir%\ftp\data\screen%var_screen0%\publish.bat

SET var_deletecontent=0
SET var_deleteplaylist=0

IF "%var_deletecontent%"=="1" (
	DEL /Q %var_livedir%\ftp\data\screen%var_screen0%\*.*
	DEL /Q %var_livedir%\live\screen%var_screen0%\*.*
	ECHO Deleting all cached data for screen%var_screen0%.
)

IF "%var_deleteplaylist%"=="1" (
	DEL /Q %var_livedir%\ftp\data\screen%var_screen0%\*.html
	ECHO Deleting cached playlist for screen%var_screen0%.
)


for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j
set ldt=%ldt:~0,4%-%ldt:~4,2%-%ldt:~6,2% %ldt:~8,2%:%ldt:~10,2%:%ldt:~12,6%
@ECHO %ldt%: Downloading "/client_%var_client%/screen%var_screen0%" started>> C:\LiveDigital\%var_processfile%

ncftpget.exe -d "%var_livedir%\ftplog-screen%var_screen0%.txt" -u %var_username% -p %var_password% -R %var_server% "%var_ftpdir%" "/client_%var_client%/screen%var_screen0%"

for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j
set ldt=%ldt:~0,4%-%ldt:~4,2%-%ldt:~6,2% %ldt:~8,2%:%ldt:~10,2%:%ldt:~12,6%
@ECHO %ldt%: Downloading "/client_%var_client%/screen%var_screen0%" complete>> C:\LiveDigital\%var_processfile%

FIND "Cmd: RETR" %var_livedir%\ftplog-screen%var_screen0%.txt > %var_livedir%\ftplog-screen%var_screen0%-parsed.txt

FART.exe -C "%var_livedir%\ftplog-screen%var_screen0%-parsed.txt" \/ \\
FART.exe -C "%var_livedir%\ftplog-screen%var_screen0%-parsed.txt" \\client_%var_client%\\screen screen

for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j
set ldt=%ldt:~0,4%-%ldt:~4,2%-%ldt:~6,2% %ldt:~8,2%:%ldt:~10,2%:%ldt:~12,6%
@ECHO %ldt%: Touching "/client_%var_client%/screen%var_screen0%" started>> C:\LiveDigital\%var_processfile%

FOR /F "tokens=5 delims= " %%G IN (%var_livedir%\ftplog-screen%var_screen0%-parsed.txt) DO ( 
	touch.exe %var_livedir%\ftp\data\%%G
)

for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j
set ldt=%ldt:~0,4%-%ldt:~4,2%-%ldt:~6,2% %ldt:~8,2%:%ldt:~10,2%:%ldt:~12,6%
@ECHO %ldt%: Touching "/client_%var_client%/screen%var_screen0%" complete>> C:\LiveDigital\%var_processfile%


IF %var_noscreens% GTR 1 (	
	
	for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j
	set ldt=%ldt:~0,4%-%ldt:~4,2%-%ldt:~6,2% %ldt:~8,2%:%ldt:~10,2%:%ldt:~12,6%
	@ECHO %ldt%: Downloading "/client_%var_client%/screen%var_screen1%/publish.bat" started>> C:\LiveDigital\%var_processfile%	

	ncftpget.exe -DD -u %var_username% -p %var_password% -R %var_server% "%var_ftpdir%\screen%var_screen1%" "/client_%var_client%/screen%var_screen1%/publish.bat

	for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j
	set ldt=%ldt:~0,4%-%ldt:~4,2%-%ldt:~6,2% %ldt:~8,2%:%ldt:~10,2%:%ldt:~12,6%
	@ECHO %ldt%: Downloading "/client_%var_client%/screen%var_screen1%/publish.bat" complete>> C:\LiveDigital\%var_processfile%	

	CALL %var_livedir%\ftp\data\screen%var_screen1%\publish.bat
	
	SET var_deletecontent=0
	SET var_deleteplaylist=0
	
	IF "%var_deletecontent%"=="1" (
		DEL /Q %var_livedir%\ftp\data\screen%var_screen1%\*.*
		DEL /Q %var_livedir%\live\screen%var_screen1%\*.*
		ECHO Deleting all cached data for screen%var_screen1%.
	)

	IF "%var_deleteplaylist%"=="1" (
		DEL /Q %var_livedir%\ftp\data\screen%var_screen1%\*.html
		ECHO Deleting cached playlist for screen%var_screen1%.
	)
	
	for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j
	set ldt=%ldt:~0,4%-%ldt:~4,2%-%ldt:~6,2% %ldt:~8,2%:%ldt:~10,2%:%ldt:~12,6%
	@ECHO %ldt%: Downloading "/client_%var_client%/screen%var_screen1%" started>> C:\LiveDigital\%var_processfile%

	ncftpget.exe -d "%var_livedir%\ftplog-screen%var_screen1%.txt" -u %var_username% -p %var_password% -R %var_server% "%var_ftpdir%" "/client_%var_client%/screen%var_screen1%"

	for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j
	set ldt=%ldt:~0,4%-%ldt:~4,2%-%ldt:~6,2% %ldt:~8,2%:%ldt:~10,2%:%ldt:~12,6%
	@ECHO %ldt%: Downloading "/client_%var_client%/screen%var_screen1%" complete>> C:\LiveDigital\%var_processfile%
	
	FIND "Cmd: RETR" %var_livedir%\ftplog-screen%var_screen1%.txt > %var_livedir%\ftplog-screen%var_screen1%-parsed.txt
	
	FART.exe -C "%var_livedir%\ftplog-screen%var_screen1%-parsed.txt" \/ \\
	FART.exe -C "%var_livedir%\ftplog-screen%var_screen1%-parsed.txt" \\client_%var_client%\\screen screen
	
	for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j
	set ldt=%ldt:~0,4%-%ldt:~4,2%-%ldt:~6,2% %ldt:~8,2%:%ldt:~10,2%:%ldt:~12,6%
	@ECHO %ldt%: Touching "/client_%var_client%/screen%var_screen1%" started>> C:\LiveDigital\%var_processfile%

	FOR /F "tokens=5 delims= " %%G IN (%var_livedir%\ftplog-screen%var_screen1%-parsed.txt) DO ( 
		touch.exe %var_livedir%\ftp\data\%%G
	)

	for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j
	set ldt=%ldt:~0,4%-%ldt:~4,2%-%ldt:~6,2% %ldt:~8,2%:%ldt:~10,2%:%ldt:~12,6%
	@ECHO %ldt%: Touching "/client_%var_client%/screen%var_screen1%" complete>> C:\LiveDigital\%var_processfile%
)

IF %var_noscreens% GTR 2 (	
	for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j
	set ldt=%ldt:~0,4%-%ldt:~4,2%-%ldt:~6,2% %ldt:~8,2%:%ldt:~10,2%:%ldt:~12,6%
	@ECHO %ldt%: Downloading "/client_%var_client%/screen%var_screen2%/publish.bat" started>> C:\LiveDigital\%var_processfile%
	
	ncftpget.exe -DD -u %var_username% -p %var_password% -R %var_server% "%var_ftpdir%\screen%var_screen2%" "/client_%var_client%/screen%var_screen2%/publish.bat

	for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j
	set ldt=%ldt:~0,4%-%ldt:~4,2%-%ldt:~6,2% %ldt:~8,2%:%ldt:~10,2%:%ldt:~12,6%
	@ECHO %ldt%: Downloading "/client_%var_client%/screen%var_screen2%/publish.bat" complete>> C:\LiveDigital\%var_processfile%

	CALL %var_livedir%\ftp\data\screen%var_screen2%\publish.bat
	
	SET var_deletecontent=0
	SET var_deleteplaylist=0
	
	IF "%var_deletecontent%"=="1" (
		DEL /Q %var_livedir%\ftp\data\screen%var_screen2%\*.*
		DEL /Q %var_livedir%\live\screen%var_screen2%\*.*
		ECHO Deleting all cached data for screen%var_screen2%.
	)

	IF "%var_deleteplaylist%"=="1" (
		DEL /Q %var_livedir%\ftp\data\screen%var_screen2%\*.html
		ECHO Deleting cached playlist for screen%var_screen2%.
	)
	
	for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j
	set ldt=%ldt:~0,4%-%ldt:~4,2%-%ldt:~6,2% %ldt:~8,2%:%ldt:~10,2%:%ldt:~12,6%
	@ECHO %ldt%: Downloading "/client_%var_client%/screen%var_screen2%" started>> C:\LiveDigital\%var_processfile%

	ncftpget.exe -d "%var_livedir%\ftplog-screen%var_screen2%.txt" -u %var_username% -p %var_password% -R %var_server% "%var_ftpdir%" "/client_%var_client%/screen%var_screen2%"
	
	for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j
	set ldt=%ldt:~0,4%-%ldt:~4,2%-%ldt:~6,2% %ldt:~8,2%:%ldt:~10,2%:%ldt:~12,6%
	@ECHO %ldt%: Downloading "/client_%var_client%/screen%var_screen2%" complete>> C:\LiveDigital\%var_processfile%
	
	FIND "Cmd: RETR" %var_livedir%\ftplog-screen%var_screen2%.txt > %var_livedir%\ftplog-screen%var_screen2%-parsed.txt
	
	FART.exe -C "%var_livedir%\ftplog-screen%var_screen2%-parsed.txt" \/ \\
	FART.exe -C "%var_livedir%\ftplog-screen%var_screen2%-parsed.txt" \\client_%var_client%\\screen screen
	
	for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j
	set ldt=%ldt:~0,4%-%ldt:~4,2%-%ldt:~6,2% %ldt:~8,2%:%ldt:~10,2%:%ldt:~12,6%
	@ECHO %ldt%: Touching "/client_%var_client%/screen%var_screen2%" started>> C:\LiveDigital\%var_processfile%

	FOR /F "tokens=5 delims= " %%G IN (%var_livedir%\ftplog-screen%var_screen2%-parsed.txt) DO ( 
		touch.exe %var_livedir%\ftp\data\%%G
	)

	for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j
	set ldt=%ldt:~0,4%-%ldt:~4,2%-%ldt:~6,2% %ldt:~8,2%:%ldt:~10,2%:%ldt:~12,6%
	@ECHO %ldt%: Touching "/client_%var_client%/screen%var_screen2%" complete>> C:\LiveDigital\%var_processfile%
)

IF %var_noscreens% GTR 3 (	
	for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j
	set ldt=%ldt:~0,4%-%ldt:~4,2%-%ldt:~6,2% %ldt:~8,2%:%ldt:~10,2%:%ldt:~12,6%
	@ECHO %ldt%: Downloading "/client_%var_client%/screen%var_screen3%/publish.bat" started>> C:\LiveDigital\%var_processfile%	

	ncftpget.exe -DD -u %var_username% -p %var_password% -R %var_server% "%var_ftpdir%\screen%var_screen3%" "/client_%var_client%/screen%var_screen3%/publish.bat

	for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j
	set ldt=%ldt:~0,4%-%ldt:~4,2%-%ldt:~6,2% %ldt:~8,2%:%ldt:~10,2%:%ldt:~12,6%
	@ECHO %ldt%: Downloading "/client_%var_client%/screen%var_screen3%/publish.bat" complete>> C:\LiveDigital\%var_processfile%

	CALL %var_livedir%\ftp\data\screen%var_screen3%\publish.bat
	
	SET var_deletecontent=0
	SET var_deleteplaylist=0
	
	IF "%var_deletecontent%"=="1" (
		DEL /Q %var_livedir%\ftp\data\screen%var_screen3%\*.*
		DEL /Q %var_livedir%\live\screen%var_screen3%\*.*
		ECHO Deleting all cached data for screen%var_screen3%.
	)

	IF "%var_deleteplaylist%"=="1" (
		DEL /Q %var_livedir%\ftp\data\screen%var_screen3%\*.html
		ECHO Deleting cached playlist for screen%var_screen3%.
	)
	
	for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j
	set ldt=%ldt:~0,4%-%ldt:~4,2%-%ldt:~6,2% %ldt:~8,2%:%ldt:~10,2%:%ldt:~12,6%
	@ECHO %ldt%: Downloading "/client_%var_client%/screen%var_screen3%" started>> C:\LiveDigital\%var_processfile%

	ncftpget.exe -d "%var_livedir%\ftplog-screen%var_screen3%.txt" -u %var_username% -p %var_password% -R %var_server% "%var_ftpdir%" "/client_%var_client%/screen%var_screen3%"

	for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j
	set ldt=%ldt:~0,4%-%ldt:~4,2%-%ldt:~6,2% %ldt:~8,2%:%ldt:~10,2%:%ldt:~12,6%
	@ECHO %ldt%: Downloading "/client_%var_client%/screen%var_screen3%" complete>> C:\LiveDigital\%var_processfile%
	
	FIND "Cmd: RETR" %var_livedir%\ftplog-screen%var_screen3%.txt > %var_livedir%\ftplog-screen%var_screen3%-parsed.txt
	
	FART.exe -C "%var_livedir%\ftplog-screen%var_screen3%-parsed.txt" \/ \\
	FART.exe -C "%var_livedir%\ftplog-screen%var_screen3%-parsed.txt" \\client_%var_client%\\screen screen
	
	for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j
	set ldt=%ldt:~0,4%-%ldt:~4,2%-%ldt:~6,2% %ldt:~8,2%:%ldt:~10,2%:%ldt:~12,6%
	@ECHO %ldt%: Touching "/client_%var_client%/screen%var_screen3%" started>> C:\LiveDigital\%var_processfile%
	
	FOR /F "tokens=5 delims= " %%G IN (%var_livedir%\ftplog-screen%var_screen3%-parsed.txt) DO ( 
		touch.exe %var_livedir%\ftp\data\%%G
	)

	for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j
	set ldt=%ldt:~0,4%-%ldt:~4,2%-%ldt:~6,2% %ldt:~8,2%:%ldt:~10,2%:%ldt:~12,6%
	@ECHO %ldt%: Touching "/client_%var_client%/screen%var_screen3%" complete>> C:\LiveDigital\%var_processfile%
)

IF %var_noscreens% GTR 4 (	
	for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j
	set ldt=%ldt:~0,4%-%ldt:~4,2%-%ldt:~6,2% %ldt:~8,2%:%ldt:~10,2%:%ldt:~12,6%
	@ECHO %ldt%: Downloading "/client_%var_client%/screen%var_screen4%/publish.bat" started>> C:\LiveDigital\%var_processfile%	

	ncftpget.exe -DD -u %var_username% -p %var_password% -R %var_server% "%var_ftpdir%\screen%var_screen4%" "/client_%var_client%/screen%var_screen4%/publish.bat

	for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j
	set ldt=%ldt:~0,4%-%ldt:~4,2%-%ldt:~6,2% %ldt:~8,2%:%ldt:~10,2%:%ldt:~12,6%
	@ECHO %ldt%: Downloading "/client_%var_client%/screen%var_screen4%/publish.bat" complete>> C:\LiveDigital\%var_processfile%

	CALL %var_livedir%\ftp\data\screen%var_screen4%\publish.bat
	
	SET var_deletecontent=0
	SET var_deleteplaylist=0
	
	IF "%var_deletecontent%"=="1" (
		DEL /Q %var_livedir%\ftp\data\screen%var_screen4%\*.*
		DEL /Q %var_livedir%\live\screen%var_screen4%\*.*
		ECHO Deleting all cached data for screen%var_screen4%.
	)

	IF "%var_deleteplaylist%"=="1" (
		DEL /Q %var_livedir%\ftp\data\screen%var_screen4%\*.html
		ECHO Deleting cached playlist for screen%var_screen4%.
	)
	
	for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j
	set ldt=%ldt:~0,4%-%ldt:~4,2%-%ldt:~6,2% %ldt:~8,2%:%ldt:~10,2%:%ldt:~12,6%
	@ECHO %ldt%: Downloading "/client_%var_client%/screen%var_screen4%" started>> C:\LiveDigital\%var_processfile%

	ncftpget.exe -d "%var_livedir%\ftplog-screen%var_screen4%.txt" -u %var_username% -p %var_password% -R %var_server% "%var_ftpdir%" "/client_%var_client%/screen%var_screen4%"

	for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j
	set ldt=%ldt:~0,4%-%ldt:~4,2%-%ldt:~6,2% %ldt:~8,2%:%ldt:~10,2%:%ldt:~12,6%
	@ECHO %ldt%: Downloading "/client_%var_client%/screen%var_screen4%" complete>> C:\LiveDigital\%var_processfile%
	
	FIND "Cmd: RETR" %var_livedir%\ftplog-screen%var_screen4%.txt > %var_livedir%\ftplog-screen%var_screen4%-parsed.txt
	
	FART.exe -C "%var_livedir%\ftplog-screen%var_screen4%-parsed.txt" \/ \\
	FART.exe -C "%var_livedir%\ftplog-screen%var_screen4%-parsed.txt" \\client_%var_client%\\screen screen
	
	for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j
	set ldt=%ldt:~0,4%-%ldt:~4,2%-%ldt:~6,2% %ldt:~8,2%:%ldt:~10,2%:%ldt:~12,6%
	@ECHO %ldt%: Touching "/client_%var_client%/screen%var_screen4%" started>> C:\LiveDigital\%var_processfile%
	
	FOR /F "tokens=5 delims= " %%G IN (%var_livedir%\ftplog-screen%var_screen4%-parsed.txt) DO ( 
		touch.exe %var_livedir%\ftp\data\%%G
	)

	for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j
	set ldt=%ldt:~0,4%-%ldt:~4,2%-%ldt:~6,2% %ldt:~8,2%:%ldt:~10,2%:%ldt:~12,6%
	@ECHO %ldt%: Touching "/client_%var_client%/screen%var_screen4%" complete>> C:\LiveDigital\%var_processfile%
)

IF %var_noscreens% GTR 5 (	
	for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j
	set ldt=%ldt:~0,4%-%ldt:~4,2%-%ldt:~6,2% %ldt:~8,2%:%ldt:~10,2%:%ldt:~12,6%
	@ECHO %ldt%: Downloading "/client_%var_client%/screen%var_screen5%/publish.bat" started>> C:\LiveDigital\%var_processfile%	

	ncftpget.exe -DD -u %var_username% -p %var_password% -R %var_server% "%var_ftpdir%\screen%var_screen5%" "/client_%var_client%/screen%var_screen5%/publish.bat

	for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j
	set ldt=%ldt:~0,4%-%ldt:~4,2%-%ldt:~6,2% %ldt:~8,2%:%ldt:~10,2%:%ldt:~12,6%
	@ECHO %ldt%: Downloading "/client_%var_client%/screen%var_screen5%/publish.bat" complete>> C:\LiveDigital\%var_processfile%

	CALL %var_livedir%\ftp\data\screen%var_screen5%\publish.bat
	
	SET var_deletecontent=0
	SET var_deleteplaylist=0
	
	IF "%var_deletecontent%"=="1" (
		DEL /Q %var_livedir%\ftp\data\screen%var_screen5%\*.*
		DEL /Q %var_livedir%\live\screen%var_screen5%\*.*
		ECHO Deleting all cached data for screen%var_screen5%.
	)

	IF "%var_deleteplaylist%"=="1" (
		DEL /Q %var_livedir%\ftp\data\screen%var_screen5%\*.html
		ECHO Deleting cached playlist for screen%var_screen5%.
	)
	
	for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j
	set ldt=%ldt:~0,4%-%ldt:~4,2%-%ldt:~6,2% %ldt:~8,2%:%ldt:~10,2%:%ldt:~12,6%
	@ECHO %ldt%: Downloading "/client_%var_client%/screen%var_screen5%" started>> C:\LiveDigital\%var_processfile%

	ncftpget.exe -d "%var_livedir%\ftplog-screen%var_screen5%.txt" -u %var_username% -p %var_password% -R %var_server% "%var_ftpdir%" "/client_%var_client%/screen%var_screen5%"

	for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j
	set ldt=%ldt:~0,4%-%ldt:~4,2%-%ldt:~6,2% %ldt:~8,2%:%ldt:~10,2%:%ldt:~12,6%
	@ECHO %ldt%: Downloading "/client_%var_client%/screen%var_screen5%" complete>> C:\LiveDigital\%var_processfile%
	
	FIND "Cmd: RETR" %var_livedir%\ftplog-screen%var_screen5%.txt > %var_livedir%\ftplog-screen%var_screen5%-parsed.txt
	
	FART.exe -C "%var_livedir%\ftplog-screen%var_screen5%-parsed.txt" \/ \\
	FART.exe -C "%var_livedir%\ftplog-screen%var_screen5%-parsed.txt" \\client_%var_client%\\screen screen
	
	for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j
	set ldt=%ldt:~0,4%-%ldt:~4,2%-%ldt:~6,2% %ldt:~8,2%:%ldt:~10,2%:%ldt:~12,6%
	@ECHO %ldt%: Touching "/client_%var_client%/screen%var_screen5%" started>> C:\LiveDigital\%var_processfile%
	
	FOR /F "tokens=5 delims= " %%G IN (%var_livedir%\ftplog-screen%var_screen5%-parsed.txt) DO ( 
		touch.exe %var_livedir%\ftp\data\%%G
	)

	for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j
	set ldt=%ldt:~0,4%-%ldt:~4,2%-%ldt:~6,2% %ldt:~8,2%:%ldt:~10,2%:%ldt:~12,6%
	@ECHO %ldt%: Touching "/client_%var_client%/screen%var_screen5%" complete>> C:\LiveDigital\%var_processfile%
)

MKDIR "%var_livedir%\live"

for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j
set ldt=%ldt:~0,4%-%ldt:~4,2%-%ldt:~6,2% %ldt:~8,2%:%ldt:~10,2%:%ldt:~12,6%
@ECHO %ldt%: Copying "%var_ftpdir%" to "%var_livedir%\live" started>> C:\LiveDigital\%var_processfile%

XCOPY "%var_ftpdir%" "%var_livedir%\live" /E /C /I /R /Y /D /Exclude:excludes.txt>%var_livedir%\copy.log
FOR /F "tokens=*" %%B IN (%var_livedir%\copy.log) DO ( 
	IF "%%B"=="0 File(s) copied" (
		SET var_unused=0
	) ELSE (	
		SET var_restart=1
	)
)

for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j
set ldt=%ldt:~0,4%-%ldt:~4,2%-%ldt:~6,2% %ldt:~8,2%:%ldt:~10,2%:%ldt:~12,6%
@ECHO %ldt%: Copying "%var_ftpdir%" to "%var_livedir%\live" complete>> C:\LiveDigital\%var_processfile%

DEL /Q "%var_livedir%\ftplog-screen%var_screen0%.txt"
DEL /Q "%var_livedir%\ftplog-screen%var_screen0%-parsed.txt"

IF %var_noscreens% GTR 1 (
	DEL /Q "%var_livedir%\ftplog-screen%var_screen1%.txt"
	DEL /Q "%var_livedir%\ftplog-screen%var_screen1%-parsed.txt"
)

IF %var_noscreens% GTR 2 (
	DEL /Q "%var_livedir%\ftplog-screen%var_screen2%.txt"
	DEL /Q "%var_livedir%\ftplog-screen%var_screen2%-parsed.txt"
)

IF %var_noscreens% GTR 3 (
	DEL /Q "%var_livedir%\ftplog-screen%var_screen3%.txt"
	DEL /Q "%var_livedir%\ftplog-screen%var_screen3%-parsed.txt"
)

IF %var_noscreens% GTR 4 (
	DEL /Q "%var_livedir%\ftplog-screen%var_screen4%.txt"
	DEL /Q "%var_livedir%\ftplog-screen%var_screen4%-parsed.txt"
)

IF %var_noscreens% GTR 5 (
	DEL /Q "%var_livedir%\ftplog-screen%var_screen5%.txt"
	DEL /Q "%var_livedir%\ftplog-screen%var_screen5%-parsed.txt"
)

DEL "%var_livedir%\copy.log"
DEL "%var_livedir%\copy-temp.log"

PING 127.0.0.1 -n 4 -w 500

DEL "C:\LiveDigital\%var_processfile%"

IF "%var_restart%"=="1" (
	@ECHO Changes Detected
	IF "%var_is64%"=="1" (
		wget64.exe --timeout=5 --tries=2 --delete-after "%var_pingaddress%%var_pingscript%?clientid=%var_client%&serverip=%var_supportip%&type=ftp-changes"
	) ELSE (
		wget.exe --timeout=5 --tries=2 --delete-after "%var_pingaddress%%var_pingscript%?clientid=%var_client%&serverip=%var_supportip%&type=ftp-changes"
	)
	
	START /B C:\LiveDigital\startplayer.bat
) ELSE (
	@ECHO No Changes Detected
	
	IF "%var_is64%"=="1" (
		wget64.exe --timeout=5 --tries=2 --delete-after "%var_pingaddress%%var_pingscript%?clientid=%var_client%&serverip=%var_supportip%&type=ftp-nochange"
	) ELSE (
		wget.exe --timeout=5 --tries=2 --delete-after "%var_pingaddress%%var_pingscript%?clientid=%var_client%&serverip=%var_supportip%&type=ftp-nochange"
	)
)


PAUSE

EXIT