CCCPaste

l4d2_generate_addon_filelist

@echo off
setlocal enabledelayedexpansion
title %~n0

set filelist=file_list.txt

if not "%~1"=="" ( set "folder1=%~1" & goto :Continue) 
if exist addoninfo.txt goto :Continue

:Folder1
set f=
echo.
set /p f="Drop mod folder here "
if not '!f!'=='' (
	set f=!f:"=!
	for %%A in ("!f!") do ( if exist "%%~A" set "folder1=%%~A" & set "folder1name=%%~nA" & goto :Continue)
)
goto :Folder1
goto :eof

:Continue
if not "%folder1%"=="" if exist "%folder1%" cd /d "%folder1%"
if exist addoninfo.txt CALL :ReadAddoninfo addoninfo.txt
if not "!addontitle!"=="" ( set "msg=!addontitle!") else ( set "msg=%folder1%")

:Confirm
set proceed=
set /p "proceed= Confirm %msg% (Y/N)?"
if not "!proceed!"=="" (
	set "proceed=!proceed: =!"
	for /f "delims=yYnN" %%A in ('echo !proceed!') do ( goto :Confirm)
)
if /i !proceed!==y goto :ProcessFolder
if /i !proceed!==n goto :Folder1
goto :Confirm



:ProcessFolder
if exist %filelist% del %filelist%
for /r %%A in (*.*) do CALL :ParseFile "%cd%" "%%~A" %%~xA
set line=
goto :Finish

:Finish
echo.
echo ----------------------------------
echo Finished
echo ----------------------------------
pause & goto :eof

:ParseFile
for %%A in (addoninfo.txt addonimage.jpg) do ( if /i "%~nx2"=="%%~A" goto :eof)
if /i "%~nx2"=="%~nx0" goto :eof

set "line=%~2"
set line=!line:%~dpnx1\=!

for %%X in (.ani .bik .bsp .cache .cfg .dat .dict .lst .manifest .mdl .mp3 .nav .nuc .nut .pcf .phy .phz .pre .rad .raw .res .snd .tbl .txt .vbf .vbsp .vcs .vcd .vdf .vfe .vfont .vmt .vtf .vtx .vvd .wav) do ( if /i %3==%%X ( echo !line!& echo !line!>>"%filelist%"& goto :eof))
goto :eof

:ReadAddoninfo
for /f "tokens=*" %%L in ('type "addoninfo.txt"') DO (	
	if "!addontitle!"=="" (
		echo "%%L"| find /i "addontitle" > nul 2>&1
		if !ErrorLevel!==0 (
			set addontitle=%%~L
			set "addontitle=!addontitle:addontitle=!"
			set addontitle=!addontitle:"=!
			for /f "tokens=*" %%A in ("!addontitle!") do set "addontitle=%%~A"
		)
	)
)
goto :eof



cd /d "%~dp0"
if exist addoninfo.txt ( CALL :ReadAddoninfo addoninfo.txt) else ( goto :Folder1)
if not "!addontitle!"=="" goto :Continue