@@ -18,13 +18,16 @@ set "formatend=[0m"
1818)
1919set " space = "
2020
21+ set " starttime = %TIME% "
22+
2123for %%G in (%* ) DO (if " %%G " == " --debug" (set " par_debug=true" & goto ArgParser))
2224
2325:ArgParser
26+ set " allargs = %* "
2427 set " FLAG = 0"
2528 for %%G in (%* ) DO (
2629 set ARG = %%G
27- :: if FLAG, record the flag name
30+ rem if FLAG, record the flag name
2831 echo !ARG! | findstr " \--" > nul && (
2932 if not [" !FLAG! " ]== [" 0" ] ( rem Check if FLAG is set - if it is, then previous was a boolean.
3033 set " par_!FLAG! = true"
@@ -44,25 +47,45 @@ for %%G in (%*) DO (if "%%G"=="--debug" (set "par_debug=true" & goto ArgParser))
4447 set " par_!FLAG! = true"
4548 if " %par_debug% " == " true" (echo %iconyellow% par_!FLAG! =TRUE%formatend% )
4649 )
47-
48- if not defined par_selfwrapped (
49- cmd /c " %~f0 " %* --selfwrapped || (set " wraperror=true" )
50+
51+ if not " %par_selfwrapped% " == " true" (
52+ cmd /c " " %~f0 " %* --selfwrapped" || (set " wraperror=true" )
53+ echo UNWRAPPED ^ (!errorlevel! ^ )
54+ echo Returning to instance %starttime%
55+ echo Currentargs: %*
56+ echo Currentargs2: !allargs!
5057 if " !wraperror! " == " true" (
58+ < %TEMP% \batch_update.tmp set /p " newfilename = "
59+ echo newfilename: !newfilename!
60+ pause
61+ rem If errorlevel is negative, it's a restart command:
62+ rem Standard restart
63+ if " !errorlevel! " == " -1" (
64+ echo ERROR MINUS 1 - RESTART REQUESTED
65+ pause
66+ " %~f0 "
67+ )
68+ rem Restart after update
69+ if " !errorlevel! " == " -2" (!newfilename! --updated-from " %~f0 " )
70+ rem Restart after update (with silent, so passing previous args)
71+ rem if "!errorlevel!"=="-3" ((goto) 2> nul & !newfilename! --updated-from "%~f0" %* --update false --selfwrapped false)
72+
73+ rem If errorlevel starts with 101, it's already been handled
5174 if " !errorlevel:~0 ,3 ! " == " 101" (
52- :: if errorlevel starts with 101, it's already been handled
53- set " errorlevel = !errorlevel:~3 !
75+ set " errorlevel = !errorlevel:~3 ! "
5476 ) else (
5577 call :CritError " Wrapper critically exited with error code !errorlevel! ."
5678 )
5779 )
80+ echo about to exit with code !errorlevel!
5881 exit /b !errorlevel!
5982)
6083
6184if " %par_debug% " == " true" (pause)
6285cls
6386
6487if defined par_help (
65- :: list help for args, then exit
88+ rem list help for args, then exit
6689 echo %formatend% Help for Batch Encoder %CurrentVersion%
6790 echo Program usage:
6891 echo .
@@ -96,7 +119,7 @@ if defined par_help (
96119if defined par_updated-from (
97120 echo %icongray% ^^! %formatend% Just updated^^! Running cleanup...
98121 timeout /nobreak 2 > nul
99- :: ↓ special format to remove " from string
122+ rem ↓ special format to remove " from string
100123 if exist " %par_updated-from:" =% " (del " %par_updated-from:" =% " )
101124)
102125
@@ -131,7 +154,7 @@ if defined par_updated-from (
131154 if exist " batch encoder %UpdateVersion%%append% -u.bat" (del " batch encoder %UpdateVersion%%append% -u.bat" )
132155 echo %icongray% i %formatend% Downloading information...
133156 set " updateFileName = batch_update.json"
134- curl --silent -L -H " Accept: application/vnd.github+json" -H " X-GitHub-Api-Version:2022-11-28" -o %updateFileName% https://api.github.com/repos/Adam-Kay/Batch-Encoder/releases/latest
157+ rem curl --silent -L -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version:2022-11-28" -o %updateFileName% https://api.github.com/repos/Adam-Kay/Batch-Encoder/releases/latest
135158 if not exist " %updateFileName% " (goto AutoUpdateError)
136159
137160 > %TEMP% \batch_update.tmp findstr " tag_name" %updateFileName%
@@ -175,7 +198,7 @@ if defined par_updated-from (
175198 if /i " %par_silent% " == " true" (
176199 (goto) 2 > nul & " %~f0 " %* --update false
177200 ) else (
178- (goto) 2 > nul & " %~f0 "
201+ exit -1
179202 )
180203 )
181204 )
@@ -186,7 +209,7 @@ if defined par_updated-from (
186209 echo %iconyellow% ^^! %formatend% Differing version found^^! ^ (%textred%%CurrentVersion%%formatend% -^ > %textgreen%%UpdateVersion%%formatend% ^ )
187210 echo Proceeding with update in 5 seconds; close window to cancel.
188211 )
189- :: ... anim
212+ rem ... anim
190213 echo . & echo [s
191214 for /l %%x in (1, 1, 6) do (
192215 timeout /nobreak /t 1 > nul
@@ -212,12 +235,17 @@ if defined par_updated-from (
212235 echo You can read the full changelog at: https://github.com/Adam-Kay/Batch-Encoder/releases
213236 echo .
214237 echo %icongray% i %formatend% The program will now clean up and restart.
238+ pause rem REMOVE
215239 call :GrayPause
216240 if exist " %updateFileName% " (del " %updateFileName% " )
241+ echo " batch encoder %UpdateVersion%%append% .bat" > %TEMP% \batch_update.tmp
217242 if /i " %par_silent% " == " true" (
218- (goto) 2 > nul & " batch encoder %UpdateVersion%%append% .bat" --updated-from " %~f0 " %* --update false
243+ exit -3
244+ rem (goto) 2> nul & (goto) 2> nul & "batch encoder %UpdateVersion%%append%.bat" --updated-from "%~f0" %* --update false --selfwrapped false
245+ rem cmd /c ""batch encoder %UpdateVersion%%append%.bat" --updated-from "%~f0" %* --update false --selfwrapped false" & exit
219246 ) else (
220- (goto) 2 > nul & " batch encoder %UpdateVersion%%append% .bat" --updated-from " %~f0 "
247+ exit -2
248+ rem "batch encoder %UpdateVersion%%append%.bat" --updated-from "%~f0"
221249 )
222250
223251
@@ -392,14 +420,14 @@ if defined par_updated-from (
392420 set " OUTPUTFILE = !INPUTFILE:~0 ,-8 ! .ENC.mp4"
393421 ) else (
394422 set " outputfiledupe = true"
395- set " OUTPUTFILE = !INPUTFILE:~0 ,-8 ! _!date! -!time: : =- ! .ENC.mp4"
423+ set " OUTPUTFILE = !INPUTFILE:~0 ,-8 ! _!date! -!timerem =-! .ENC.mp4"
396424 )
397425 ) else (
398426 if not exist " !INPUTFILE:~0 ,-4 ! .ENC.mp4" (
399427 set " OUTPUTFILE = !INPUTFILE:~0 ,-4 ! .ENC.mp4"
400428 ) else (
401429 set " outputfiledupe = true"
402- set " OUTPUTFILE = !INPUTFILE:~0 ,-4 ! _!date! -!time: : =- ! .ENC.mp4"
430+ set " OUTPUTFILE = !INPUTFILE:~0 ,-4 ! _!date! -!timerem =-! .ENC.mp4"
403431 )
404432 )
405433
@@ -429,7 +457,7 @@ if defined par_updated-from (
429457 ) do (set LEN_INP=%%g )
430458 for /F " tokens=*" %%g in ( 'powershell -Command " (^& '%LOCATION_pwsh% ' -i '!OUTPUTFILE! ' 2>&1 | select-String 'Duration: (.*), s').Matches.Groups[1].Value" '
431459 ) do (set LEN_OUT=%%g )
432- for /F " tokens=*" %%g in ( 'powershell -Command " [Math]:: Abs(((Get-Date !LEN_INP! ) - (Get-Date !LEN_OUT! )).TotalSeconds)" '
460+ for /F " tokens=*" %%g in ( 'powershell -Command " [Math]rem Abs(((Get-Date !LEN_INP! ) - (Get-Date !LEN_OUT! )).TotalSeconds)" '
433461 ) do (set LEN_DIFF=%%g )
434462
435463 echo Input file: !LEN_INP! - Output file: !LEN_OUT!
@@ -455,8 +483,8 @@ if defined par_updated-from (
455483 )
456484 echo %icongreen% ^ | %formatend% Safely proceeding with input file recycling...
457485 if exist " !INPUTFILE! " (
458- :: delete to recycle bin
459- powershell -Command " Add-Type -AssemblyName Microsoft.VisualBasic; [Microsoft.VisualBasic.FileIO.FileSystem]:: DeleteFile('%CD% \!INPUTFILE! ','OnlyErrorDialogs','SendToRecycleBin')"
486+ rem delete to recycle bin
487+ powershell -Command " Add-Type -AssemblyName Microsoft.VisualBasic; [Microsoft.VisualBasic.FileIO.FileSystem]rem DeleteFile('%CD% \!INPUTFILE! ','OnlyErrorDialogs','SendToRecycleBin')"
460488 )
461489 )
462490 )
@@ -497,13 +525,13 @@ if %TOTAL% equ 0 (echo [100;37m No files found. %formatend%)
497525 if / i " %par_silent%" == " true" (call:CtrlExit 2)
498526 echo The program will now restart.
499527 call :GrayPause
500- (goto) 2 > nul & " %~f0 "
528+ exit -1
501529
502530:CtrlExit
503- if defined par_selfwrapped (
531+ if " % par_selfwrapped% " == " true " (
504532 exit 101%~1
505533 )
506- :: go one level up (out of subroutine), then exit
534+ rem go one level up (out of subroutine), then exit
507535 (goto) 2 > nul || exit /b %~1
508536
509537:GrayPause
@@ -534,6 +562,6 @@ if %TOTAL% equ 0 (echo [100;37m No files found. %formatend%)
534562 cls
535563 set " message = %~1 "
536564 if defined message (set " message=- %message% " )
537- echo [7m Batch Encoder %CurrentVersion% %message%%formatend%
565+ echo [7m Batch Encoder %CurrentVersion% %message%%formatend% ( %starttime% ) ( %allargs% )
538566 echo .
539567 goto :eof
0 commit comments