@setlocal
@REM Update 2010-12-04 - 2010-09-13
@set TEMPLIST=
@call amlist
@if "%TEMPLIST%x" == "x" goto NOSETUP
@if "%TEMPBATS%x" == "x" goto NOSETUP2

@set TEMPD=C:\HOMEPAGE\GA\mperl\src
@set TEMPP=C:\HOMEPAGE\GA\mperl\zips\am2dsp
@set TEMPZL=tempzl.txt
@set TEMPZL2=tempzl2.txt
@set TEMPC=0

@REM Get NEXT zip file number
:RPT
@set /A TEMPC+=1
@if %TEMPC% LSS 10 ( 
@set TEMPZ=%TEMPP%0%TEMPC%.zip
) else ( 
@set TEMPZ=%TEMPP%%TEMPC%.zip
)
@if EXIST %TEMPZ% goto RPT

@echo [%TEMPC%] New ZIP file is [%TEMPZ%]...

@if EXIST %TEMPZL% @del %TEMPZL%
@if EXIST %TEMPZL2% (
@echo Deleting old %TEMPZL2%
@del %TEMPZL2%
)

@echo Moment... doing update check...
@set TEMPT=0
@set TEMPC=0
@set TEMPN=0
@set TEMPS=0
@for %%i in (%TEMPLIST%) do @(call :CHKIT %%i)
@set TEMPBC=0
@for %%i in (%TEMPBATS%) do @(call :CHKBAT %%i)

@echo TOTAL %TEMPT%, with SAME %TEMPS%, UPDATED %TEMPC%, and NEW %TEMPN%, plus %TEMPBC% BATS

@echo All into ZIP [%TEMPZ%]...

@call chkdbgon
@if ERRORLEVEL 1 goto SHOWDBG
@echo Appear no files with DEBUG ON...
@goto CONT
:SHOWDBG
@echo NOTE: Appears %ERRORLEVEL% files still have $debug_on SET

:CONT
@echo TOTAL %TEMPT%, with SAME %TEMPS%, UPDATED %TEMPC%, and NEW %TEMPN%
@echo *** CONTINUE WITH UPDATE? ***
@echo New ZIP file will be [%TEMPZ%]...
@pause
@echo *** ARE YOU SURE? ***
@pause


@echo Processing the LIST...

@set TEMPDN=0
@for %%i in (%TEMPLIST%) do @(call :DOIT %%i)

@if NOT EXIST %TEMPZL% goto FAILED
@set TEMPDN=%TEMPT%

@echo TOTAL %TEMPT%, with SAME %TEMPS%, UPDATED %TEMPC%, and NEW %TEMPN%, plus %TEMPBC% BAT... %TEMPDN%
@set TEMPZC=0
@for /F "tokens=*" %%i in (%TEMPZL%) do @(set /A TEMPZC+=1)
@echo Put %TEMPZC% files to the zip %TEMPZ%?
@echo *** CONTINUE? ***
@pause

@call zip8 -a -o %TEMPZ% @%TEMPZL%

@call zip8 -vb %TEMPZ%

@set /A TEMPDN+=%TEMPBC%

@echo TOTAL %TEMPT%, with SAME %TEMPS%, UPDATED %TEMPC%, and NEW %TEMPN%, plus %TEMPBC% BAT... %TEMPDN%

@echo All done...

@goto END

:CHKBAT
@if "%1x" == "x" goto :EOF
@if NOT EXIST %1 goto NOBAT
@set /A TEMPBC+=1
@echo %1 >>%TEMPZL%
@goto :EOF
:NOBAT
@echo ERROR: Bat file %1 is MISSING! Abort by Ctrl+C and FIX!
@pause
@echo This is a bad error! Abort...
@pause
@echo Can ONLY repeat...
@goto NOBAT

:FAILED
@echo.
@echo FAILED to create ZIP LIST [%TEMPZL%]!
@echo.
@pause
@goto END

:CHKIT
@if "%1x" == "x" goto :EOF
@set TEMPF1=%1.pl
@set TEMPF2=%TEMPD%\%1.txt
@echo Checking %TEMPF1%...
@echo %TEMPF1% >> %TEMPZL2%
@if NOT EXIST %TEMPF1% goto CHKFILE
@set /A TEMPT+=1
@if NOT EXIST %TEMPF2% goto CHKCOPY
@fc4 -v0 -q %TEMPF1% %TEMPF2% >nul
@if ERRORLEVEL 1 goto CHKCOPY2
@set /A TEMPS+=1
@goto :EOF

:CHKFILE
@echo.
@echo Missing file [%TEMPF1%] List needs fixing...
@echo What is this file doing in the LIST!
@pause
@echo FIX THE LIST! Ctrl+C to abort...
@pause
@goto CHKFILE

:CHKCOPY
@set /A TEMPN+=1
@goto :EOF

:CHKCOPY2
@set /A TEMPC+=1
@goto :EOF


:DOIT
@if "%1x" == "x" goto :EOF
@set TEMPF1=%1.pl
@set TEMPF2=%TEMPD%\%1.txt
@REM echo Doing %TEMPF1%...
@set /A TEMPDN+=1
@if NOT EXIST %TEMPF1% goto NOFILE
@if NOT EXIST %TEMPF2% goto DOCOPY
@fc4 -v0 -q %TEMPF1% %TEMPF2% >nul
@if ERRORLEVEL 1 goto DOCOPY2
@echo %TEMPDN% of %TEMPT%: %TEMPF1% - Appears up to date...
@goto DOZIP

:DOCOPY
@echo %TEMPDN% of %TEMPT%: %TEMPF1% - Copying to %TEMPF2%
@copy %TEMPF1% %TEMPF2% >nul
@goto DOZIP

:DOCOPY2
@echo.
@echo %TEMPDN% of %TEMPT%: %TEMPF1% - Showing difference...
@fc4 %TEMPF1% %TEMPF2%
@echo %TEMPDN% of %TEMPT%: %TEMPF1% - Different, so do copy to %TEMPF2%
@pause
@copy %TEMPF1% %TEMPF2% >nul
@goto DOZIP

:DOZIP
@REM Add this file to the ZIP
@echo %TEMPF1% >>%TEMPZL%
@goto :EOF

:NOFILE
@echo Missing file [%TEMPF1%]
@echo As stated, what is this file doing in the LIST!
@pause
@goto :EOF

:FATAL
@echo Copy of previous ZIP FAILED! Abort with Ctrl+C and FIX!
@pause
@echo It is NOT good to continue! Ctrl+C to abort...
@pause
@goto END

:NOSETUP
@echo ERROR: amlist.bat FAILED to set the TEMPLIST!!!
@goto END
:NOSETUP2
@echo ERROR: amlist.bat FAILED to set the TEMPBATS!!!
@goto END


:END
@endlocal
