-
Notifications
You must be signed in to change notification settings - Fork 7
/
PatchWwise.bat
65 lines (51 loc) · 1.5 KB
/
PatchWwise.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
:: Copyright (c) Microsoft Corporation. All rights reserved.
:: Licensed under the MIT License.
@echo off
cls
call :PatchFiles Private\AkAudioDevice.cpp AkAudioDevice.cpp.patch 1
call :PatchFiles Public\AkAudioDevice.h AkAudioDevice.h.patch 1
goto :Done
rem args:
rem %~1 file that needs patching
rem %~2 the patch to apply
rem %~3 number of lines from the end of file to start applying patch. All lines after this will be discarded
:PatchFiles
SETLOCAL enableextensions EnableDelayedExpansion
echo Patching %~1 ...
set "filepath=..\..\Wwise\Source\AkAudio\%~1"
set "cmd=findstr /R /N "^^" %filepath% | find /C ":""
rem Count lines in file and compute at what line we need to insert patch
for /f %%a in ('!cmd!') do set number=%%a
set /A number=number-%~3
set "output_file=_tempFile.txt"
set /a linecounter=0
SETLOCAL DisableDelayedExpansion
type nul > "%output_file%"
for /f "tokens=1,* delims=]" %%a in ('type %filepath% ^| find /V /N ""') do (
set "line=%%b"
(echo.%%b)>>%output_file%
call :Increment
SETLOCAL EnableDelayedExpansion
if !linecounter!==!number! goto :break
ENDLOCAL
)
ENDLOCAL
:break
if NOT %~2==NoFilePatch (
echo Applying patch file %~2
SETLOCAL DisableDelayedExpansion
rem append our patch to the file
for /f "tokens=1,* delims=]" %%a in ('type "%~2" ^| find /V /N ""') do (
set "line=%%b"
(echo.%%b)>>%output_file%
)
ENDLOCAL
)
rem replace the original
copy %output_file% %filepath%
del %output_file%
EXIT /B /0
:Increment
set /a linecounter+=1
EXIT /B /0
:Done