-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBiG World Textpack.bat
310 lines (269 loc) · 9.06 KB
/
BiG World Textpack.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
:: BiG World Textpack Installer
:: Process a directory tree and call different commands when some
:: of the following files/directories exist in the mod directory:
:: *.patch => patch with these files
:: _delete => delete all files listed in this file
:: (paths are relative to the mod directory)
:: _rename => like _delete but a line in this file should
:: have the format:
:: path\original-filename\tnew-filename
:: (\t means insert a literal TAB here)
:: _copy => copy the tree to target directory
::
:: _depends => process subdir if the mod is present
:: _depends_not => process subdir if the mod is not present
:: _optional => process subdir if it contains a description
:: and the user has chosen to install it
::
:: If the target directory of a _copy is not the same as the mod name
:: use a _target file in the mod directory to specify the target directory.
:: (Not necessary for patches, since the information is in the patch itself.)
::
:: arguments (all internal, do not use from command line):
:: %1 - directory you want to process
:: %2 - further instructions on how to handle the subdirectories (NOT / OPT)
::
:: error codes
:: 1 => missing main directory
::
@echo off
:: set proper paths
SETLOCAL
cd /d %~dp0
IF exist "BiG World Install.bat" (
if "%BWIP%" == "" (
echo.
echo Please start the "BiG World Install.bat"
echo.
echo Bitte startet die "BiG World Install.bat"
echo.
echo Veuillez lancer le "BiG World Install.bat"
echo.
pause
exit
)
)
:: variable definitions
SET MAIN_DIR=BiG World Textpack GERMAN
SET UTILS=%MAIN_DIR%\_utils
SET MESSAGES=%MAIN_DIR%\_messages
SET INTERACTIVE=true
SET ADD_MISSING_SETUP=true
SET COPY_DIR=_copy
SET DEPENDS_DIR=_depends
SET DEPENDS_NOT_DIR=_depends_not
SET OPTIONAL_DIR=_optional
SET DESC_FILE=_description
SET REN_FILE=_rename
SET DEL_FILE=_delete
SET TARGET_FILE=_target
SET PATCH_FILES=*.patch
SET TP2_FILES=*.tp2
SET COPY_CMD=xcopy /Y /E /R /V
SET PATCH_CMD="%UTILS%\patch" -p0 --no-backup-if-mismatch --ignore-whitespace
SET TEE_CMD="%UTILS%\tee" -a "BiG World Debug.txt"
SET INSTALL_MARKER=BWP_Textpack.installed
SET WEIDU=WeiDU.exe
:: set absolute path for install marker file
SET INSTALL_MARKER=%~dp0\%INSTALL_MARKER%
:: fixes the variable expansion in for loops (using !VAR!)
:: (but introduces a bug related to filenames with exclamation marks)
SETLOCAL ENABLEDELAYEDEXPANSION
:: counter for detecting the last run through this batch
SET /A COUNTER=0
:checks
IF NOT EXIST "%MAIN_DIR%" (
echo.
echo Can't locate the directory "%MAIN_DIR%".
echo Make sure it resides in the current directory!
echo.
echo.
echo Das Verzeichnis "%MAIN_DIR%" konnnte nicht gefunden werden.
echo Es ist fr die Installation zwingend erforderlich
echo und muss im aktuellen Verzeichnis vorhanden sein.
echo.
pause
exit /B 1
)
IF NOT EXIST "%WEIDU%" (
call :show_message "%MESSAGES%\missing_weidu.txt"
)
IF NOT EXIST "%INSTALL_MARKER%" (
type nul >"%INSTALL_MARKER%"
)
:start
cls
type "%MESSAGES%\header.txt" | %TEE_CMD%
call :show_message "%MESSAGES%\start.txt"
IF EXIST "BiG World Install.bat" goto :BEGINN
echo.
echo.
echo.
echo.
echo.
echo.
:start6
echo.
echo.
echo.
echo. T E X T - A N G L E I C H U N G
echo.
echo.
echo.
echo.
echo. Ihr k”nnt eine alternative Textversion fr die deutschen
echo. Texte w„hlen. Dadurch werden die ansonsten unterschiedlichen
echo. Beschreibungen der Gegenst„nde und Zauber vereinheitlicht.
echo.
echo. Wollt Ihr die Beschreibungen nach gleichem Schema anpassen?
echo. (empfohlen)
echo.
echo.
echo.
echo.
set /P X= (J)a - (N)ein . . .
echo.
if /I "%X%"=="J" goto :JHARMON
if /I "%X%"=="N" goto :BEGINN
echo.
echo.
echo. Ihr habt keine Wahl getroffen. Wiederholt es bitte nochmals.
echo.
echo.
goto :start6
:JHARMON
IF EXIST "BiG World Textpack" xcopy /Y /S /E ".\BiG World Textpack\_Textharmonisation" ".\BiG World Textpack"
:BEGINN
:process
SET /A COUNTER=%COUNTER% + 1
:: set current directory for recursive processing
:: also try to workaround the ampersand in dirname problem
IF "x%~1" == "x" (SET CUR_DIR="%MAIN_DIR%") ELSE SET CUR_DIR="%~1"
SET CUR_DIR=%CUR_DIR:&=^&%
SET CUR_DIR=%CUR_DIR:"=%
:: walk the tree
FOR /D %%d IN ("%CUR_DIR%\*") DO (
:: check if the mod does (not) exist in the game dir ^
:: also search for modname.tp2 and setup-modname.tp2 ^
:: (we need a helper variable because it's not possible combine IFs with OR)
SET DO_STUFF=false
IF "x%~2" == "x" (
IF EXIST "%%~nd" SET DO_STUFF=true
IF EXIST "%%~nd.tp2" SET DO_STUFF=true
IF EXIST "setup-%%~nd.tp2" SET DO_STUFF=true
) ELSE (
IF "%~2" == "NOT" (
IF NOT EXIST "%%~nd" IF NOT EXIST "%%~nd.tp2" IF NOT EXIST "setup-%%~nd.tp2" SET DO_STUFF=true
) ELSE (
IF "%~2" == "OPT" IF "%~3" == "%%~nd" SET DO_STUFF=true
)
)
IF "%CUR_DIR%" == "%MAIN_DIR%" (
:: also check if we already patched this mod ^
:: errorlevel is somehow bugged, so we need a workaround (for loop)
FOR /F %%x IN ('findstr /B /E /I "%%~nd" "%INSTALL_MARKER%"') DO (
echo.
echo skipping "%%~nd" [already fixed]| %TEE_CMD%
SET DO_STUFF=false
)
)
IF "!DO_STUFF!" == "true" (
IF "%CUR_DIR%" == "%MAIN_DIR%" (
echo.
echo processing fixes for "%%~nd"| %TEE_CMD%
echo.
SET TARGET_DIR=%%~nd
:: look for TARGET_FILE which can override target directory
IF EXIST "%%d\%TARGET_FILE%" (
FOR /F "usebackq delims=" %%x IN ("%%d\%TARGET_FILE%") DO SET TARGET_DIR=%%x
)
)
FOR %%p IN ("%%d\%PATCH_FILES%") DO (
:: ugly workaround for MS bug related to delayed expansion
SETLOCAL DISABLEDELAYEDEXPANSION
SET p=%%p
SETLOCAL ENABLEDELAYEDEXPANSION
%PATCH_CMD% < "!p!" | %TEE_CMD%
ENDLOCAL
ENDLOCAL
)
:: special handling for tp2s (do not use this!)
FOR %%t IN ("%%d\%TP2_FILES%") DO (
copy /Y "%%t" "." | %TEE_CMD%
)
IF EXIST "%%d\%DEL_FILE%" (
echo.
echo deleting files ...| %TEE_CMD%
FOR /F "usebackq delims=" %%x IN ("%%d\%DEL_FILE%") DO (
echo !TARGET_DIR!\%%x| %TEE_CMD%
del /F "!TARGET_DIR!\%%x"
)
)
IF EXIST "%%d\%REN_FILE%" (
echo.
echo renaming files ...| %TEE_CMD%
FOR /F "usebackq delims=" %%x IN ("%%d\%REN_FILE%") DO (
FOR /F "tokens=1,2 delims= " %%y IN ("%%x") DO (
echo !TARGET_DIR!\%%y %%z| %TEE_CMD%
ren "!TARGET_DIR!\%%y" "%%z"
)
)
)
IF EXIST "%%d\%COPY_DIR%" IF EXIST "!TARGET_DIR!" (
echo.
echo copying files ...| %TEE_CMD%
%COPY_CMD% "%%d\%COPY_DIR%" "!TARGET_DIR!" | %TEE_CMD%
)
IF EXIST "%%d\%DEPENDS_DIR%" call :process "%%d\%DEPENDS_DIR%"
IF EXIST "%%d\%DEPENDS_NOT_DIR%" call :process "%%d\%DEPENDS_NOT_DIR%" NOT
IF EXIST "%%d\%OPTIONAL_DIR%" IF "%INTERACTIVE%" == "true" (
FOR /D %%o IN ("%%d\%OPTIONAL_DIR%\*.*") DO (
IF EXIST "%%o\%DESC_FILE%" (
echo.
type "%%o\%DESC_FILE%"
:query_optional
type "%MESSAGES%\opt_install.txt"
SET /P ACTION=
IF /I "!ACTION!" NEQ "I" IF /I "!ACTION!" NEQ "N" goto query_optional
IF /I "!ACTION!" EQU "I" (
echo.
echo processing optional component "%%~no"| %TEE_CMD%
call :process "%%d\%OPTIONAL_DIR%" OPT "%%~no"
)
)
)
)
:: we are done for this mod
IF "%CUR_DIR%" == "%MAIN_DIR%" (
echo %%~nd>>"%INSTALL_MARKER%"
)
)
)
SET /A COUNTER=%COUNTER% - 1
IF NOT %COUNTER% == 0 goto :EOF
:add_missing_setup_files
IF EXIST "%WEIDU%" IF "%ADD_MISSING_SETUP%" == "true" (
FOR %%t IN ("*.tp2") DO (
SET FOUND=false
SET BASENAME=%%~nt
IF EXIST "!BASENAME!.exe" SET FOUND=true
IF EXIST "setup-!BASENAME!.exe" SET FOUND=true
IF NOT "!FOUND!" == "true" (
IF /I "!BASENAME:~0,6!" EQU "setup-" (
copy /Y "WeiDU.exe" "!BASENAME!.exe" >nul
) ELSE (
copy /Y "WeiDU.exe" "setup-!BASENAME!.exe" >nul
)
)
)
)
:finished
call :show_message "%MESSAGES%\end.txt"
exit /B 0
:show_message
IF "%INTERACTIVE%" == "true" (
echo.
type %1
echo.
IF NOT EXIST "BiG World Installpack\Big World Smoothpack" pause
)