Skip to content

Commit 9b01642

Browse files
authored
Merge PR #17 from Adam-Kay/update-system-upgrade for v1.5.0 release
Update System Upgrade - Upgrading the update system to pull directly from GitHub releases.
2 parents 11fe17d + 6600c6b commit 9b01642

2 files changed

Lines changed: 57 additions & 28 deletions

File tree

b-e updater.bat

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,22 @@ setlocal enabledelayedexpansion
3838
:Update
3939
cls
4040
echo Downloading information...
41-
curl --silent -o batch_update.txt https://gist.githubusercontent.com/Adam-Kay/ec5da0ff40e8eb14beee2242161f5191/raw
42-
for /f "tokens=1,2,3 delims=|" %%A in (batch_update.txt) do (
43-
set UpdateVersion=%%A
44-
set UpdateAPIURL=%%B
45-
set UpdateBrowserURL=%%C
46-
)
47-
48-
rem Test if any of them are blank
49-
for %%a in (UpdateVersion, UpdateAPIURL, UpdateBrowserURL) do if not defined %%a goto AutoUpdateError
50-
41+
set "updateFileName=batch_update.json"
42+
curl --silent -L -H "Accept: application/vnd.github+json" -o %updateFileName% https://api.github.com/repos/Adam-Kay/Batch-Encoder/releases/latest
43+
rem curl --silent -o batch_update.txt https://gist.githubusercontent.com/Adam-Kay/ec5da0ff40e8eb14beee2242161f5191/raw
44+
45+
>%TEMP%\batch_update.tmp findstr "tag_name" %updateFileName%
46+
<%TEMP%\batch_update.tmp set /p "ver_entry="
47+
set "ver=%ver_entry:~15,-2%"
48+
set "UpdateVersion=v%ver:~1%"
49+
50+
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"
51+
52+
FOR /F "tokens=*" %%g IN ('%regex_command%') do (SET API_link_entry=%%g)
53+
set "UpdateAPIURL=%API_link_entry:~1,-2%"
5154

55+
for %%a in (ver_entry, API_link_entry, UpdateVersion, UpdateAPIURL) do if not defined %%a goto AutoUpdateError
56+
5257
echo Version found^^! ^(%UpdateVersion%^)
5358
echo Proceeding with force update in 5 seconds, press CTRL+C or close window to cancel.
5459
echo.
@@ -63,12 +68,18 @@ setlocal enabledelayedexpansion
6368
del "%BEFile%"
6469
)
6570
)
66-
del "batch_update.txt"
71+
del "%updateFileName%"
6772
(goto) 2>nul & "batch encoder %UpdateVersion%.bat" --updated-from "%~f0"
6873

6974
:AutoUpdateError
75+
del "%updateFileName%"
76+
echo.
77+
echo.
78+
echo *******************************************************
79+
echo There was a problem with the auto-updater. You can download the latest version of the program at:
80+
echo https://github.com/Adam-Kay/Batch-Encoder/releases
7081
echo.
71-
echo There was a problem with the auto-updater. Exiting...
82+
echo Exiting...
7283
echo.
7384
pause
7485
exit

batch encoder.bat

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@echo off
22
setlocal enabledelayedexpansion
33

4-
SET CurrentVersion=v1.4.5
4+
SET CurrentVersion=v1.5.0
55

66
cls
77
if /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

Comments
 (0)