Files
SbLauncher/build.cmd
T
2026-09-26 21:51:08 +03:00

135 lines
5.4 KiB
Batchfile

@echo off
rem ---------------------------------------------------------------------
rem Build SbLauncher with the C# compiler that ships inside Windows.
rem No .NET SDK, no Visual Studio, no internet required.
rem
rem build.cmd normal build (exe asks for admin)
rem build.cmd deploy <target> build, then copy exe/Ui/templates
rem build.cmd selftest [root] build without manifest + run --selftest
rem build.cmd staged build SbLauncher.updated.exe while app is running
rem build.cmd icon <source.png> regenerate app.ico and logo.png
rem
rem NOTE: this file is intentionally ASCII-only and CRLF. cmd.exe reads
rem .bat in the OEM codepage and breaks "goto" on LF line endings.
rem ---------------------------------------------------------------------
setlocal
cd /d "%~dp0"
set "FW=%WINDIR%\Microsoft.NET\Framework64\v4.0.30319"
set "CSC=%FW%\csc.exe"
if not exist "%CSC%" (
echo [!] csc.exe not found at %CSC%
echo .NET Framework 4.x is required - it ships with Windows.
exit /b 1
)
set "WPF=/reference:"%FW%\WPF\PresentationFramework.dll" /reference:"%FW%\WPF\PresentationCore.dll" /reference:"%FW%\WPF\WindowsBase.dll" /reference:"%FW%\System.Xaml.dll" /reference:"%FW%\System.dll" /reference:"%FW%\System.Core.dll""
set "WINFORMS=/reference:"%FW%\System.Windows.Forms.dll" /reference:"%FW%\System.Drawing.dll""
rem System.Web.Extensions = JavaScriptSerializer, reads profiles/local json
set "JSON=/reference:"%FW%\System.Web.Extensions.dll""
set "REFS=%WPF% %WINFORMS% %JSON%"
rem Ui.xaml and the three config templates are embedded, so a bare exe
rem works on its own; a file of the same name next to the exe wins.
set "RES=/resource:Ui.xaml,Ui.xaml /resource:app.ico,app.ico /resource:logo.png,logo.png /resource:templates\wg.json,wg.json /resource:templates\direct.json,direct.json /resource:templates\wgonly.json,wgonly.json"
set "DODEPLOY="
set "APP_OUT=SbLauncher.exe"
if /i "%~1"=="icon" goto icon
if /i "%~1"=="selftest" goto selftest
if /i "%~1"=="stress" goto stress
if /i "%~1"=="profiletest" goto profiletest
if /i "%~1"=="importtest" goto importtest
if /i "%~1"=="staged" set "APP_OUT=SbLauncher.updated.exe"
if /i "%~1"=="deploy" set "DODEPLOY=1"
if not exist app.ico (
echo [!] app.ico missing - run: build.cmd icon "path\to\logo.png"
exit /b 1
)
echo [*] Building %APP_OUT% ...
"%CSC%" /nologo /target:winexe /platform:x64 /optimize+ /out:%APP_OUT% /win32manifest:app.manifest /win32icon:app.ico %RES% %REFS% Version.cs SbLauncher.cs ViewModels.cs App.cs Import.cs
if errorlevel 1 goto failed
echo [+] Done: %CD%\%APP_OUT%
if defined DODEPLOY goto docopy
echo.
echo Run %APP_OUT% here, or deploy to an explicit test target.
goto end
:docopy
set "DST=%~2"
if "%DST%"=="" (
echo [!] Specify a test target: build.cmd deploy "path"
exit /b 1
)
if not exist "%DST%" (
echo [!] target not found: %DST%
exit /b 1
)
echo [*] Deploying to %DST%
copy /y SbLauncher.exe "%DST%\" >nul
copy /y Ui.xaml "%DST%\" >nul
copy /y profiles.json "%DST%\" >nul
if not exist "%DST%\templates" mkdir "%DST%\templates"
copy /y templates\*.json "%DST%\templates\" >nul
rem local.json is deliberately NOT overwritten: it holds this machine's
rem private key and adapter name.
if not exist "%DST%\local.json" (
echo [i] %DST%\local.json missing - seeding it from local.example.json
copy /y local.example.json "%DST%\local.json" >nul
)
echo [+] Deployed. bin\sb.exe and doc\doc.srs must already be there.
goto end
:icon
if "%~2"=="" ( echo [!] usage: build.cmd icon "path\to\logo.png" & exit /b 1 )
echo [*] Building MakeIcon.exe ...
"%CSC%" /nologo /target:exe /platform:x64 /out:tools\MakeIcon.exe %WPF% tools\MakeIcon.cs
if errorlevel 1 goto failed
"%CD%\tools\MakeIcon.exe" "%~2" app.ico logo.png
if errorlevel 1 goto failed
goto end
:selftest
echo [*] Test build without manifest (so it does not trigger UAC) ...
"%CSC%" /nologo /target:exe /platform:x64 /out:SbLauncher.selftest.exe %RES% %REFS% Version.cs SbLauncher.cs ViewModels.cs App.cs Import.cs
if errorlevel 1 goto failed
echo [+] Built. Running --selftest
echo.
if "%~2"=="" ("%CD%\SbLauncher.selftest.exe" --selftest) else ("%CD%\SbLauncher.selftest.exe" --selftest --root "%~2")
goto end
:stress
"%CSC%" /nologo /target:exe /platform:x64 /out:SbLauncher.selftest.exe %RES% %REFS% Version.cs SbLauncher.cs ViewModels.cs App.cs Import.cs
if errorlevel 1 goto failed
"%CSC%" /nologo /target:exe /platform:x64 /out:UiStress.exe /reference:SbLauncher.selftest.exe %REFS% tests\UiStress.cs
if errorlevel 1 goto failed
"%CD%\UiStress.exe"
if errorlevel 1 goto failed
goto end
:profiletest
"%CSC%" /nologo /target:exe /platform:x64 /out:SbLauncher.selftest.exe %RES% %REFS% Version.cs SbLauncher.cs ViewModels.cs App.cs Import.cs
if errorlevel 1 goto failed
"%CSC%" /nologo /target:exe /platform:x64 /out:ProfileSmoke.exe /reference:SbLauncher.selftest.exe %REFS% tests\ProfileSmoke.cs
if errorlevel 1 goto failed
"%CD%\ProfileSmoke.exe"
if errorlevel 1 goto failed
goto end
:importtest
"%CSC%" /nologo /target:exe /platform:x64 /out:SbLauncher.selftest.exe %RES% %REFS% Version.cs SbLauncher.cs ViewModels.cs App.cs Import.cs
if errorlevel 1 goto failed
"%CSC%" /nologo /target:exe /platform:x64 /out:ImportSmoke.exe /reference:SbLauncher.selftest.exe %REFS% tests\ImportSmoke.cs
if errorlevel 1 goto failed
"%CD%\ImportSmoke.exe"
if errorlevel 1 goto failed
goto end
:failed
echo [!] Build failed
exit /b 1
:end
endlocal