added logging to the project
This commit is contained in:
@@ -14,11 +14,22 @@ param(
|
||||
|
||||
$ErrorActionPreference = 'SilentlyContinue'
|
||||
|
||||
$config = Import-PowerShellDataFile -Path (Join-Path $PSScriptRoot '..\config.psd1')
|
||||
if ($Port -eq 0) {
|
||||
$config = Import-PowerShellDataFile -Path (Join-Path $PSScriptRoot '..\config.psd1')
|
||||
$Port = $config.WebSocketPort
|
||||
$Port = $config.WebSocketPort
|
||||
}
|
||||
|
||||
# --- 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-Save.log') -Append -ErrorAction Stop
|
||||
} catch {
|
||||
# Log path unavailable — continue without transcript
|
||||
}
|
||||
|
||||
Write-Host "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') [INFO] Invoke-ReplaySave started. Target: ws://localhost:$Port"
|
||||
|
||||
$ws = $null
|
||||
$cts = $null
|
||||
|
||||
@@ -28,34 +39,43 @@ try {
|
||||
$uri = [System.Uri]"ws://localhost:$Port"
|
||||
|
||||
$ws.ConnectAsync($uri, $cts.Token).Wait()
|
||||
Write-Host "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') [INFO] WebSocket connected."
|
||||
|
||||
$buffer = New-Object byte[] 8192
|
||||
|
||||
# Receive Hello (opcode 0)
|
||||
$null = $ws.ReceiveAsync($buffer, $cts.Token).Result
|
||||
Write-Host "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') [INFO] Received Hello (op 0)."
|
||||
|
||||
# Send Identify (opcode 1) — no authentication
|
||||
$identify = [System.Text.Encoding]::UTF8.GetBytes('{"op":1,"d":{"rpcVersion":1}}')
|
||||
$ws.SendAsync($identify, [System.Net.WebSockets.WebSocketMessageType]::Text, $true, $cts.Token).Wait()
|
||||
Write-Host "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') [INFO] Sent Identify (op 1)."
|
||||
|
||||
# Receive Identified (opcode 2)
|
||||
$null = $ws.ReceiveAsync($buffer, $cts.Token).Result
|
||||
Write-Host "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') [INFO] Received Identified (op 2)."
|
||||
|
||||
# Send SaveReplayBuffer request (opcode 6)
|
||||
$request = [System.Text.Encoding]::UTF8.GetBytes('{"op":6,"d":{"requestType":"SaveReplayBuffer","requestId":"itrecord-1"}}')
|
||||
$ws.SendAsync($request, [System.Net.WebSockets.WebSocketMessageType]::Text, $true, $cts.Token).Wait()
|
||||
Write-Host "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') [INFO] Sent SaveReplayBuffer request (op 6)."
|
||||
|
||||
# Receive RequestResponse (opcode 7)
|
||||
$null = $ws.ReceiveAsync($buffer, $cts.Token).Result
|
||||
Write-Host "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') [INFO] Received response (op 7)."
|
||||
|
||||
$ws.CloseAsync([System.Net.WebSockets.WebSocketCloseStatus]::NormalClosure, 'Done', $cts.Token).Wait()
|
||||
Write-Host "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') [INFO] WebSocket closed. Save completed successfully."
|
||||
|
||||
return $true
|
||||
}
|
||||
catch {
|
||||
Write-Host "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') [ERROR] Save failed: $_"
|
||||
return $false
|
||||
}
|
||||
finally {
|
||||
if ($ws) { $ws.Dispose() }
|
||||
if ($cts) { $cts.Dispose() }
|
||||
Stop-Transcript -ErrorAction SilentlyContinue
|
||||
}
|
||||
|
||||
@@ -12,6 +12,18 @@
|
||||
Add-Type -AssemblyName System.Windows.Forms
|
||||
Add-Type -AssemblyName System.Drawing
|
||||
|
||||
# --- Start transcript logging ---
|
||||
try {
|
||||
$config = Import-PowerShellDataFile -Path (Join-Path $PSScriptRoot '..\config.psd1')
|
||||
$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-Tray.log') -Append -ErrorAction Stop
|
||||
} catch {
|
||||
# Log path unavailable — continue without transcript
|
||||
}
|
||||
|
||||
Write-Host "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') [INFO] Tray icon started."
|
||||
|
||||
function Show-Notification {
|
||||
param([string]$Title, [string]$Body)
|
||||
try {
|
||||
@@ -46,12 +58,16 @@ $saveItem.Add_Click({
|
||||
$saveItem.Enabled = $false
|
||||
$saveItem.Text = 'Saving...'
|
||||
|
||||
Write-Host "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') [INFO] Save replay requested."
|
||||
|
||||
$result = & powershell.exe -ExecutionPolicy Bypass -NonInteractive -File $saveScript
|
||||
|
||||
if ($result -eq $true) {
|
||||
Write-Host "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') [INFO] Replay saved successfully."
|
||||
Show-Notification -Title 'IT Screen Recorder' -Body 'Replay saved.'
|
||||
}
|
||||
else {
|
||||
Write-Host "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') [ERROR] Replay save failed."
|
||||
Show-Notification -Title 'IT Screen Recorder' -Body 'Could not save replay. Please contact the helpdesk.'
|
||||
}
|
||||
|
||||
@@ -60,6 +76,7 @@ $saveItem.Add_Click({
|
||||
})
|
||||
|
||||
$exitItem.Add_Click({
|
||||
Write-Host "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') [INFO] Tray icon exited by user."
|
||||
$tray.Visible = $false
|
||||
[System.Windows.Forms.Application]::Exit()
|
||||
})
|
||||
@@ -74,3 +91,4 @@ $tray.ContextMenuStrip = $menu
|
||||
[System.Windows.Forms.Application]::Run()
|
||||
|
||||
$tray.Dispose()
|
||||
Stop-Transcript -ErrorAction SilentlyContinue
|
||||
|
||||
@@ -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