Constant UPDATER_SCRIPT
Source pub const UPDATER_SCRIPT: &'static str = "param (\r\n [Parameter(Mandatory = $true)]\r\n [string]$binary,\r\n\r\n [Parameter(Mandatory = $false)]\r\n [string[]]$arguments = @(),\r\n\r\n [Parameter(Mandatory = $true)]\r\n [int]$processPid,\r\n\r\n [Parameter(Mandatory = $false)]\r\n [switch]$restart = $false\r\n)\r\n\r\nWrite-Host \"Waiting for process with PID $processPid to exit...\"\r\ntry {\r\n $process = Get-Process -Id $processPid -ErrorAction Stop\r\n $process.WaitForExit()\r\n Write-Host \"Process with PID $processPid has exited.\"\r\n}\r\ncatch {\r\n Write-Host \"Process with PID $processPid is not running or already exited.\"\r\n}\r\n\r\n$binaryDirectory = [System.IO.Path]::GetDirectoryName($binary)\r\n$obsNewDir = Join-Path -Path $binaryDirectory -ChildPath \"obs_new\"\r\n\r\nif (Test-Path $obsNewDir -PathType Container) {\r\n Write-Host \"Found obs_new directory, copying all contents to binary directory\"\r\n\r\n try {\r\n $files = Get-ChildItem -Path $obsNewDir -Recurse\r\n foreach ($file in $files) {\r\n $relativePath = $file.FullName.Substring($obsNewDir.Length + 1)\r\n $destination = Join-Path -Path $binaryDirectory -ChildPath $relativePath\r\n\r\n # Create directory structure if needed\r\n if ($file.PSIsContainer) {\r\n if (-Not (Test-Path $destination -PathType Container)) {\r\n New-Item -ItemType Directory -Path $destination -Force | Out-Null\r\n }\r\n continue\r\n }\r\n\r\n # Remove target file if it exists\r\n if (Test-Path $destination) {\r\n try {\r\n Remove-Item -Path $destination -Force\r\n }\r\n catch {\r\n Write-Host \"Failed to remove existing file ${destination}: $_\"\r\n exit 1\r\n }\r\n }\r\n\r\n # Copy the file\r\n try {\r\n Copy-Item -Path $file.FullName -Destination $destination -Force\r\n }\r\n catch {\r\n Write-Host \"Failed to copy $($file.FullName) to ${destination}: $_\"\r\n exit 1\r\n }\r\n }\r\n Write-Host \"Successfully copied all contents from obs_new to binary directory\"\r\n\r\n # Optionally remove the obs_new directory after successful copy\r\n try {\r\n Remove-Item -Path $obsNewDir -Recurse -Force\r\n Write-Host \"Removed obs_new directory after copying contents\"\r\n }\r\n catch {\r\n Write-Host \"Warning: Could not remove obs_new directory: $_\"\r\n }\r\n }\r\n catch {\r\n Write-Host \"Error copying files from obs_new directory: $_\"\r\n exit 1\r\n }\r\n}\r\nelse {\r\n Write-Host \"Warning: obs_new directory not found in $binaryDirectory\"\r\n}\r\n\r\nif (-not $restart) {\r\n Write-Host \"No binary specified, exiting.\"\r\n exit 0\r\n}\r\n\r\n# Restart the binary with given arguments\r\nWrite-Host \"Restarting $binary with arguments: $($arguments -join \' \')\"\r\ntry {\r\n if ($arguments.Count -eq 0) {\r\n Start-Process -FilePath $binary\r\n }\r\n else {\r\n Start-Process -FilePath $binary -ArgumentList $arguments\r\n }\r\n Write-Host \"Successfully restarted $binary\"\r\n}\r\ncatch {\r\n Write-Host \"Failed to restart ${binary}: $_\"\r\n exit 1\r\n}";