All checks were successful
Publish Python Package to Gitea / publish (push) Successful in 27s
Keep DuiLib subclass wake only with GETOBJECT reentrancy guard; let ensure probe warm out-of-process. Co-authored-by: Cursor <cursoragent@cursor.com>
81 lines
3.6 KiB
PowerShell
81 lines
3.6 KiB
PowerShell
# 编译 N1/N2:x86 desktop-wake.exe + x86 wecom_wake*.dll(匹配 WXWork.exe)
|
||
$ErrorActionPreference = "Stop"
|
||
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||
$outDir = (Resolve-Path (Join-Path $here "..\native")).Path
|
||
$outExe = Join-Path $outDir "desktop-wake.exe"
|
||
$srcCs = Join-Path $here "DesktopWake\Program.cs"
|
||
$srcCpp = Join-Path $here "N2\payload\wecom_wake.cpp"
|
||
$srcDef = Join-Path $here "N2\payload\wecom_wake.def"
|
||
$objPath = Join-Path $env:TEMP "jiangchang_wecom_wake.obj"
|
||
|
||
$vcvars32 = "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\Build\vcvars32.bat"
|
||
if (-not (Test-Path $vcvars32)) {
|
||
throw "vcvars32.bat not found: $vcvars32"
|
||
}
|
||
|
||
function Test-FileWritable([string]$path) {
|
||
try {
|
||
if (-not (Test-Path $path)) { return $true }
|
||
$fs = [System.IO.File]::Open($path, 'Open', 'ReadWrite', 'None')
|
||
$fs.Close()
|
||
return $true
|
||
} catch { return $false }
|
||
}
|
||
|
||
$dllTarget = $null
|
||
$names = @("wecom_wake.dll", "wecom_wake_b.dll", "wecom_wake_c.dll", "wecom_wake_d.dll", "wecom_wake_e.dll")
|
||
$names += @("wecom_wake_{0:HHmmss}.dll" -f (Get-Date))
|
||
foreach ($name in $names) {
|
||
$cand = Join-Path $outDir $name
|
||
if (Test-FileWritable $cand) { $dllTarget = $cand; break }
|
||
}
|
||
if (-not $dllTarget) {
|
||
throw "All wecom_wake*.dll locked. Fully quit WXWork.exe (tray too), then rebuild."
|
||
}
|
||
if ((Split-Path -Leaf $dllTarget) -ne "wecom_wake.dll") {
|
||
Write-Host "WARN: primary dll locked; writing $(Split-Path -Leaf $dllTarget). Quit WXWork later to refresh wecom_wake.dll."
|
||
}
|
||
|
||
Write-Host "Building $(Split-Path -Leaf $dllTarget) (x86) ..."
|
||
|
||
# 用临时 bat + 管道进 cmd,避免 cmd /c 弄坏多行命令
|
||
$bat = Join-Path $env:TEMP "jiangchang_build_wecom_wake.bat"
|
||
@"
|
||
@echo off
|
||
call "$vcvars32" || exit /b 1
|
||
cl /nologo /LD /O2 /EHsc /DWIN32 /D_WINDOWS /D_USRDLL /utf-8 "$srcCpp" /Fe"$dllTarget" /Fo"$objPath" /link /DEF:"$srcDef" user32.lib ole32.lib oleacc.lib comctl32.lib
|
||
exit /b %ERRORLEVEL%
|
||
"@ | Set-Content -Path $bat -Encoding ASCII
|
||
|
||
$buildOut = cmd.exe /c "`"$bat`"" 2>&1
|
||
Write-Host ($buildOut | Out-String)
|
||
if (-not (Test-Path $dllTarget)) {
|
||
throw "wecom_wake dll build failed. cl output above. If locked, quit WXWork and retry."
|
||
}
|
||
Write-Host "OK $dllTarget"
|
||
|
||
$csc = Join-Path $env:WINDIR "Microsoft.NET\Framework\v4.0.30319\csc.exe"
|
||
if (-not (Test-Path $csc)) { throw "x86 csc.exe not found: $csc" }
|
||
|
||
$gac = Join-Path $env:WINDIR "Microsoft.NET\assembly\GAC_MSIL"
|
||
$uiaClient = Get-ChildItem (Join-Path $gac "UIAutomationClient") -Recurse -Filter "UIAutomationClient.dll" | Select-Object -First 1 -ExpandProperty FullName
|
||
$uiaTypes = Get-ChildItem (Join-Path $gac "UIAutomationTypes") -Recurse -Filter "UIAutomationTypes.dll" | Select-Object -First 1 -ExpandProperty FullName
|
||
$winBase = Get-ChildItem (Join-Path $gac "WindowsBase") -Recurse -Filter "WindowsBase.dll" | Select-Object -First 1 -ExpandProperty FullName
|
||
|
||
Write-Host "Building desktop-wake.exe (x86) ..."
|
||
& $csc /nologo /target:exe /platform:x86 /optimize+ `
|
||
/reference:"$uiaClient" `
|
||
/reference:"$uiaTypes" `
|
||
/reference:"$winBase" `
|
||
/out:"$outExe" `
|
||
"$srcCs"
|
||
if ($LASTEXITCODE -ne 0) { throw "csc failed: $LASTEXITCODE" }
|
||
|
||
Remove-Item $objPath -ErrorAction SilentlyContinue
|
||
Get-ChildItem $outDir -Filter "wecom_wake*.exp" | Remove-Item -ErrorAction SilentlyContinue
|
||
Get-ChildItem $outDir -Filter "wecom_wake*.lib" | Remove-Item -ErrorAction SilentlyContinue
|
||
|
||
Write-Host "OK built:"
|
||
Get-Item $outExe, $dllTarget | Format-Table Name, Length, LastWriteTime -AutoSize
|
||
Write-Host "NOTE: WXWork is 32-bit. Fully quit WXWork before a clean N2 retest if dlls were locked."
|