Files
bd2/bd2w.cmd
T
Flechazo fe67072b7d refactor(all): share core services and streamline launcher workflows
Centralize configuration, logging, database decryption and resource metadata.
Use task dependencies for development, SDK and release builds; move source tools and game downloads to Go with ordered client preparation.
Rename the client to BD2 Launcher, add native icons, and update packaging and SDK checks.
2026-10-14 00:04:21 +08:00

73 lines
1.8 KiB
Batchfile

@echo off
setlocal DisableDelayedExpansion
set "BD2W_ROOT=%~dp0"
set "BD2W_TOOL_DIR=%BD2W_ROOT%.build\tools"
set "BD2W_TOOL=%BD2W_TOOL_DIR%\bd2w.exe"
set "BD2W_RUN_TOOL=%BD2W_TOOL%"
if not exist "%BD2W_TOOL_DIR%" (
mkdir "%BD2W_TOOL_DIR%"
if errorlevel 1 exit /b 1
)
set "BD2W_LOCK=%BD2W_TOOL_DIR%\.bootstrap.lock"
set "BD2W_ATTEMPTS=0"
:lock
mkdir "%BD2W_LOCK%" 2>nul
if errorlevel 1 goto wait
set "BD2W_TEMP=%BD2W_TOOL_DIR%\.bd2w-%RANDOM%-%RANDOM%.exe"
call :compile_tool
if errorlevel 1 goto failed
if not exist "%BD2W_TOOL%" goto replace_tool
fc /b "%BD2W_TEMP%" "%BD2W_TOOL%" >nul 2>nul
if errorlevel 1 goto replace_tool
del /q "%BD2W_TEMP%"
if errorlevel 1 goto failed
goto unlock
:replace_tool
move /y "%BD2W_TEMP%" "%BD2W_TOOL%" >nul 2>nul
if errorlevel 1 set "BD2W_RUN_TOOL=%BD2W_TEMP%"
:unlock
rmdir "%BD2W_LOCK%"
if errorlevel 1 exit /b 1
"%BD2W_RUN_TOOL%" %*
set "BD2W_EXIT_CODE=%errorlevel%"
if exist "%BD2W_TEMP%" (
del /q "%BD2W_TEMP%"
if errorlevel 1 exit /b 1
)
exit /b %BD2W_EXIT_CODE%
:wait
set /a BD2W_ATTEMPTS+=1 >nul
if %BD2W_ATTEMPTS% geq 120 (
echo bd2w: Bootstrap lock still held at "%BD2W_LOCK%"; check the first launcher. 1>&2
exit /b 1
)
ping -n 2 127.0.0.1 >nul
goto lock
:failed
if defined BD2W_TEMP if exist "%BD2W_TEMP%" del /q "%BD2W_TEMP%"
rmdir "%BD2W_LOCK%"
echo bd2w: Build tool compilation failed. 1>&2
exit /b 1
:compile_tool
setlocal
pushd "%BD2W_ROOT%go"
if errorlevel 1 exit /b 1
set "GOCACHE=%BD2W_ROOT%go\.cache\go-build"
set "GOOS="
set "GOARCH="
for /f "delims=" %%A in ('go env GOHOSTOS') do set "GOOS=%%A"
for /f "delims=" %%A in ('go env GOHOSTARCH') do set "GOARCH=%%A"
if not defined GOOS goto compile_failed
if not defined GOARCH goto compile_failed
set "CGO_ENABLED=0"
go build -buildvcs=false -trimpath -o "%BD2W_TEMP%" ./build
if errorlevel 1 goto compile_failed
popd
exit /b 0
:compile_failed
popd
exit /b 1