@REM Updates 2011-10-01 - renamed to zipamtemp.bat - 2010-10-26 - 2010-09-13
@setlocal
@REM OPTIONS
@REM ============================
@set TEMPGLIB=no
@set TEMPDIFF=no
@set TEMPPANGO=no
@REM ============================

@set TEMPZCNT=0
@set TEMPZCNT2=0
@set TEMPLIST=
@call amlist
@if "%TEMPLIST%x" == "x" goto NOSETUP
@if "%TEMPBATS%x" == "x" goto NOSETUP2
@set TEMPP=C:\GTools\perl\zips\temp-am2dsp
@set TEMPZL=tempzl.txt
@set TEMPC=0

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

@echo Delete TEMPZL [%TEMPZL%] if exists...
@if EXIST %TEMPZL% @del %TEMPZL%

@set TEMPLST=templist%TEMPV%.txt
@set TEMPZ2=C:\GTools\perl\zips\glib-msvc-%TEMPV%.zip
@set TEMPZ3=C:\GTools\perl\zips\glib-changes-%TEMPV%.zip
@set TEMPZ4=C:\GTools\perl\zips\pango-msvc-%TEMPV%.zip
@set TEMPZ5A=C:\GTools\perl\zips\diff-msvc-%TEMPV%.zip
@set TEMPZ5B=C:\GTools\perl\zips\diff-chgs-%TEMPV%.zip

@if "%TEMPDIFF%x" == "yesx" (
@set /A TEMPZCNT2+=1
@echo New sub-zips %TEMPZCNT2% [%TEMPZ5A%] [%TEMPZ5B%]
)

@if "%TEMPGLIB%x" == "yesx" (
@set /A TEMPZCNT2+=1
@echo New sub-zips %TEMPZCNT2% [%TEMPZ2%] [%TEMPZ3%]
)

@if "%TEMPPANGO%x" == "yesx" (
@set /A TEMPZCNT2+=1
@echo New sub-zips %TEMPZCNT2% [%TEMPZ4%]
)

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

@echo Moment... doing check...

@set TEMPT=0
@for %%i in (%TEMPLIST%) do @(call :CHKIT %%i)

@set TEMPBC=0
@for %%i in (%TEMPBATS%) do @(call :CHKBAT %%i)

@if NOT EXIST %TEMPZL% goto FAILED

@echo TOTAL %TEMPT%, 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% to ZIP %TEMPZ%, using %TEMPZL%
@echo *** CONTINUE WITH UPDATE? ***

@echo Processing the LIST...
@set TEMPDN=%TEMPT%
@set /A TEMPDN+=%TEMPBC%

@echo TOTAL %TEMPT%, plus %TEMPBC% BATS... %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

@if EXIST amtemp2.bat (
@echo Getting sub-zips for %TEMPV% version...
@call amtemp2.bat

@if "%TEMPGLIB%x" == "yesx" (
@if NOT EXIST %TEMPZ2% goto NOZIP2
@if NOT EXIST %TEMPZ3% goto NOZIP3
)

@if "%TEMPPANGO%x" == "yesx" (
@if NOT EXIST %TEMPZ4% goto NOZIP4
)

@if "%TEMPDIFF%x" == "yesx" (
@if NOT EXIST %TEMPZ5A% goto NOZIP5A
@if NOT EXIST %TEMPZ5B% goto NOZIP5B
)

)

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

@call zip8 -vb %TEMPZ%

@echo TOTAL %TEMPT%, plus %TEMPBC% BAT... %TEMPDN%
@echo Check the zip count...
@pause

@echo Adding 3 files to zip...

@if "%TEMPGLIB%x" == "yesx" (
@call zip8 -a -o %TEMPZ% C:\Projects\%TEMPLST% %TEMPZ2% %TEMPZ3%
)
@if "%TEMPPANGO%x" == "yesx" (
@call zip8 -a -o %TEMPZ% %TEMPZ4%
)
@if "%TEMPDIFF%x" == "yesx" (
@call zip8 -a -o %TEMPZ% %TEMPZ5A% %TEMPZ5B%
)

@call zip8 -vb %TEMPZ%

@echo All done... should NOW contain the EXTRA %TEMPZCNT% zip files... 

@call :DOFTP %TEMPZ%

@REM Add a network save
@call savetod2 %TEMPZ%

@goto END

:DOFTP
@set TEMPZ1=%~nx1
@if NOT EXIST zips\%TEMPZ1% goto NOFIND
@dir zips\%TEMPZ1%
@echo.
@echo Proceed to ftp [%TEMPZ1%] to site?
@echo *** CONTINUE? ***
@pause
@cd zips
@call ftp-copy-one %TEMPZ1%
@cd ..
@goto :EOF


:NOFIND
@echo ERROR: Can NOT locate zips\%TEMPZ1%
@echo Can NOT do FTP copy...
@goto :EOF

: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
@REM cho Checking %TEMPF1%...
@if NOT EXIST %TEMPF1% goto CHKFILE
@set /A TEMPT+=1
@echo %TEMPF1% >>%TEMPZL%
@goto :EOF

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

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

:CHKCOPY2
@set /A TEMPC+=1
@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

:NOZIP2
@echo ERROR: %TEMPZ2% NOT created...
@goto END
:NOZIP3
@echo ERROR: %TEMPZ3% NOT created...
@goto END
:NOZIP4
@echo ERROR: %TEMPZ4% NOT created...
@goto END
:NOZIP5A
@echo ERROR: %TEMPZ5A% NOT created...
@goto END
:NOZIP5B
@echo ERROR: %TEMPZ5B% NOT created...
@goto END


:END
@endlocal
