@echo off
call "%~dp0env.bat"
echo ============================================
echo LoggerDemo - Shared Memory Mode (.NET calling Java)
echo ============================================
echo.

echo Step 1: Building Java and generating proxies...
cd .\ProxyGen
call Build.bat
if errorlevel 1 (
  echo Java build failed!
  pause
  exit /b 1
)

echo.
echo Step 2: Building C# project...
cd ..\LoggerDemo
dotnet build -c Release
if errorlevel 1 (
  echo C# build failed!
  pause
  exit /b 1
)

echo.
echo Step 3: Generating shared-memory config with JVM paths from env.bat...
powershell -Command "[xml]$x = Get-Content 'App.config'; $n = $x.configuration.jnbridge.dotNetToJavaConfig; $n.SetAttribute('jvm64','%JVM_DLL_64%'); $n.SetAttribute('jvm32','%JVM_DLL_32%'); $x.Save('%cd%\bin\Release\net48\LoggerDemo.exe.config')"
if errorlevel 1 (
  echo Config generation failed!
  pause
  exit /b 1
)

echo.
echo ============================================
echo Build complete! Running demo...
echo ============================================
echo.

cd bin\Release\net48
LoggerDemo.exe

pause
