fix: improve wechat collector deploy visibility

This commit is contained in:
Codex
2026-06-13 14:54:34 +00:00
parent 19930f56ce
commit 5d484d1ac4
5 changed files with 100 additions and 8 deletions
+33 -2
View File
@@ -6,18 +6,44 @@ $WcfRoot = Join-Path $Root "wcf\v39.5.2"
$StateRoot = Join-Path $Root "wcf-state"
$DownloadRoot = Join-Path $Root "downloads"
$PrepareResult = Join-Path $StateRoot "prepare-result.json"
$ProgressLog = Join-Path $StateRoot "prepare-progress.log"
$Python = "C:\ProgramData\miniconda3\python.exe"
$PipIndex = "http://mirrors.aliyun.com/pypi/simple/"
$ReleaseBase = "https://github.com/lich0821/WeChatFerry/releases/download/v39.5.2"
New-Item -ItemType Directory -Force $WechatRoot,$WcfRoot,$StateRoot,$DownloadRoot | Out-Null
$StartedAt = (Get-Date).ToUniversalTime().ToString("o")
function Write-PrepareProgress {
param([string]$Message)
Add-Content -Encoding utf8 -Path $ProgressLog -Value "$((Get-Date).ToUniversalTime().ToString("o")) $Message"
}
trap {
$message = $_.Exception.Message
Write-PrepareProgress "error $message"
$failed = [ordered]@{
ok = $false
startedAt = $StartedAt
finishedAt = (Get-Date).ToUniversalTime().ToString("o")
root = $Root
stateRoot = $StateRoot
python = $Python
error = $message
valuesPrinted = $false
}
$failed | ConvertTo-Json -Depth 6 | Set-Content -Encoding utf8 $PrepareResult
exit 1
}
function Download-IfMissing {
param([string]$Url, [string]$Path)
if (Test-Path $Path) { return }
Write-PrepareProgress "download-start $Url"
$tmp = "$Path.part"
Invoke-WebRequest -Uri $Url -OutFile $tmp -UseBasicParsing
Move-Item -Force $tmp $Path
Write-PrepareProgress "download-done $Path"
}
function Find-WeChatExe {
@@ -32,7 +58,7 @@ function Find-WeChatExe {
return $null
}
$startedAt = (Get-Date).ToUniversalTime().ToString("o")
Write-PrepareProgress "prepare-start"
$installer = Join-Path $DownloadRoot "WeChatSetup-3.9.12.51.exe"
Download-IfMissing "$ReleaseBase/WeChatSetup-3.9.12.51.exe" $installer
Download-IfMissing "$ReleaseBase/sdk.dll" (Join-Path $WcfRoot "sdk.dll")
@@ -45,8 +71,10 @@ if (!(Test-Path $Python)) {
$pipOut = Join-Path $StateRoot "prepare-pip.stdout.log"
$pipErr = Join-Path $StateRoot "prepare-pip.stderr.log"
Write-PrepareProgress "pip-install-start"
& $Python -m pip install --trusted-host mirrors.aliyun.com --index-url $PipIndex "wcferry==39.5.2.0" > $pipOut 2> $pipErr
if ($LASTEXITCODE -ne 0) { throw "pip install wcferry failed" }
Write-PrepareProgress "pip-install-done"
Copy-Item -Force "$PSScriptRoot\wcf_host.py" (Join-Path $WcfRoot "wcf_host.py")
@@ -70,8 +98,10 @@ $installStderr = Join-Path $StateRoot "prepare-wechat-installer.stderr.log"
if (-not $wechatExe) {
$installAttempted = $true
$args = @("/S", "/D=$WechatRoot")
Write-PrepareProgress "wechat-install-start $installer"
$proc = Start-Process -FilePath $installer -ArgumentList $args -Wait -PassThru -RedirectStandardOutput $installStdout -RedirectStandardError $installStderr -WindowStyle Hidden
$installExitCode = $proc.ExitCode
Write-PrepareProgress "wechat-install-exit $installExitCode"
Start-Sleep -Seconds 5
$wechatExe = Find-WeChatExe
}
@@ -93,7 +123,7 @@ $pyProbe = $pyProbeJson | ConvertFrom-Json
$summary = [ordered]@{
ok = [bool]($pyProbe.ok -and $wechatExe)
startedAt = $startedAt
startedAt = $StartedAt
finishedAt = (Get-Date).ToUniversalTime().ToString("o")
root = $Root
wechatInstaller = $installer
@@ -111,5 +141,6 @@ $summary = [ordered]@{
wcferryVersion = $pyProbe.wcferryVersion
next = if ($wechatExe) { "Run start.ps1 and scan the WeChat login QR." } else { "WeChat silent install did not produce WeChat.exe; run the installer UI from the interactive Windows session, then re-run prepare.ps1." }
}
Write-PrepareProgress "prepare-done ok=$($summary.ok)"
$summary | ConvertTo-Json -Depth 6 | Set-Content -Encoding utf8 $PrepareResult
$summary | ConvertTo-Json -Depth 6
@@ -5,6 +5,9 @@ $StateRoot = Join-Path $Root "wcf-state"
$PidFile = Join-Path $StateRoot "wcf-host.pid"
$StatusFile = Join-Path $StateRoot "status.json"
$PrepareResultFile = Join-Path $StateRoot "prepare-result.json"
$PrepareStdout = Join-Path $StateRoot "prepare.stdout.log"
$PrepareStderr = Join-Path $StateRoot "prepare.stderr.log"
$PrepareProgress = Join-Path $StateRoot "prepare-progress.log"
$Stdout = Join-Path $StateRoot "wcf-host.stdout.log"
$Stderr = Join-Path $StateRoot "wcf-host.stderr.log"
function Read-JsonFile {
@@ -31,12 +34,25 @@ if (Test-Path $PidFile) {
}
$status = Read-JsonFile $StatusFile
$prepare = Read-JsonFile $PrepareResultFile
$prepareProc = Get-Process -Name powershell -ErrorAction SilentlyContinue |
Where-Object { $_.Path -like "*powershell*" -or $_.ProcessName -like "*powershell*" } |
Sort-Object StartTime -Descending |
Select-Object -First 5 Id,ProcessName,StartTime
[pscustomobject]@{
ok = $true
pid = $pidValue
running = $running
prepared = if ($prepare) { [bool]$prepare.ok } else { $false }
prepare = $prepare
prepareRuntime = [ordered]@{
candidateProcesses = $prepareProc
stdout = $PrepareStdout
stderr = $PrepareStderr
progress = $PrepareProgress
stdoutTail = Tail-Text $PrepareStdout
stderrTail = Tail-Text $PrepareStderr
progressTail = Tail-Text $PrepareProgress
}
status = $status
ports = Get-NetTCPConnection -LocalPort 10086,10087 -ErrorAction SilentlyContinue | Select-Object LocalAddress,LocalPort,State,OwningProcess
logs = [ordered]@{