-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompressPak.bat
More file actions
391 lines (318 loc) · 8.05 KB
/
CompressPak.bat
File metadata and controls
391 lines (318 loc) · 8.05 KB
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
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
@echo off
set BinPath=Engine\Binaries\Win64
set BinUnrealPak=UnrealPak.exe
set PAKARGS=-compress
set FILEARGS=-compress
set MountPoint=../../../UnrealTournament/
set CustomRoot=
set overwrite=1
set force=0
set uncompress=0
set newversion=
:: -----------------------------------------------------
set script_no_wait=1
set script_silent=0
set UE4Root=%~dp0
if NOT ["%CustomRoot%"] == [""] set UE4Root=%CustomRoot%\
:: Normalize paths
set UE4Root=%UE4Root:\\=\%
set UE4Root=%UE4Root:"=%
set OutDir=%TEMP%\%~n1
set NewPak=%~dp0%~nx1
set UnrealPak=%UE4Root%%BinPath%\%BinUnrealPak%
:: Normalize UnrealPak bin
set OutDir=%OutDir:\\=\%
set OutDir=%OutDir:"=%
set PakDir=%OutDir%\Pak
set PakResponseFile=%OutDir%\list.txt
:: Normalize UnrealPak bin
set UnrealPak=%UnrealPak:\\=\%
set UnrealPak=%UnrealPak:"=%
: Check if opened from CMD
setlocal enabledelayedexpansion
set testl=%cmdcmdline:"=%
set testr=!testl:%~nx0=!
set FromDrop=0
if not "%testl%" == "%testr%" (
:: opened from drag'n'drop
set script_no_wait=0
set FromDrop=1
) else (
:: opened from CMD
set overwrite=0
)
:: check for silent mode
for %%x in (%*) do (
if "%%x"=="-s" (
set script_silent=1
)
)
call :NullLine
call :Header #########################################################################
call :Header =========================================================================
call :Msg UE4 pak file compressing script v0.6
call :Msg by RattleSN4K3
call :Header -------------------------------------------------------------------------
call :Msg A small command line script allowing to re-compress pak files
call :Header -------------------------------------------------------------------------
call :Header
call :Wait 1000
if not exist "%UnrealPak%" goto :Error_BatchFileInWrongLocation
if %1.==. GOTO :Error_NoParameters
if not exist %1 goto :Error_NoPakFile %1
SETLOCAL ENABLEEXTENSIONS
ECHO.%~a1 | find "d" >NUL 2>NUL && (
goto :Error_IsDir %1
)
:: Remove first argument from command line
SET allargs=%*
CALL SET restargs=%%allargs:*%1=%%
SET restargs=%restargs:~1%
:: parse command line arguments. see AssignKeyValue
call :SplitArgs %restargs%
if %uncompress% == 1 (
set PAKARGS=
set FILEARGS=
)
:: Info
call :Msg Processing:
call :Msg %~n1
call :Msg (%~dp1)
call :Msg
call :Msg Options:
if %uncompress% == 1 (
call :Msg - Uncompress file
) else if "%newversion%" NEQ "" (
call :Msg - Overwrite network version: %newversion%
call :Msg
)
if %overwrite% == 1 (
call :Msg - Overwrite original file
) else (
set TempVar1=
set TempVar2=
call :GetPath TempVar1="%NewPak%"
call :GetFilename TempVar2="%NewPak%"
call :Msg - Output file: !TempVar2!
call :Msg - Output dir: !TempVar1!
if %force% == 0 (
if exist "%NewPak%" GOTO :Error_Exists
) else (
call :Msg - Force overwrite output file
)
)
call :Msg
:: Process options
set PakFile=%~1
if %overwrite% == 1 (
set NewPak=%~1
if %FromDrop% == 1 (
echo.
echo.Press any key to continue...
pause > nul
)
)
:: Clean up old temp files
if exist "%OutDir%" (
call :Msg Clean up old temp files...
rmdir "%OutDir%" /s /q
call :Msg Clean up old temp files done.
)
:: Extracting
call :Msg Extracting...
"%UnrealPak%" "%PakFile%" -extract "%PakDir%" > nul
call :Msg Extracting done.
:: Count path depth
set count=0
call :countdepth "%PakDir%"
:: Check mounting
pushd %PakDir%
set subpath=
for /f "tokens=%count%* delims=\" %%f in ('dir /b /s /a-h-s *-AssetRegistry.bin') do (
set subpath=/%%g
set subpath=!subpath:%%~nxg=!
)
set subpath=%subpath:\=/%
if NOT "%subpath%" == "/" (
set MountPoint=!MountPoint:%subpath%=/!
)
popd
:: Check network version
set networkversion=
if "%newversion%" NEQ "" (
pushd %PakDir%
set versionfile=
for /r %PakDir% %%f in (*-version.txt) do (
set versionfile=%%f
set /p networkversion=<%%f
)
popd
call :Msg
call :Msg Current network version: !networkversion!
call :Msg Overwrite with: %newversion%
echo %newversion%>!versionfile!
call :Msg Version set.
call :Msg
)
:: Creating response file
:: preserve pak order (kinda)
set orderfile=%OutDir%\order.txt
"%UnrealPak%" "%PakFile%" -list > %orderfile%
for /F "tokens=*" %%A in (%orderfile%) do (
set InFile=
call :ParseOutputList InFile=%%A
if NOT "!InFile!" == "" (
echo "%PakDir%\!InFile!" "%MountPoint%!InFile!" %FILEARGS%>>%PakResponseFile%
)
)
:: !!! OLD CODE BELOW
:: pushd %PakDir%
:: for /f "tokens=%count%* delims=\" %%f in ('dir /b /s /a-d-h-s') do (
:: echo "%PakDir%\%%g" "%MountPoint%%%g" %FILEARGS%>>%PakResponseFile%
:: )
:: popd
:: !!! OLD CODE END
:: Compressing
if %overwrite% == 1 (
call :Msg Overwriting old pak file
)
call :Msg Compressing...
"%UnrealPak%" "%NewPak%" -create="%PakResponseFile%" %PAKARGS% > nul
call :Msg Compressing done.
:: Deleting temp files
if exist "%OutDir%" (
call :Msg Deleting temp files...
rmdir "%OutDir%" /s /q
call :Msg Deleting temp files done.
)
call :Msg
call :Msg Process done.
call :Wait 5000
goto :Exit
:Error_BatchFileInWrongLocation
call :Msg ERROR:
call :Msg The batch file does not appear to be located in the root UE4 directory.
call :Msg This script must be run from within that directory.
call :Msg
call :Msg or specify 'CustomRoot' in the top of this file.
call :Msg
if %FromDrop% == 1 pause
goto Exit
:Error_NoParameters
call :Msg ERROR:
call :Msg No parameter set.
call :Msg
call :Wait 500
goto Exit
:Error_NoPakFile
call :Msg ERROR:
call :Msg No valid pak file given. Unable to find given file:
call :Msg %~1
call :Msg
call :Wait 1000
goto Exit
:Error_IsDir
call :Msg ERROR:
call :Msg Input file is a directory:
call :Msg %~1
call :Msg
call :Wait 1000
goto Exit
:Error_Exists
call :Msg
call :Msg ERROR:
call :Msg Output file already exists.
call :Msg Use the force option (-f) to overwrite or delete the file.
call :Msg
call :Wait 2000
goto Exit
:Header
if %script_silent% == 0 echo #%*
goto :EOF
:Msg
if %script_silent% == 0 echo # %*
goto :EOF
:NullLine
if %script_silent% == 0 echo.
goto :EOF
:Wait
if %script_no_wait% == 0 @ping 1.1.1.1 -n 1 -w %1 > nul
goto :EOF
:countdepth
set list=%1
set list=%list:"=%
FOR /f "tokens=1* delims=\" %%a IN ("%list%") DO (
if not "%%a" == "" call Set /A count+=1
if not "%%b" == "" call :countdepth "%%b"
)
goto :EOF
:GetFilename
set %~1=%~n2
goto :EOF
:GetPath
set %~1=%~dp2
goto :EOF
:ParseOutputList
:: setlocal enabledelayedexpansion
set string=%*
set "find=*Display: "
call set string=%%string:!find!=%%
set "find=* offset: "
call set delete=%%string:!find!=%%
call set string=%%string:!delete!=%%
:: remove " offset: "
set string=%string:~0,-9%
set first=%string:~0,1%
set first=%first:"=%
if "%first%" == "" (
:: remove quotes
set string=%string:~1,-1%
set %~1=!string!
) else (
set %~1=
)
goto :EOF
:ParseOutputTest
:: setlocal enabledelayedexpansion
set string=%*
set "find=*Display: "
call set string=%%string:!find!=%%
:: remove " OK."
set string=%string:~0,-4%
set first=%string:~0,1%
set first=%first:"=%
if "%first%" == "" (
:: remove quotes
set string=%string:~1,-1%
set %~1=!string!
) else (
set %~1=
)
goto :EOF
:SplitArgs
REM recursive procedure to split off the first two tokens from the input
if "%*" NEQ "" (
REM %%i = KEY, %%j = VALUE, %%k = remainder of input
REM delimiters are space character and equals character
for /F "tokens=1,2,* delims== " %%i in ("%*") do (
call :AssignKeyValue %%i %%j & call :SplitArgs %%j %%k
)
)
goto :eof
:AssignKeyValue
REM KEY %1, VALUE %2
if "%1" EQU "-o" (
SET overwrite=1
) else if "%1" EQU "-f" (
SET force=1
) else if "%1" EQU "-u" (
SET uncompress=1
) else if "%1" EQU "-n" (
SET newversion=%2
) else (
REM Append unrecognised [key,value] to BADARGS
REM echo Unknown KEY %1
REM SET BADARGS=%BADARGS%[%1, %2]
)
goto :eof
:Exit