vrts: fix paths with & ! %

This commit is contained in:
bnnm 2021-10-10 11:23:15 +02:00
parent af86aeca74
commit d71bbc16be

View File

@ -10,9 +10,7 @@ REM # extensions found unless specified (except a few).
REM # REM #
REM # Options: see below. REM # Options: see below.
REM #------------------------------------------------------------------------- REM #-------------------------------------------------------------------------
REM #TODO: escape & ! % in file/folder names
setlocal enableDelayedExpansion
REM #------------------------------------------------------------------------- REM #-------------------------------------------------------------------------
REM #options REM #options
@ -35,7 +33,8 @@ REM # -Po: performance test old (same but also don't write file)
REM # -Pm: performance test new (only parse meta) REM # -Pm: performance test new (only parse meta)
REM # -Pmo: performance test old (only parse meta) REM # -Pmo: performance test old (only parse meta)
set OP_PERFORMANCE= set OP_PERFORMANCE=
REM # -fc <exe>: file comparer (Windows's FC is slow) REM # -fc <exe>: file comparer
REM # Windows's FC is slow, try -fc ffc.exe (https://github.com/bnnm/vgm-tools/tree/master/misc/ffc)
set OP_CMD_FC=fc /a /b set OP_CMD_FC=fc /a /b
@ -60,9 +59,9 @@ goto set_options
:end_options :end_options
REM # output color defs REM # output color defs
set C_W=0e set COLOR_WN=0e
set C_E=0c set COLOR_ER=0c
set C_O=0f set COLOR_OK=0f
REM # remove command options and possibly " REM # remove command options and possibly "
for /f "tokens=1-1 delims= " %%A in ("%OP_CMD_OLD%") do set CHECK_OLD=%%A for /f "tokens=1-1 delims= " %%A in ("%OP_CMD_OLD%") do set CHECK_OLD=%%A
@ -97,11 +96,17 @@ REM # process files
for /f "delims=" %%x in ('%CMD_DIR% ^| %CMD_FIND%') do ( for /f "delims=" %%x in ('%CMD_DIR% ^| %CMD_FIND%') do (
set CMD_FILE=%%x set CMD_FILE=%%x
REM # must enable/disable after setting CMD as ! & in dir names would become expanded/removed otherwise
setlocal EnableDelayedExpansion
if "%OP_PERFORMANCE%" == "" ( if "%OP_PERFORMANCE%" == "" (
call :process_file "!CMD_FILE!" call :process_file "!CMD_FILE!"
) else ( ) else (
call :performance_file "!CMD_FILE!" call :performance_file "!CMD_FILE!"
) )
endlocal
) )
REM # find time elapsed REM # find time elapsed
@ -131,58 +136,59 @@ REM # ########################################################################
set CMD_SHORTNAME=%~n1 set CMD_SHORTNAME=%~n1
if "%CMD_SHORTNAME%" == "" goto process_file_continue if "%CMD_SHORTNAME%" == "" goto process_file_continue
REM # get file
set CMD_FILE=%1 REM # get file (not from arg %1)
set CMD_FILE=%CMD_FILE:"=% set CMD_FILE=!CMD_FILE!
REM echo VTRS: file %CMD_FILE% set CMD_FILE=!CMD_FILE:"=!
REM echo VTRS: file !CMD_FILE!
REM # old/new temp output REM # old/new temp output
set WAV_OLD=%CMD_FILE%.old.wav set WAV_OLD=!CMD_FILE!.old.wav
set TXT_OLD=%CMD_FILE%.old.txt set TXT_OLD=!CMD_FILE!.old.txt
set CMD_VGM_OLD="%OP_CMD_OLD%" -o "%WAV_OLD%" "%CMD_FILE%" set CMD_VGM_OLD="%OP_CMD_OLD%" -o "!WAV_OLD!" "!CMD_FILE!"
%CMD_VGM_OLD% 1> "%TXT_OLD%" 2>&1 & REM || goto error !CMD_VGM_OLD! 1> "!TXT_OLD!" 2>&1 & REM || goto error
set WAV_NEW=%CMD_FILE%.new.wav set WAV_NEW=!CMD_FILE!.new.wav
set TXT_NEW=%CMD_FILE%.new.txt set TXT_NEW=!CMD_FILE!.new.txt
set CMD_VGM_NEW="%OP_CMD_NEW%" -o "%WAV_NEW%" "%CMD_FILE%" set CMD_VGM_NEW="%OP_CMD_NEW%" -o "!WAV_NEW!" "!CMD_FILE!"
%CMD_VGM_NEW% 1> "%TXT_NEW%" 2>&1 & REM || goto error !CMD_VGM_NEW! 1> "!TXT_NEW!" 2>&1 & REM || goto error
REM # ignore if no files are created (unsupported formats) REM # ignore if no files are created (unsupported formats)
if not exist "%WAV_NEW%" ( if not exist "!WAV_NEW!" (
if not exist "%WAV_OLD%" ( if not exist "!WAV_OLD!" (
REM echo VRTS: nothing created for file %CMD_FILE% REM echo VRTS: nothing created for file !CMD_FILE!
if exist "%TXT_NEW%" del /a:a "%TXT_NEW%" if exist "!TXT_NEW!" del /a:a "!TXT_NEW!"
if exist "%TXT_OLD%" del /a:a "%TXT_OLD%" if exist "!TXT_OLD!" del /a:a "!TXT_OLD!"
goto process_file_continue goto process_file_continue
) )
) )
REM # compare files (without /b may to be faster for small files?) REM # compare files (without /b may to be faster for small files?)
set CMP_WAV=%OP_CMD_FC% "%WAV_OLD%" "%WAV_NEW%" set CMP_WAV=%OP_CMD_FC% "!WAV_OLD!" "!WAV_NEW!"
set CMP_TXT=%OP_CMD_FC% "%TXT_OLD%" "%TXT_NEW%" set CMP_TXT=%OP_CMD_FC% "!TXT_OLD!" "!TXT_NEW!"
%CMP_WAV% 1> nul 2>&1 !CMP_WAV! 1> nul 2>&1
set CMP_WAV_ERROR=0 set CMP_WAV_ERROR=0
if %ERRORLEVEL% NEQ 0 set CMP_WAV_ERROR=1 if %ERRORLEVEL% NEQ 0 set CMP_WAV_ERROR=1
%CMP_TXT% 1> nul 2>&1 !CMP_TXT! 1> nul 2>&1
set CMP_TXT_ERROR=0 set CMP_TXT_ERROR=0
if %ERRORLEVEL% NEQ 0 set CMP_TXT_ERROR=1 if %ERRORLEVEL% NEQ 0 set CMP_TXT_ERROR=1
REM # print output REM # print output
if %CMP_WAV_ERROR% EQU 1 ( if %CMP_WAV_ERROR% EQU 1 (
if %CMP_TXT_ERROR% EQU 1 ( if %CMP_TXT_ERROR% EQU 1 (
call :echo_color %C_E% "%CMD_FILE%" "wav and txt diffs" call :echo_color %COLOR_ER% "!CMD_FILE!" "wav and txt diffs"
) else ( ) else (
call :echo_color %C_E% "%CMD_FILE%" "wav diffs" call :echo_color %COLOR_ER% "!CMD_FILE!" "wav diffs"
) )
set /a "FILES_KO+=1" set /a "FILES_KO+=1"
) else ( ) else (
if %CMP_TXT_ERROR% EQU 1 ( if %CMP_TXT_ERROR% EQU 1 (
call :echo_color %C_W% "%CMD_FILE%" "txt diffs" call :echo_color %COLOR_WN% "!CMD_FILE!" "txt diffs"
) else ( ) else (
if "%OP_NOCORRECT%" == "" ( if "%OP_NOCORRECT%" == "" (
call :echo_color %C_O% "%CMD_FILE%" "no diffs" call :echo_color %COLOR_OK% "!CMD_FILE!" "no diffs"
) )
) )
set /a "FILES_OK+=1" set /a "FILES_OK+=1"
@ -190,10 +196,10 @@ REM # ########################################################################
REM # delete temp files REM # delete temp files
if "%OP_NODELETE%" == "" ( if "%OP_NODELETE%" == "" (
if exist "%WAV_OLD%" del /a:a "%WAV_OLD%" if exist "!WAV_OLD!" del /a:a "!WAV_OLD!"
if exist "%TXT_OLD%" del /a:a "%TXT_OLD%" if exist "!TXT_OLD!" del /a:a "!TXT_OLD!"
if exist "%WAV_NEW%" del /a:a "%WAV_NEW%" if exist "!WAV_NEW!" del /a:a "!WAV_NEW!"
if exist "%TXT_NEW%" del /a:a "%TXT_NEW%" if exist "!TXT_NEW!" del /a:a "!TXT_NEW!"
) )
:process_file_continue :process_file_continue
@ -209,39 +215,39 @@ REM # ########################################################################
set CMD_SHORTNAME=%~n1 set CMD_SHORTNAME=%~n1
if "%CMD_SHORTNAME%" == "" goto performance_file_continue if "%CMD_SHORTNAME%" == "" goto performance_file_continue
REM # get file REM # get file (not from arg %1)
set CMD_FILE=%1 set CMD_FILE=!CMD_FILE!
set CMD_FILE=%CMD_FILE:"=% set CMD_FILE=!CMD_FILE:"=!
REM echo VTRS: file %CMD_FILE% REM echo VTRS: file !CMD_FILE!
set WAV_NEW=%CMD_FILE%.test.wav set WAV_NEW=!CMD_FILE!.test.wav
if "%OP_PERFORMANCE%" == "1" ( if "%OP_PERFORMANCE%" == "1" (
set CMD_VGM="%OP_CMD_NEW%" -o "%WAV_NEW%" "%CMD_FILE%" set CMD_VGM="%OP_CMD_NEW%" -o "!WAV_NEW!" "!CMD_FILE!"
) )
if "%OP_PERFORMANCE%" == "2" ( if "%OP_PERFORMANCE%" == "2" (
set CMD_VGM="%OP_CMD_NEW%" -O "%CMD_FILE%" set CMD_VGM="%OP_CMD_NEW%" -O "!CMD_FILE!"
) )
if "%OP_PERFORMANCE%" == "3" ( if "%OP_PERFORMANCE%" == "3" (
set CMD_VGM="%OP_CMD_OLD%" -o "%WAV_OLD%" "%CMD_FILE%" set CMD_VGM="%OP_CMD_OLD%" -o "!WAV_OLD!" "!CMD_FILE!"
) )
if "%OP_PERFORMANCE%" == "4" ( if "%OP_PERFORMANCE%" == "4" (
set CMD_VGM="%OP_CMD_OLD%" -O "%CMD_FILE%" set CMD_VGM="%OP_CMD_OLD%" -O "!CMD_FILE!"
) )
if "%OP_PERFORMANCE%" == "5" ( if "%OP_PERFORMANCE%" == "5" (
set CMD_VGM="%OP_CMD_NEW%" -m "%CMD_FILE%" set CMD_VGM="%OP_CMD_NEW%" -m "!CMD_FILE!"
) )
if "%OP_PERFORMANCE%" == "6" ( if "%OP_PERFORMANCE%" == "6" (
set CMD_VGM="%OP_CMD_OLD%" -m "%CMD_FILE%" set CMD_VGM="%OP_CMD_OLD%" -m "!CMD_FILE!"
) )
%CMD_VGM% 1> nul 2>&1 & REM || goto error !CMD_VGM! 1> nul 2>&1 & REM || goto error
set CMP_WAV_ERROR=0 set CMP_WAV_ERROR=0
if %ERRORLEVEL% NEQ 0 set CMP_WAV_ERROR=1 if %ERRORLEVEL% NEQ 0 set CMP_WAV_ERROR=1
call :echo_color %C_O% "%CMD_FILE%" "done" call :echo_color %COLOR_OK% "!CMD_FILE!" "done"
REM # ignore output REM # ignore output
if exist "%WAV_NEW%" del /a:a "%WAV_NEW%" if exist "!WAV_NEW!" del /a:a "!WAV_NEW!"
:performance_file_continue :performance_file_continue
exit /B exit /B
@ -252,14 +258,17 @@ REM # ########################################################################
REM # hack to get colored output in Windows CMD using findstr + temp file REM # hack to get colored output in Windows CMD using findstr + temp file
REM # ######################################################################## REM # ########################################################################
:echo_color :echo_color
set TEMP_FILE=%2-result REM # don't use %2 but !CMD_FILE!
set TEMP_FILE=%TEMP_FILE:"=% set TEMP_FILE=!CMD_FILE!-result
set TEMP_FILE=!TEMP_FILE:"=!
set TEMP_TEXT=%3 set TEMP_TEXT=%3
set TEMP_TEXT=%TEMP_TEXT:"=% set TEMP_TEXT=!TEMP_TEXT:"=!
echo %TEMP_TEXT% > "%TEMP_FILE%" echo !TEMP_TEXT! > "!TEMP_FILE!"
REM # show colored filename + any text in temp file REM # show colored filename + any text in temp file
findstr /v /a:%1 /r "^$" "%TEMP_FILE%" nul findstr /a:%1 /r ".*" "!TEMP_FILE!" nul
del "%TEMP_FILE%" del "!TEMP_FILE!"
exit /B exit /B
REM :echo_color end, continue from last call REM :echo_color end, continue from last call