Repository navigation
Expand file tree
/
Copy pathStart-RustDesk.ps1
More file actions
58 lines (53 loc) · 2.04 KB
/
Copy pathStart-RustDesk.ps1
File metadata and controls
58 lines (53 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
[CmdletBinding()]
param()
$ErrorActionPreference = "Stop"
$repo = Split-Path $PSScriptRoot -Parent
$receiptPath = Join-Path $repo "logs\last-rustdesk-start.json"
. (Join-Path $PSScriptRoot "GodBrain-HostServices.ps1")
function Assert-RustDeskGameStopped {
if (Get-Process -Name CS2 -ErrorAction SilentlyContinue) {
throw "CS2 is running; RustDesk launch is blocked."
}
}
function Write-RustDeskLaunchReceipt {
param([hashtable]$Receipt)
$null = New-Item -ItemType Directory -Path (Split-Path $receiptPath -Parent) -Force
$tmp = $receiptPath + "." + [guid]::NewGuid().ToString("N") + ".tmp"
try {
[IO.File]::WriteAllText($tmp, ($Receipt | ConvertTo-Json -Depth 5), [Text.UTF8Encoding]::new($false))
Move-Item -LiteralPath $tmp -Destination $receiptPath -Force
} finally {
if (Test-Path -LiteralPath $tmp) { Remove-Item -LiteralPath $tmp -Force }
}
}
function Invoke-RustDeskShortcutLaunch {
$receipt = @{
at = [DateTimeOffset]::UtcNow.ToString("o")
status = "running"
backend_ready = $false
message = ""
}
try {
Assert-RustDeskGameStopped
Write-RustDeskLaunchReceipt $receipt
Start-GodBrainRustDeskBackend -RegisterIfMissing
Assert-RustDeskGameStopped
if (-not (Test-GodBrainRustDeskBackend) -or (Invoke-GodBrainRustDeskStopOption) -eq "Y") {
throw "RustDesk remote-desktop backend is not ready."
}
Set-Content -LiteralPath (Join-Path $repo "logs\rustdesk-pause.txt") -Value "off"
$receipt.status = "ok"
$receipt.backend_ready = $true
$receipt.message = "RustDesk remote-desktop service ready."
$receipt.at = [DateTimeOffset]::UtcNow.ToString("o")
Write-RustDeskLaunchReceipt $receipt
return $receipt.message
} catch {
$receipt.status = "failed"
$receipt.message = $_.Exception.Message
$receipt.at = [DateTimeOffset]::UtcNow.ToString("o")
Write-RustDeskLaunchReceipt $receipt
throw
}
}
Invoke-RustDeskShortcutLaunch