added logging to the project
This commit is contained in:
@@ -15,6 +15,17 @@ $ErrorActionPreference = 'Stop'
|
||||
$configPath = Join-Path $PSScriptRoot '..\config.psd1'
|
||||
$config = Import-PowerShellDataFile -Path $configPath
|
||||
|
||||
# --- Start transcript logging ---
|
||||
try {
|
||||
$logDir = Join-Path $config.LogPath $env:USERNAME
|
||||
New-Item -ItemType Directory -Path $logDir -Force -ErrorAction SilentlyContinue | Out-Null
|
||||
Start-Transcript -Path (Join-Path $logDir 'OBSReplayBuffer.log') -Append -ErrorAction Stop
|
||||
} catch {
|
||||
# Log path unavailable — continue without transcript
|
||||
}
|
||||
|
||||
Write-Host "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') [INFO] Starting OBS Replay Buffer for user: $env:USERNAME"
|
||||
|
||||
# --- Verify required project files are accessible ---
|
||||
$requiredPaths = @(
|
||||
(Join-Path $PSScriptRoot '..\obs-config\global.ini')
|
||||
@@ -24,12 +35,17 @@ $requiredPaths = @(
|
||||
)
|
||||
foreach ($path in $requiredPaths) {
|
||||
if (-not (Test-Path -Path $path)) {
|
||||
Write-Host "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') [ERROR] Required path not accessible: $path"
|
||||
Stop-Transcript -ErrorAction SilentlyContinue
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
Write-Host "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') [INFO] All required paths verified."
|
||||
|
||||
# --- Skip if OBS is already running (handles reconnect scenarios) ---
|
||||
if (Get-Process -Name 'obs64' -ErrorAction SilentlyContinue) {
|
||||
Write-Host "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') [INFO] OBS already running — exiting."
|
||||
Stop-Transcript -ErrorAction SilentlyContinue
|
||||
exit 0
|
||||
}
|
||||
|
||||
@@ -37,6 +53,9 @@ if (Get-Process -Name 'obs64' -ErrorAction SilentlyContinue) {
|
||||
$userCapturePath = Join-Path $config.UNCPath $env:USERNAME
|
||||
if (-not (Test-Path -Path $userCapturePath)) {
|
||||
New-Item -ItemType Directory -Path $userCapturePath -Force | Out-Null
|
||||
Write-Host "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') [INFO] Created capture folder: $userCapturePath"
|
||||
} else {
|
||||
Write-Host "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') [INFO] Capture folder exists: $userCapturePath"
|
||||
}
|
||||
|
||||
# --- Detect primary monitor resolution ---
|
||||
@@ -44,6 +63,7 @@ Add-Type -AssemblyName System.Windows.Forms
|
||||
$screen = [System.Windows.Forms.Screen]::PrimaryScreen
|
||||
$width = $screen.Bounds.Width
|
||||
$height = $screen.Bounds.Height
|
||||
Write-Host "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') [INFO] Detected resolution: ${width}x${height}"
|
||||
|
||||
# --- Deploy global OBS config and WebSocket plugin config ---
|
||||
$obsConfigRoot = "$env:APPDATA\obs-studio"
|
||||
@@ -55,6 +75,8 @@ $wsConfigDir = "$obsConfigRoot\plugin_config\obs-websocket"
|
||||
New-Item -ItemType Directory -Path $wsConfigDir -Force | Out-Null
|
||||
Copy-Item -Path "$sourceConfig\plugin_config\obs-websocket\config.json" -Destination "$wsConfigDir\config.json" -Force
|
||||
|
||||
Write-Host "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') [INFO] OBS config files deployed to: $obsConfigRoot"
|
||||
|
||||
# --- Write OBS profile (basic.ini) ---
|
||||
$profileDir = "$env:APPDATA\obs-studio\basic\profiles\$($config.ProfileName)"
|
||||
New-Item -ItemType Directory -Path $profileDir -Force | Out-Null
|
||||
@@ -88,6 +110,8 @@ ColorSpace=709
|
||||
ColorRange=Partial
|
||||
"@ | Set-Content -Path "$profileDir\basic.ini" -Encoding UTF8
|
||||
|
||||
Write-Host "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') [INFO] OBS profile written: $profileDir\basic.ini"
|
||||
|
||||
# --- Launch OBS hidden ---
|
||||
$obsArgs = @(
|
||||
'--minimize-to-tray'
|
||||
@@ -100,6 +124,7 @@ $obsArgs = @(
|
||||
)
|
||||
|
||||
Start-Process -FilePath $config.OBSExecutable -ArgumentList $obsArgs -WindowStyle Hidden
|
||||
Write-Host "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') [INFO] OBS launched: $($config.OBSExecutable)"
|
||||
|
||||
# --- Launch tray icon as a separate background process ---
|
||||
$trayScript = Join-Path $PSScriptRoot 'Show-ReplayTray.ps1'
|
||||
@@ -109,3 +134,6 @@ Start-Process -FilePath 'powershell.exe' -ArgumentList @(
|
||||
'-WindowStyle', 'Hidden'
|
||||
'-File', $trayScript
|
||||
) -WindowStyle Hidden
|
||||
Write-Host "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') [INFO] Tray icon launched."
|
||||
|
||||
Stop-Transcript -ErrorAction SilentlyContinue
|
||||
|
||||
Reference in New Issue
Block a user