-
Notifications
You must be signed in to change notification settings - Fork 1
/
bf_updater.bat
324 lines (260 loc) · 7.96 KB
/
bf_updater.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
:: https://www.mbnq.pl/
@echo off
setlocal enabledelayedexpansion
title Brute Force Updater
color 09
if exist ".gitattributes" (
echo Warning^^! detected repo files^^!
goto bye
)
call :intro
echo This script will update Brute Force to the latest available version.
echo Custom maps and user options will remain saved.&&echo.
echo If you encounter an error during updating run updater once again.&&echo.
call :readVersion
call :readLatestVersion
echo.
choice /C YN /M "- Do you want to run autoupdater? (Y/N)"
if not %errorlevel% equ 1 (
call :intro
echo Update aborted.
goto bye
)
echo.
echo - Checking files...
if not exist gamemd.exe (
call :error0001
echo Cannot find gamemd.exe^^!
goto bye
)
taskkill /im clientdx.exe > nul
taskkill /im gamemd.exe > nul
cls
call :intro
set "gameRoot=%cd%"
cd "%gameRoot%"
set url=https://bf.mbnq.pl/patch/ra2yrbf_patch.zip
set psScriptName=bf_downloadLatest2.ps1
set "psScriptUrl=https://raw.githubusercontent.com/mbnq/RA2YRBF/main/tools/bf_tools/OtherScripts/%psScriptName%"
set bfTempPath=bftmp
set extractedPath=%bfTempPath%\extracted
set backupPath=%bfTempPath%\backup
set downloadedFile=%bfTempPath%\ra2yrbf_patch.zip
set "bfFiles=INI Maps Resources tools debug audio.bag audio.idx syringe.log spawn.ini rmgmd.ini soundmd.ini spawnmap.ini mpmbnqdummy.ini urbannmd.ini urbanmd.ini temperatmd.ini snowmd.ini desertmd.ini lunarmd.ini rulesmd.ini aimd.ini artmd.ini uimd.ini artmd.ini evamd.ini rbcvbf.ini mpzombie.ini mpmodesmd.ini mpbrutedoomsday2.ini mpanimaldoomsday2.ini heroicvehicles.ini heroicbuildings.ini heroicshields.ini heroicsidebonus.ini heroicbuildingsciv.ini heroicinfantry.ini heroicAI.ini ares.dll ares.dll.inj ares.mix BFLauncher.exe BFLauncherUnix.sh changelog.temp.txt cncnet5.dll expandmd70.mix expandmd71.mix expandmd72.mix expandmd73.mix gamemd.exe Phobos.dll Phobos.pdb qres.dat qres32.dll README.md Syringe.exe bfAI.ini bfAnimal.ini bfBrute.ini bfBuildings.ini bfBuildingsCiv.ini bfInfantry.ini bfLoot.ini bfRMCV.ini bfShields.ini bfSideBonus.ini bfVehicles.ini bfZombie.ini"
set /a checkCounter=0
set /a checkAll=10
if not exist "%bfTempPath%" mkdir "%bfTempPath%"
if not exist "%extractedPath%" mkdir "%extractedPath%"
if not exist "%backupPath%" mkdir "%backupPath%"
if not exist "%bfTempPath%" (
call :error0001
echo Was not able to create temporary files.
goto bye
)
echo.
echo - Creating backup of user settings and maps...
echo.
copy /y RA2MD.ini "%backupPath%\RA2MD.ini" > nul
xcopy /s /e /y "%gameRoot%\Maps\Custom\" "%backupPath%\Custom\" > nul
if %ERRORLEVEL% neq 0 (
echo Failed to backup user custom maps.
echo If you want to abort close the updater now or press any key to ignore.
pause > nul
)
if not exist "%backupPath%\RA2MD.ini" (
echo:Was not able to backup user settings.
echo If you want to abort close the updater now or press any key to ignore.
pause > nul
)
call :sleep
echo.
echo - Downloading the latest RA2YRBF version available...
echo.
:: ---------------------------------------------------------------------------------------------
:WITHGH
echo.
echo - Downloading github downloader script...
echo.
powershell -Command "Invoke-WebRequest -Uri %psScriptUrl% -OutFile %psScriptName%" > nul
if %ERRORLEVEL% neq 0 (
echo Failed to download downloader script.
goto WITHCURL
)
echo.
echo - Starting github downloader script...
echo.
if exist %psScriptName% (
powershell -ExecutionPolicy Bypass -File %psScriptName%
) else (
echo Failed to run downloader script will try with CURL now...
goto WITHCURL
)
if %ERRORLEVEL% neq 0 (
echo Failed to run downloader script will try with CURL now...
goto WITHCURL
)
MOVE /Y "ra2yrbf_latest.zip" "%downloadedFile%" > nul
call :sleep
if exist "%downloadedFile%" goto EXTRACT
:: ---------------------------------------------------------------------------------------------
:WITHCURL
where curl > nul 2> nul
if %ERRORLEVEL% neq 0 (
call :error0001
echo Cannot find curl.exe^^!
goto bye
)
echo.
echo - Downloading with CURL...
echo.
curl -L -k -o "%downloadedFile%" "%url%"
if %ERRORLEVEL% neq 0 (
call :error0001
echo Failed to download the update files.
goto bye
)
call :sleep
:: ---------------------------------------------------------------------------------------------
:EXTRACT
echo.
echo - Extracting new mod files...
powershell -Command "Expand-Archive -Path '%downloadedFile%' -DestinationPath '%extractedPath%'" > nul
if %ERRORLEVEL% neq 0 (
call :error0001
echo Failed to extract the update files^^!
goto bye
)
call :sleep
echo.
echo - Unblocking files...
powershell -Command "dir -r '%extractedPath%' | Unblock-File"
if %ERRORLEVEL% neq 0 (
echo.
echo BF Updater was unable to unblock the files^^!
echo You may need to do that manually.
echo.
echo Press any key to continue updating...
pause > nul
)
call :sleep
move /y "%extractedPath%\RA2YRBF\bf_updater.bat" "%backupPath%"\bf_updater.bat > nul
call :sleep
:uninstall
for %%f in (%bfFiles%) do (
if exist "%%f" (
echo Deleting: %%f
del /Q /f "%%f"
rd /Q /s "%%f"
call :intro
echo.
echo - Uninstalling old files...
echo.
)
)
if exist "cnc-ddraw config.exe" del /q /f "cnc-ddraw config.exe" > nul
call :sleep
:install
call :intro
echo.
echo - Copying new version mod files...
xcopy /s /e /y "%extractedPath%\RA2YRBF\*" * > nul
if %ERRORLEVEL% neq 0 (
call :error0001
echo Failed to copy the update files into the game folder^^!
goto bye
)
call :sleep
:restore
echo.
echo - Restoring player settings and maps...
copy /y "%backupPath%\RA2MD.ini" "RA2MD.ini" > nul
if %ERRORLEVEL% neq 0 (
call :error0001
echo Failed to restore player settings^^!
goto bye
)
xcopy /s /e /y "%backupPath%\Custom\" "%gameRoot%\Maps\Custom\" > nul
if %ERRORLEVEL% neq 0 (
call :error0001
echo Failed to restore player settings^^!
goto bye
)
call :sleep
echo.
echo - Cleaning up...
copy /y "%backupPath%\bf_updater.bat" "bf_updater.bat" > nul
call :sleep
rd /s /q "%bfTempPath%" > nul
if exist %psScriptName% del /q /f %psScriptName% > nul
if %ERRORLEVEL% neq 0 (
call :error0001
goto bye
)
call :sleep
if %checkCounter% neq %checkAll% (
call :error0001
goto bye
)
call :readVersion
call :intro
echo Success^^!
echo Mod files have been updated.
call :readVersion
goto bye
:bye
echo.
echo Press any key to quit this updater...
pause > nul
endlocal
exit
:readVersion
if exist "readme.md" (
for /f "tokens=1,* delims=:" %%a in ('findstr /c:"Version" "readme.md"') do (
set "bfversionR=%%b"
set "bfversionR=!bfversionR:~1!"
)
set bfversion=!bfversionR!
) else (
set bfversion=unknown
)
echo Current version is: %bfversion%
exit /b
:readLatestVersion
powershell -NoProfile -Command ^
"$url = 'https://raw.githubusercontent.com/mbnq/RA2YRBF/main/README.md';" ^
"$html = Invoke-WebRequest -Uri $url;" ^
"$versionLine = $html.Content -split \"`n\" | Where-Object { $_ -match 'Version: ' };" ^
"if ($versionLine -match 'Version:\s*(\S+)') {" ^
" $version = $matches[1];" ^
" Write-Host 'Latest version is: ' $version;" ^
"} else {" ^
" Write-Host 'Latest version is: not found.';" ^
"}"
exit /b
:sleep
set /a checkCounter=%checkCounter%+1
title [%checkCounter%/%checkAll%] BF Updater > nul
timeout /t 1 > nul
exit /b
:intro
cls
echo *********************************************************
echo * *
echo * Command ^& Conquer Yuri^'s Revenge - Brute Force Mod *
echo * *
echo * mbnq.pl 2024 *
echo * *
echo *********************************************************
echo.
exit /b
:error0001
echo.
echo EEEEEEE EEEEEE EEEEEE EEEEEE EEEEEE
echo EE EE EE EE EE EE EE EE EE
echo EEEEE EEEEEE EEEEEE EE EE EEEEEE
echo EE EE EE EE EE EE EE EE EE
echo EEEEEEE EE EE EE EE EEEEEE EE EE
echo.
echo Something went wrong. You can try again.
exit /b