11@ echo off
22setlocal enabledelayedexpansion
33
4- SET CurrentVersion = v1.4.5
4+ SET CurrentVersion = v1.5.0
55
66cls
77if /i " %1 " == " --updated-from" (
@@ -29,15 +29,23 @@ if /i "%1"=="--updated-from" (
2929:AutoUpdate
3030 call :ClearAndTitle
3131 echo Downloading information...
32- curl --silent -o batch_update.txt https://gist.githubusercontent.com/Adam-Kay/ec5da0ff40e8eb14beee2242161f5191/raw
33- for /f " tokens=1,2,3 delims=|" %%A in (batch_update.txt) do (
34- set UpdateVersion = %%A
35- set UpdateAPIURL = %%B
36- set UpdateBrowserURL = %%C
37- )
32+ set " updateFileName = batch_update.json"
33+ curl --silent -L -H " Accept: application/vnd.github+json" -o %updateFileName% https://api.github.com/repos/Adam-Kay/Batch-Encoder/releases/latest
34+ rem curl --silent -o batch_update.txt https://gist.githubusercontent.com/Adam-Kay/ec5da0ff40e8eb14beee2242161f5191/raw
35+
36+ > %TEMP% \batch_update.tmp findstr " tag_name" %updateFileName%
37+ < %TEMP% \batch_update.tmp set /p " ver_entry = "
38+ set " ver = %ver_entry:~15 ,-2 % "
39+ set " UpdateVersion = v%ver:~1 % "
40+
41+ set regex_command = powershell -Command " $x = Get-Content %updateFileName% -Raw; $k = $x | Select-String -Pattern '(?s)url(((?^^^!url).)*?)batch\.encoder'; $g = $k.Matches.Value | Select-String -Pattern '^" " [^^^^" " " ]+?^ " " " ,'; $g.Matches.Value"
42+
43+ FOR /F " tokens=*" %%g IN ('%regex_command% ') do (SET API_link_entry=%%g )
44+ set " UpdateAPIURL = %API_link_entry:~1 ,-2 % "
3845
39- rem Test if any of them are blank
40- for %%a in (UpdateVersion, UpdateAPIURL, UpdateBrowserURL) do if not defined %%a goto AutoUpdateError
46+ for %%a in (ver_entry, API_link_entry, UpdateVersion, UpdateAPIURL) do if not defined %%a goto AutoUpdateError
47+
48+ if exist " batch encoder %UpdateVersion% .bat" set " append = _new"
4149
4250 echo .
4351 if /i " %UpdateVersion% " == " %CurrentVersion% " (
@@ -46,20 +54,20 @@ if /i "%1"=="--updated-from" (
4654 echo Restarting program...
4755 echo .
4856 pause
49- del " batch_update.txt "
57+ del " %updateFileName% "
5058 goto AskProceed
5159 ) else (
5260 echo Differing version found^^! ^ (%CurrentVersion% -^ > %UpdateVersion% ^ )
5361 echo Proceeding with update in 5 seconds, press CTRL+C or close window to cancel.
5462 echo .
5563 timeout /nobreak /t 5 > nul
5664 echo Downloading files...
57- curl --silent -L -H " Accept: application/octet-stream" -o " batch encoder %UpdateVersion% .bat" %UpdateAPIURL%
65+ curl --silent -L -H " Accept: application/octet-stream" -o " batch encoder %UpdateVersion%%append% .bat" %UpdateAPIURL%
5866 echo .
5967 echo Download complete. The program will now clean up and restart.
6068 pause
61- del " batch_update.txt "
62- (goto) 2 > nul & " batch encoder %UpdateVersion% .bat" --updated-from " %~f0 "
69+ del " %updateFileName% "
70+ (goto) 2 > nul & " batch encoder %UpdateVersion%%append% .bat" --updated-from " %~f0 "
6371 )
6472
6573:FFMPEGLocation
@@ -122,8 +130,12 @@ set "INPUTFILE="
122130 echo .
123131
124132 echo Checking output file length...
125- FOR /F " tokens=*" %%g IN ('powershell -Command " $Shell = New-Object -ComObject Shell.Application; $Folder = $Shell.Namespace('%cd% '); $Folder.GetDetailsOf($Folder.ParseName('!INPUTFILE! '), 27)" ') do (SET LEN_INP=%%g )
126- FOR /F " tokens=*" %%g IN ('powershell -Command " $Shell = New-Object -ComObject Shell.Application; $Folder = $Shell.Namespace('%cd% '); $Folder.GetDetailsOf($Folder.ParseName('!OUTPUTFILE! '), 27)" ') do (SET LEN_OUT=%%g )
133+ FOR /F " tokens=*" %%g IN (
134+ 'powershell -Command " $Shell = New-Object -ComObject Shell.Application; $Folder = $Shell.Namespace('%cd% '); $Folder.GetDetailsOf($Folder.ParseName('!INPUTFILE! '), 27)" '
135+ ) do (SET LEN_INP=%%g )
136+ FOR /F " tokens=*" %%g IN (
137+ 'powershell -Command " $Shell = New-Object -ComObject Shell.Application; $Folder = $Shell.Namespace('%cd% '); $Folder.GetDetailsOf($Folder.ParseName('!OUTPUTFILE! '), 27)" '
138+ ) do (SET LEN_OUT=%%g )
127139 echo Input file: !LEN_INP! - Output file: !LEN_OUT!
128140 if /i NOT " !LEN_INP! " == " !LEN_OUT! " goto CritError
129141 echo - File lengths match^^!
@@ -157,8 +169,14 @@ echo **********************************
157169 goto EndPause
158170
159171:AutoUpdateError
172+ del " %updateFileName% "
173+ echo .
174+ echo .
175+ echo *******************************************************
176+ echo There was a problem with the auto-updater. You can download the latest version of the program at:
177+ echo https://github.com/Adam-Kay/Batch-Encoder/releases
160178 echo .
161- echo There was a problem with the auto-updater. Restarting program...
179+ echo Restarting program...
162180 echo .
163181 pause
164182 goto AskProceed
0 commit comments