-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparameter-manager.bat
More file actions
621 lines (592 loc) · 24.2 KB
/
Copy pathparameter-manager.bat
File metadata and controls
621 lines (592 loc) · 24.2 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
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
@echo off
setlocal EnableExtensions DisableDelayedExpansion
rem Classic console guard: Windows Terminal hosts console apps in a pseudoconsole
rem that cannot deliver the console close-event protection and can hide the
rem SAFE TO CLOSE shutdown flow. When this launcher is started from Windows
rem Terminal, restart it in the classic Windows Console Host first.
if defined _JAROCK_CLASSIC_CONSOLE goto :classic_console_ok
if not defined WT_SESSION goto :classic_console_ok
if not exist "%~dp0scripts\classic-console.bat" goto :classic_console_ok
set "_JAROCK_CLASSIC_CONSOLE=1"
call "%~dp0scripts\classic-console.bat" "Jarock classic console" "%~f0" /wait
echo.
echo Jarock was relaunched in the classic Windows console because it was started from Windows Terminal.
exit /b 0
:classic_console_ok
rem Run from an isolated copy so an update can safely replace this batch file.
rem cmd.exe reads batch files by position; replacing the active file otherwise can
rem execute fragments of the new file while this parameter manager is still open.
if /i "%~nx0"=="parameter-manager-runner.bat" if defined _JAROCK_PARAMETER_MANAGER_ROOT goto :runner_start
set "ROOT=%~dp0"
if "%ROOT:~-1%"=="\" set "ROOT=%ROOT:~0,-1%"
if not exist "%ROOT%\.cache" mkdir "%ROOT%\.cache" >nul 2>&1
if exist "%ROOT%\.cache\parameter-manager-runner.bat" del /q "%ROOT%\.cache\parameter-manager-runner.bat" >nul 2>&1
copy /y "%~f0" "%ROOT%\.cache\parameter-manager-runner.bat" >nul 2>&1
if not exist "%ROOT%\.cache\parameter-manager-runner.bat" goto :runner_fallback
set "_JAROCK_PARAMETER_MANAGER_ROOT=%ROOT%"
call "%ROOT%\.cache\parameter-manager-runner.bat" %*
set "RUNNER_EXIT_CODE=%errorlevel%"
del /q "%ROOT%\.cache\parameter-manager-runner.bat" >nul 2>&1
exit /b %RUNNER_EXIT_CODE%
:runner_fallback
echo ERROR: Could not create the isolated parameter-manager runner.
echo Suggested fix: check that the repository is writable and that antivirus software is not blocking the .cache folder, then run parameter-manager.bat again.
exit /b 1
:runner_start
if defined _JAROCK_PARAMETER_MANAGER_ROOT set "ROOT=%_JAROCK_PARAMETER_MANAGER_ROOT%"
call :read_edition_marker
if /i "%JAROCK_INTERFACE%"=="tui" if not defined JAROCK_TUI_BYPASS goto :run_tui_parameter_manager
set "SETTINGS=%ROOT%\scripts\server-launch-settings.ini"
set "TEMPLATE=%ROOT%\scripts\server-launch-settings.ini.template"
set "TEMP_SETTINGS=%TEMP%\Jarock-parameter-manager-%RANDOM%-%RANDOM%.ini"
set "CONFIG_ONLY=false"
if /i "%~1"=="/configure-only" set "CONFIG_ONLY=true"
where powershell.exe >nul 2>&1
if errorlevel 1 (
echo ERROR: Windows PowerShell was not found.
echo Suggested fix: restore Windows PowerShell 5.1 and run this file again.
pause
exit /b 1
)
if not exist "%SETTINGS%" if exist "%ROOT%\server-launch-settings.ini" (
echo Migrating local launch settings to scripts\server-launch-settings.ini ...
move /y "%ROOT%\server-launch-settings.ini" "%SETTINGS%" >nul
if errorlevel 1 (
echo ERROR: Could not migrate the existing local launch settings.
echo Suggested fix: close editors or antivirus scans using the file, check permissions, and run parameter-manager.bat again.
pause
exit /b 1
)
)
if not exist "%SETTINGS%" if not exist "%TEMPLATE%" (
echo ERROR: The launch-settings template is missing.
echo Suggested fix: restore scripts\server-launch-settings.ini.template from the repository.
pause
exit /b 1
)
if exist "%SETTINGS%" (
copy /y "%SETTINGS%" "%TEMP_SETTINGS%" >nul
) else (
copy /y "%TEMPLATE%" "%TEMP_SETTINGS%" >nul
)
if errorlevel 1 (
echo ERROR: Could not create a temporary settings copy.
echo Suggested fix: check the Windows temporary folder and repository permissions, then run this file again.
pause
exit /b 1
)
:menu
cls
echo ================================================
echo Jarock server parameter manager
echo ================================================
call :read_menu_values
set "PAD= "
echo %OPT1%%PAD:~0,23%[%LOADER_TYPE%]
echo %OPT2%%PAD:~0,34%[%RAM_INITIAL% / %RAM_MAX%]
echo %OPT3%%PAD:~0,21%[%GUI_MODE%]
echo %OPT4%%PAD:~0,14%[%GC_PROFILE%]
echo %OPT5%%PAD:~0,3%[%AUTO_CONFIGURE_JAVA%]
echo %OPT6%%PAD:~0,29%[%ONLINE_MODE%]
echo %OPT7%%PAD:~0,30%[%SHOW_READY_BANNER%]
echo %OPTI%%PAD:~0,35%[%IMPORT_SHOW%]
echo Import remembered?%PAD:~0,32%[%IMPORT_REMEMBER_SHOW%]
echo %OPTE%%PAD:~0,35%[%EXPORT_SHOW%]
echo %OPTY%%PAD:~0,21%[%AUTO_UPDATE_MODE%]
echo %OPTU%%PAD:~0,23%[checks GitHub now]
echo %OPTC%%PAD:~0,23%[cleans inactive .cache files]
echo.
echo %OPT8%%PAD:~0,22%[starts the server]
echo %OPT9%%PAD:~0,34%[saves settings]
echo %OPT0%%PAD:~0,28%[discards changes]
echo %OPTX%%PAD:~0,28%[restores defaults]
echo.
if /i "%ONLINE_MODE%"=="false" echo WARNING: online-mode=false disables Mojang authentication. Keep it for private testing only.
echo.
choice /c 1234567890XYIEUC /n /m "Choose an option: "
if errorlevel 16 goto clean_cache_menu
if errorlevel 15 goto manual_update_check
if errorlevel 14 goto export_world_menu
if errorlevel 13 goto import_world_menu
if errorlevel 12 goto update_mode_menu
if errorlevel 11 goto reset
if errorlevel 10 goto cancel_exit
if errorlevel 9 goto save_exit
if errorlevel 8 goto save_start
if errorlevel 7 goto banner_toggle
if errorlevel 6 goto online_mode_menu
if errorlevel 5 goto java_toggle
if errorlevel 4 goto gc_menu
if errorlevel 3 goto mode_menu
if errorlevel 2 goto ram_menu
if errorlevel 1 goto loader_menu
goto menu
:loader_menu
cls
echo 1. Fabric (recommended first choice)
echo 2. NeoForge (fallback; official 26.2 beta installer)
echo 3. Forge (currently unavailable for official Minecraft 26.2)
echo.
choice /c 123 /n /m "Choose loader: "
if errorlevel 3 goto loader_forge
if errorlevel 2 goto loader_neoforge
if errorlevel 1 goto loader_fabric
:loader_forge
echo Forge is currently unavailable because no official Minecraft 26.2 server build is published for this bootstrap.
echo Choose Fabric or NeoForge instead.
pause
goto menu
:loader_neoforge
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%ROOT%\scripts\update-launch-setting.ps1" -SettingsPath "%TEMP_SETTINGS%" -Name LOADER_TYPE -Value neoforge
if errorlevel 1 pause
goto menu
:loader_fabric
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%ROOT%\scripts\update-launch-setting.ps1" -SettingsPath "%TEMP_SETTINGS%" -Name LOADER_TYPE -Value fabric
if errorlevel 1 pause
goto menu
:ram_menu
cls
echo Current values:
call :read_value RAM_INITIAL 4G
call :read_value RAM_MAX 4G
echo.
echo Enter values such as 4G or 6144M. Minimum is 1G.
set "NEW_INITIAL="
set /p "NEW_INITIAL=Initial RAM [%RAM_INITIAL%]: "
if not defined NEW_INITIAL set "NEW_INITIAL=%RAM_INITIAL%"
set "NEW_MAX="
set /p "NEW_MAX=Maximum RAM [%RAM_MAX%]: "
if not defined NEW_MAX set "NEW_MAX=%RAM_MAX%"
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%ROOT%\scripts\update-launch-settings.ps1" -SettingsPath "%TEMP_SETTINGS%" -InitialMemory "%NEW_INITIAL%" -MaximumMemory "%NEW_MAX%"
if errorlevel 1 (
pause
goto menu
)
goto menu
:mode_menu
cls
echo 1. Console mode (recommended): no graphical server window
echo 2. GUI mode: graphical Minecraft server window when supported
echo.
choice /c 12 /n /m "Choose mode: "
if errorlevel 2 goto mode_gui
if errorlevel 1 goto mode_nogui
:mode_gui
set "NEW_MODE=gui"
goto mode_save
:mode_nogui
set "NEW_MODE=nogui"
:mode_save
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%ROOT%\scripts\update-launch-setting.ps1" -SettingsPath "%TEMP_SETTINGS%" -Name GUI_MODE -Value "%NEW_MODE%"
if errorlevel 1 pause
goto menu
:gc_menu
cls
echo 1. Default JVM garbage collector (recommended)
echo 2. Low-pause G1GC profile (test before production)
echo.
choice /c 12 /n /m "Choose profile: "
if errorlevel 2 goto gc_low_pause
if errorlevel 1 goto gc_default
:gc_default
set "NEW_GC=default"
goto gc_save
:gc_low_pause
set "NEW_GC=low-pause"
:gc_save
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%ROOT%\scripts\update-launch-setting.ps1" -SettingsPath "%TEMP_SETTINGS%" -Name GC_PROFILE -Value "%NEW_GC%"
if errorlevel 1 pause
goto menu
:online_mode_menu
cls
echo 1. online-mode=true (recommended; authenticated Java accounts)
echo 2. online-mode=false (advanced/offline mode; unsafe for public servers without a trusted proxy)
echo.
choice /c 12 /n /m "Choose online-mode: "
if errorlevel 2 goto online_mode_false
if errorlevel 1 goto online_mode_true
:online_mode_true
set "NEW_ONLINE_MODE=true"
goto online_mode_save
:online_mode_false
set "NEW_ONLINE_MODE=false"
echo WARNING: online-mode=false disables normal Mojang account authentication.
echo Do not use it on a public server unless a trusted, correctly configured proxy handles authentication.
pause
:online_mode_save
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%ROOT%\scripts\update-launch-setting.ps1" -SettingsPath "%TEMP_SETTINGS%" -Name ONLINE_MODE -Value "%NEW_ONLINE_MODE%"
if errorlevel 1 pause
goto menu
:java_toggle
cls
call :read_value AUTO_CONFIGURE_JAVA true
if /i "%AUTO_CONFIGURE_JAVA%"=="true" (
set "NEW_JAVA=false"
echo Automatic user Java environment setup will be disabled.
) else (
set "NEW_JAVA=true"
echo Automatic user Java environment setup will be enabled.
)
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%ROOT%\scripts\update-launch-setting.ps1" -SettingsPath "%TEMP_SETTINGS%" -Name AUTO_CONFIGURE_JAVA -Value "%NEW_JAVA%"
if errorlevel 1 pause
pause
goto menu
:clean_cache_menu
cls
echo ==^> Opening the Jarock cache cleaner in a new window
echo The server and all other Java applications must be stopped first.
if not exist "%ROOT%\clean-cache.bat" (
echo ERROR: The cache cleaner entry point is missing: clean-cache.bat
echo Suggested fix: restore clean-cache.bat from the Jarock repository or release package.
pause
goto menu
)
call "%ROOT%\scripts\classic-console.bat" "Jarock cache cleanup" "%ROOT%\clean-cache.bat" /wait
if errorlevel 1 (
echo ERROR: Windows could not open the cache cleaner window.
echo Suggested fix: verify that Windows can start its command processor and run this option again.
pause
) else (
echo The Jarock cache cleaner window has finished.
pause
)
goto menu
:manual_update_check
cls
echo ==^> Opening the Jarock updater in a new window
echo The server will not be started. The updater will check GitHub and ask before installing a verified package matching this edition.
if not exist "%ROOT%\scripts\update-jarock.bat" (
echo ERROR: The updater entry point is missing: scripts\update-jarock.bat
echo Suggested fix: restore scripts\update-jarock.bat from the Jarock repository or release package.
pause
goto menu
)
call "%ROOT%\scripts\classic-console.bat" "Jarock updater" "%ROOT%\scripts\update-jarock.bat"
if errorlevel 1 (
echo ERROR: Windows could not open the updater window.
echo Suggested fix: verify that Windows can start its command processor and run this option again.
pause
) else (
echo The Jarock updater is running in a separate window.
echo This parameter manager will close now; reopen it after the updater finishes.
del /q "%TEMP_SETTINGS%" >nul 2>&1
exit /b 0
)
goto menu
:update_mode_menu
cls
echo Startup update behavior:
echo 1. Check and install updates automatically
echo Contacts GitHub and installs a verified compatible package for this edition before startup.
echo 2. Check updates only
echo Contacts GitHub and reports updates, but never installs anything.
echo 3. Do not check updates ^& do not install updates
echo Does not contact GitHub during startup.
echo.
choice /c 123 /n /m "Choose update mode: "
if errorlevel 3 goto update_mode_never
if errorlevel 2 goto update_mode_check
if errorlevel 1 goto update_mode_install
goto menu
:update_mode_install
set "NEW_UPDATE_MODE=install"
goto update_mode_save
:update_mode_check
set "NEW_UPDATE_MODE=check"
goto update_mode_save
:update_mode_never
set "NEW_UPDATE_MODE=never"
:update_mode_save
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%ROOT%\scripts\update-launch-setting.ps1" -SettingsPath "%TEMP_SETTINGS%" -Name AUTO_UPDATE_MODE -Value "%NEW_UPDATE_MODE%"
if errorlevel 1 pause
pause
goto menu
:banner_toggle
cls
call :read_value SHOW_READY_BANNER true
if /i "%SHOW_READY_BANNER%"=="true" (
set "NEW_BANNER=false"
echo The ready banner will be hidden when the server finishes loading.
) else (
set "NEW_BANNER=true"
echo The ready banner will be shown when the server finishes loading.
)
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%ROOT%\scripts\update-launch-setting.ps1" -SettingsPath "%TEMP_SETTINGS%" -Name SHOW_READY_BANNER -Value "%NEW_BANNER%"
if errorlevel 1 pause
pause
goto menu
:import_world_menu
cls
call :read_value WORLD_IMPORT_SOURCE ""
call :read_value WORLD_IMPORT_REMEMBER false
echo Current world import source: [%WORLD_IMPORT_SOURCE%]
echo Remembered for future starts: [%WORLD_IMPORT_REMEMBER%]
echo (remembered = imported at every start, with confirmation and backup)
echo.
echo Paste the full path of a world folder (containing level.dat) or a .zip world archive
echo that you want to import on every start-server.bat run (or once if not remembered).
echo Leave empty and press Enter to open a folder picker.
echo Type CLEAR and press Enter to remove the import request.
set "NEW_IMPORT="
set /p "NEW_IMPORT=Import source: "
if /i "%NEW_IMPORT%"=="CLEAR" (
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%ROOT%\scripts\update-launch-setting.ps1" -SettingsPath "%TEMP_SETTINGS%" -Name WORLD_IMPORT_SOURCE -Value ""
if errorlevel 1 pause
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%ROOT%\scripts\update-launch-setting.ps1" -SettingsPath "%TEMP_SETTINGS%" -Name WORLD_IMPORT_REMEMBER -Value false
if errorlevel 1 pause
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%ROOT%\scripts\update-launch-setting.ps1" -SettingsPath "%TEMP_SETTINGS%" -Name WORLD_IMPORT_APPLIED -Value false
if errorlevel 1 pause
echo World import request removed and its remembered-world setting was cleared.
pause
goto menu
)
if not defined NEW_IMPORT (
for /f "delims=" %%P in ('powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%ROOT%\scripts\pick-folder.ps1" -Description "Select the world folder to import"') do set "NEW_IMPORT=%%P"
)
if not defined NEW_IMPORT (
echo No folder was selected; the world import source was left unchanged.
pause
goto menu
)
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%ROOT%\scripts\update-launch-setting.ps1" -SettingsPath "%TEMP_SETTINGS%" -Name WORLD_IMPORT_SOURCE -Value "%NEW_IMPORT%"
if errorlevel 1 pause
:import_remember_prompt
set "REMEMBER_INPUT="
set "NEW_REMEMBER="
set /p "REMEMBER_INPUT=Remember this world for future starts? (Y/n): "
if not defined REMEMBER_INPUT set "NEW_REMEMBER=true"
if /i "%REMEMBER_INPUT%"=="Y" set "NEW_REMEMBER=true"
if /i "%REMEMBER_INPUT%"=="YES" set "NEW_REMEMBER=true"
if /i "%REMEMBER_INPUT%"=="N" set "NEW_REMEMBER=false"
if /i "%REMEMBER_INPUT%"=="NO" set "NEW_REMEMBER=false"
if not defined NEW_REMEMBER (
echo Please answer Y or N. Press Enter to choose the default Y.
goto import_remember_prompt
)
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%ROOT%\scripts\update-launch-setting.ps1" -SettingsPath "%TEMP_SETTINGS%" -Name WORLD_IMPORT_REMEMBER -Value "%NEW_REMEMBER%"
if errorlevel 1 pause
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%ROOT%\scripts\update-launch-setting.ps1" -SettingsPath "%TEMP_SETTINGS%" -Name WORLD_IMPORT_APPLIED -Value false
if errorlevel 1 pause
if /i "%NEW_REMEMBER%"=="true" (
echo World import source set and remembered. It will be imported at every start,
echo with a confirmation prompt and a backup of the existing world.
) else (
echo World import source set for the next start only.
)
pause
goto menu
:export_world_menu
cls
call :read_value WORLD_EXPORT_DEST ""
echo Current world export destination: [%WORLD_EXPORT_DEST%]
echo.
echo Paste the full path of a folder where the world should be copied after every
echo clean shutdown. The destination folder is overwritten (mirror copy) and must
echo be outside the server folder.
echo Leave empty and press Enter to open a folder picker.
echo Type CLEAR and press Enter to remove the export request.
set "NEW_EXPORT="
set /p "NEW_EXPORT=Export destination: "
if /i "%NEW_EXPORT%"=="CLEAR" (
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%ROOT%\scripts\update-launch-setting.ps1" -SettingsPath "%TEMP_SETTINGS%" -Name WORLD_EXPORT_DEST -Value ""
if errorlevel 1 pause
echo World export request removed.
pause
goto menu
)
if not defined NEW_EXPORT (
for /f "delims=" %%P in ('powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%ROOT%\scripts\pick-folder.ps1" -Description "Select the world export folder"') do set "NEW_EXPORT=%%P"
)
if not defined NEW_EXPORT (
echo No folder was selected; the world export destination was left unchanged.
pause
goto menu
)
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%ROOT%\scripts\update-launch-setting.ps1" -SettingsPath "%TEMP_SETTINGS%" -Name WORLD_EXPORT_DEST -Value "%NEW_EXPORT%"
if errorlevel 1 pause
echo World export destination set. The world will be copied there after every clean shutdown.
pause
goto menu
:reset
copy /y "%TEMPLATE%" "%TEMP_SETTINGS%" >nul
if errorlevel 1 (
echo ERROR: Could not restore safe defaults in the temporary settings copy.
echo Suggested fix: check the template and temporary-folder permissions, then try again.
pause
goto menu
)
echo Safe defaults restored. Choose Save and exit or Save and start to keep them.
pause
goto menu
:save_start
call :save
if errorlevel 1 exit /b 1
if /i "%CONFIG_ONLY%"=="true" (
echo Configuration-only mode: returning to the first-run bootstrap.
exit /b 0
)
pushd "%ROOT%"
if errorlevel 1 (
echo ERROR: Could not enter the repository folder before starting the server.
echo Suggested fix: check folder permissions, drive availability, and the repository path.
pause
exit /b 1
)
start-server.bat
exit /b %errorlevel%
:save_exit
call :save
if errorlevel 1 exit /b 1
if /i "%CONFIG_ONLY%"=="true" exit /b 0
pause
exit /b 0
:cancel_exit
del /q "%TEMP_SETTINGS%" >nul 2>&1
echo No changes were saved. The existing server settings were left unchanged.
if /i "%CONFIG_ONLY%"=="true" echo First-run configuration was cancelled; run start-server.bat again when ready.
exit /b 2
:save
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%ROOT%\scripts\validate-launch-settings.ps1" -SettingsPath "%TEMP_SETTINGS%"
if errorlevel 1 (
pause
exit /b 1
)
copy /y "%TEMP_SETTINGS%" "%SETTINGS%" >nul
if errorlevel 1 (
echo ERROR: Could not save the settings file.
echo Suggested fix: check repository permissions, then choose Save again.
pause
exit /b 1
)
echo Settings saved:
type "%SETTINGS%"
del /q "%TEMP_SETTINGS%" >nul 2>&1
exit /b 0
:read_edition_marker
set "JAROCK_INTERFACE=cli"
set "JAROCK_PACKAGE_TIER=lite"
set "EDITION_MARKER=%ROOT%\scripts\jarock-edition.ini"
if exist "%EDITION_MARKER%" (
for /f "tokens=1,* delims==" %%A in ('findstr /b /c:"JAROCK_INTERFACE=" /c:"JAROCK_PACKAGE_TIER=" "%EDITION_MARKER%" 2^>nul') do (
if /i "%%A"=="JAROCK_INTERFACE" set "JAROCK_INTERFACE=%%B"
if /i "%%A"=="JAROCK_PACKAGE_TIER" set "JAROCK_PACKAGE_TIER=%%B"
)
)
exit /b 0
:run_tui_parameter_manager
set "TUI_EXE=%ROOT%\jarock-tui.exe"
if not exist "%TUI_EXE%" (
echo ERROR: This TUI package is missing jarock-tui.exe.
echo Suggested fix: download a complete jarock-tui-full or jarock-tui-lite package.
pause
exit /b 1
)
set "JAROCK_ROOT=%ROOT%"
"%TUI_EXE%" --parameters %*
set "TUI_EXIT_CODE=%errorlevel%"
if not "%TUI_EXIT_CODE%"=="0" (
echo.
echo ERROR: The Jarock TUI parameter manager exited unexpectedly with code %TUI_EXIT_CODE%.
call :explain_tui_exit "%TUI_EXIT_CODE%"
echo Suggested fix: verify that this is a complete TUI release package and inspect the TUI error above.
pause
)
exit /b %TUI_EXIT_CODE%
:explain_tui_exit
set "TUI_DIAGNOSTIC_CODE=%~1"
if "%TUI_DIAGNOSTIC_CODE%"=="-1073741795" (
echo Reason: Windows reported STATUS_ILLEGAL_INSTRUCTION (0xC000001D).
echo The TUI executable tried to use a CPU instruction that this computer does not support.
echo This can happen with a non-baseline or damaged executable; download the latest TUI package built for older CPUs.
exit /b 0
)
if "%TUI_DIAGNOSTIC_CODE%"=="-1073741515" (
echo Reason: Windows could not find a required native DLL (0xC0000135).
echo The TUI package may be incomplete or its OpenTUI native backend may be missing.
echo Download the complete TUI package again and keep jarock-tui.exe with its release files.
exit /b 0
)
if "%TUI_DIAGNOSTIC_CODE%"=="-1073741819" (
echo Reason: Windows reported an access violation (0xC0000005).
echo The executable or a native OpenTUI component crashed while starting.
echo Verify the package, then inspect the TUI build and native-backend version.
exit /b 0
)
echo Reason: the TUI returned an unclassified Windows exit code; the code may indicate a package, native-backend or runtime failure.
exit /b 0
:read_menu_values
rem Initialize every displayed value before reading the temporary settings copy.
rem This keeps the menu usable even if a legacy or damaged settings file omits a key.
set "LOADER_TYPE=none"
set "RAM_INITIAL=4G"
set "RAM_MAX=4G"
set "GUI_MODE=nogui"
set "GC_PROFILE=default"
set "AUTO_CONFIGURE_JAVA=true"
set "ONLINE_MODE=true"
set "SHOW_READY_BANNER=true"
set "AUTO_UPDATE_CHECK=false"
set "HAS_AUTO_UPDATE_CHECK=false"
set "HAS_AUTO_UPDATE_MODE=false"
findstr /i /b /c:"AUTO_UPDATE_CHECK=" "%TEMP_SETTINGS%" >nul
if not errorlevel 1 set "HAS_AUTO_UPDATE_CHECK=true"
findstr /i /b /c:"AUTO_UPDATE_MODE=" "%TEMP_SETTINGS%" >nul
if not errorlevel 1 set "HAS_AUTO_UPDATE_MODE=true"
set "AUTO_UPDATE_MODE=install"
set "OPT1=1. Choose server mod loader"
set "OPT2=2. Configure RAM"
set "OPT3=3. Choose GUI or console mode"
set "OPT4=4. Choose garbage-collection profile"
set "OPT5=5. Toggle automatic user Java environment setup"
set "OPT6=6. Choose online-mode"
set "OPT7=7. Show ready banner"
set "OPTI=I. Import world"
set "OPTE=E. Export world"
set "OPT8=8. Save and start the server"
set "OPT9=9. Save and exit"
set "OPT0=0. Exit without saving"
set "OPTX=X. Reset safe defaults"
set "OPTY=Y. Choose startup update mode"
set "OPTU=U. Check for Jarock updates"
set "OPTC=C. Clean Jarock cache"
set "WORLD_IMPORT_SOURCE="
set "WORLD_IMPORT_REMEMBER=false"
set "WORLD_IMPORT_APPLIED=false"
set "WORLD_EXPORT_DEST="
set "IMPORT_SHOW=none"
set "IMPORT_REMEMBER_SHOW=false"
set "EXPORT_SHOW=none"
call :read_value LOADER_TYPE none
call :read_value RAM_INITIAL 4G
call :read_value RAM_MAX 4G
call :read_value GUI_MODE nogui
call :read_value GC_PROFILE default
call :read_value AUTO_CONFIGURE_JAVA true
call :read_value ONLINE_MODE true
call :read_value SHOW_READY_BANNER true
call :read_value AUTO_UPDATE_CHECK false
call :read_value AUTO_UPDATE_MODE install
call :read_value WORLD_IMPORT_SOURCE ""
call :read_value WORLD_IMPORT_REMEMBER false
call :read_value WORLD_IMPORT_APPLIED false
call :read_value WORLD_EXPORT_DEST ""
if defined WORLD_IMPORT_SOURCE (set "IMPORT_SHOW=%WORLD_IMPORT_SOURCE%") else (set "IMPORT_SHOW=none")
set "IMPORT_REMEMBER_SHOW=%WORLD_IMPORT_REMEMBER%"
if defined WORLD_EXPORT_DEST (set "EXPORT_SHOW=%WORLD_EXPORT_DEST%") else (set "EXPORT_SHOW=none")
if /i "%HAS_AUTO_UPDATE_MODE%"=="false" (
if /i "%HAS_AUTO_UPDATE_CHECK%"=="true" if /i "%AUTO_UPDATE_CHECK%"=="true" set "AUTO_UPDATE_MODE=install"
if /i "%HAS_AUTO_UPDATE_CHECK%"=="true" if /i "%AUTO_UPDATE_CHECK%"=="false" set "AUTO_UPDATE_MODE=never"
)
if /i not "%AUTO_UPDATE_MODE%"=="install" if /i not "%AUTO_UPDATE_MODE%"=="check" if /i not "%AUTO_UPDATE_MODE%"=="never" (
set "AUTO_UPDATE_MODE=install"
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%ROOT%\scripts\update-launch-setting.ps1" -SettingsPath "%TEMP_SETTINGS%" -Name AUTO_UPDATE_MODE -Value install >nul
)
rem An explicit AUTO_UPDATE_MODE always wins over the legacy boolean setting.
if /i "%HAS_AUTO_UPDATE_MODE%"=="false" if /i "%AUTO_UPDATE_MODE%"=="false" set "AUTO_UPDATE_MODE=never"
if /i "%AUTO_UPDATE_MODE%"=="true" set "AUTO_UPDATE_MODE=install"
exit /b 0
:read_value
rem Read one key from the temporary INI and keep the supplied default if absent.
set "%~1=%~2"
for /f "tokens=1,* delims==" %%A in ('findstr /b /c:"%~1=" "%TEMP_SETTINGS%" 2^>nul') do set "%~1=%%B"
exit /b 0