29 lines
2.3 KiB
Batchfile
29 lines
2.3 KiB
Batchfile
@echo off
|
|
setlocal
|
|
set "RAMAN_PROJECT_ROOT=%~dp0"
|
|
set "RAMAN_APP_ROOT=%~dp0src\RamanApp\bin"
|
|
set "RAMAN_OUTPUT_DIR=%~dp0src\RamanApp\bin\Debug\net9.0\win-x86"
|
|
set "RAMAN_MOCK=0"
|
|
|
|
if not "%~2"=="" goto usage
|
|
if "%~1"=="" goto run
|
|
if /I not "%~1"=="-Mock" goto usage
|
|
set "RAMAN_MOCK=1"
|
|
|
|
:run
|
|
powershell -NoProfile -ExecutionPolicy Bypass -Command "$ErrorActionPreference = 'Stop'; try { Get-CimInstance Win32_Process | Where-Object { $_.Name -eq 'RamanApp.exe' -and $_.ExecutablePath -and $_.ExecutablePath.StartsWith($env:RAMAN_APP_ROOT + '\', [StringComparison]::OrdinalIgnoreCase) } | ForEach-Object { $appProcess = Get-Process -Id $_.ProcessId -ErrorAction SilentlyContinue; if ($appProcess) { if ($appProcess.CloseMainWindow()) { $null = $appProcess.WaitForExit(5000) }; if (-not $appProcess.HasExited) { Stop-Process -Id $appProcess.Id -Force; $appProcess.WaitForExit() } } } } catch { Write-Error $_; exit 1 }"
|
|
if errorlevel 1 exit /b 1
|
|
|
|
dotnet build "%RAMAN_PROJECT_ROOT%src\RamanApp\RamanApp.csproj" -r win-x86 -p:PlatformTarget=x86 --nologo
|
|
if errorlevel 1 (
|
|
echo Build failed; application was not started.
|
|
exit /b 1
|
|
)
|
|
|
|
powershell -NoProfile -ExecutionPolicy Bypass -Command "$ErrorActionPreference = 'Stop'; try { $outputDir = $env:RAMAN_OUTPUT_DIR; $sdkSource = 'C:\Program Files\Raman\SeaSDK.dll'; $sdkTarget = Join-Path $outputDir 'SeaSDK.dll'; if (Test-Path -LiteralPath $sdkSource) { Copy-Item -LiteralPath $sdkSource -Destination $sdkTarget -Force } elseif (-not (Test-Path -LiteralPath $sdkTarget)) { throw 'SeaSDK.dll is missing from the output directory and C:\Program Files\Raman.' }; $startOptions = @{ FilePath = Join-Path $outputDir 'RamanApp.exe'; WorkingDirectory = $outputDir; PassThru = $true; RedirectStandardOutput = Join-Path $outputDir 'startup.log'; RedirectStandardError = Join-Path $outputDir 'startup-error.log' }; if ($env:RAMAN_MOCK -eq '1') { $startOptions.ArgumentList = '--simulate' }; $appProcess = Start-Process @startOptions; Start-Sleep -Seconds 3; $appProcess.Refresh(); if ($appProcess.HasExited) { throw ('Application exited during startup. Check logs in ' + $outputDir) }; Write-Host ('RamanApp started. PID={0} Mock={1}' -f $appProcess.Id, ($env:RAMAN_MOCK -eq '1')) } catch { Write-Error $_; exit 1 }"
|
|
exit /b %errorlevel%
|
|
|
|
:usage
|
|
echo Usage: restart.bat [-Mock]
|
|
exit /b 2
|