提交记录修改.github/workflows/windows-build.yml+13 −0看文件
修改packaging/windows/Cage.nsi+82 −7看文件
修改packaging/windows/installation-files.ps1+28 −0看文件
修改scripts/test-windows-install.ps1+15 −2看文件
修改scripts/test-windows-installation-files.ps1+20 −0看文件
| @@ -88,6 +88,19 @@ jobs: | ||
| 88 | 88 | if-no-files-found: error |
| 89 | 89 | overwrite: true |
| 90 | 90 | retention-days: 14 |
| 91 | 新增: - name: Preserve failed unsigned candidates for installation debugging | |
| 92 | 新增: if: ${{ always() && job.status != 'success' }} | |
| 93 | 新增: uses: actions/upload-artifact@v4 | |
| 94 | 新增: with: | |
| 95 | 新增: name: ${{ inputs.artifact_name }}-${{ matrix.os }}-failed-candidate | |
| 96 | 新增: path: | | |
| 97 | 新增: _output/windows-amd64/app/** | |
| 98 | 新增: _output/releases/*/windows/Cage-*-windows-amd64-setup-unsigned.exe | |
| 99 | 新增: _output/releases/*/windows/SHA256SUMS | |
| 100 | 新增: if-no-files-found: ignore | |
| 101 | 新增: compression-level: 0 | |
| 102 | 新增: overwrite: true | |
| 103 | 新增: retention-days: 14 | |
| 91 | 104 | - name: Preserve public test reports |
| 92 | 105 | if: always() |
| 93 | 106 | uses: actions/upload-artifact@v4 |
| @@ -83,6 +83,49 @@ Var DesktopShortcutControl | ||
| 83 | 83 | Var StartMenuShortcutsControl |
| 84 | 84 | Var InstallationMutex |
| 85 | 85 | Var TransactionRecord |
| 86 | 新增:Var DiagnosticFile | |
| 87 | 新增:Var InstallPhase | |
| 88 | 新增:Var InstallOutcome | |
| 89 | 新增:Var HelperExit | |
| 90 | 新增:Var DiagnosticArguments | |
| 91 | 新增: | |
| 92 | 新增:Function WriteInstallDiagnostic | |
| 93 | 新增: ${If} $DiagnosticFile != "" | |
| 94 | 新增: Push $2 | |
| 95 | 新增: Push $3 | |
| 96 | 新增: StrCpy $3 0 | |
| 97 | 新增: IfErrors 0 +2 | |
| 98 | 新增: StrCpy $3 1 | |
| 99 | 新增: ClearErrors | |
| 100 | 新增: FileOpen $2 "$DiagnosticFile" w | |
| 101 | 新增: ${IfNot} ${Errors} | |
| 102 | 新增: FileWrite $2 '{"phase":"$InstallPhase","status":"$InstallOutcome","helperExit":"$HelperExit"}$\r$\n' | |
| 103 | 新增: FileClose $2 | |
| 104 | 新增: ${EndIf} | |
| 105 | 新增: ${If} $3 == 1 | |
| 106 | 新增: SetErrors | |
| 107 | 新增: ${Else} | |
| 108 | 新增: ClearErrors | |
| 109 | 新增: ${EndIf} | |
| 110 | 新增: Pop $3 | |
| 111 | 新增: Pop $2 | |
| 112 | 新增: ${EndIf} | |
| 113 | 新增:FunctionEnd | |
| 114 | 新增: | |
| 115 | 新增:!macro InstallPhase NAME | |
| 116 | 新增: StrCpy $InstallPhase "${NAME}" | |
| 117 | 新增: Call WriteInstallDiagnostic | |
| 118 | 新增:!macroend | |
| 119 | 新增: | |
| 120 | 新增:Function .onInstFailed | |
| 121 | 新增: StrCpy $InstallOutcome "failed" | |
| 122 | 新增: Call WriteInstallDiagnostic | |
| 123 | 新增:FunctionEnd | |
| 124 | 新增: | |
| 125 | 新增:Function .onInstSuccess | |
| 126 | 新增: StrCpy $InstallOutcome "success" | |
| 127 | 新增: Call WriteInstallDiagnostic | |
| 128 | 新增:FunctionEnd | |
| 86 | 129 | |
| 87 | 130 | !macro AcquireInstallationMutex |
| 88 | 131 | ; NSIS and UpdateInstaller both reject an existing named object and keep |
| @@ -215,6 +258,15 @@ FunctionEnd | ||
| 215 | 258 | !macroend |
| 216 | 259 | |
| 217 | 260 | Function .onInit |
| 261 | 新增: StrCpy $InstallOutcome "running" | |
| 262 | 新增: StrCpy $HelperExit "" | |
| 263 | 新增: ${GetParameters} $0 | |
| 264 | 新增: ${GetOptions} $0 "/DIAGNOSTICS=" $DiagnosticFile | |
| 265 | 新增: StrCpy $DiagnosticArguments "" | |
| 266 | 新增: ${If} $DiagnosticFile != "" | |
| 267 | 新增: StrCpy $DiagnosticArguments '-Diagnostics "$DiagnosticFile.helper.json"' | |
| 268 | 新增: ${EndIf} | |
| 269 | 新增: !insertmacro InstallPhase "initializing" | |
| 218 | 270 | SetShellVarContext current |
| 219 | 271 | SetRegView 64 |
| 220 | 272 | ${IfNot} ${IsNativeAMD64} |
| @@ -275,7 +327,7 @@ Function CheckDestination | ||
| 275 | 327 | FunctionEnd |
| 276 | 328 | |
| 277 | 329 | Function RestorePreservedFiles |
| 278 | 删除: nsExec::ExecToStack '"$SYSDIR\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -ExecutionPolicy Bypass -File "$PLUGINSDIR\installation-files.ps1" -Operation restore -Target "$BackupDir" -Source "$StageDir" -Receipt "$TransactionRecord"' | |
| 330 | 新增: nsExec::ExecToStack '"$SYSDIR\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -ExecutionPolicy Bypass -File "$PLUGINSDIR\installation-files.ps1" -Operation restore -Target "$BackupDir" -Source "$StageDir" -Receipt "$TransactionRecord" $DiagnosticArguments' | |
| 279 | 331 | Pop $0 |
| 280 | 332 | Pop $1 |
| 281 | 333 | ${If} $0 != 0 |
| @@ -289,7 +341,7 @@ Function RestorePreservedFiles | ||
| 289 | 341 | SetErrorLevel 2 |
| 290 | 342 | Abort "原安装目录未能恢复。文件保留在 $BackupDir,新程序保留在 $StageDir。" |
| 291 | 343 | ${EndIf} |
| 292 | 删除: nsExec::ExecToStack '"$SYSDIR\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -ExecutionPolicy Bypass -File "$PLUGINSDIR\installation-files.ps1" -Operation complete -Target "$INSTDIR" -Receipt "$TransactionRecord"' | |
| 344 | 新增: nsExec::ExecToStack '"$SYSDIR\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -ExecutionPolicy Bypass -File "$PLUGINSDIR\installation-files.ps1" -Operation complete -Target "$INSTDIR" -Receipt "$TransactionRecord" $DiagnosticArguments' | |
| 293 | 345 | Pop $0 |
| 294 | 346 | Pop $1 |
| 295 | 347 | ${If} $0 != 0 |
| @@ -299,18 +351,21 @@ Function RestorePreservedFiles | ||
| 299 | 351 | FunctionEnd |
| 300 | 352 | |
| 301 | 353 | Section "Cage" Main |
| 354 | 新增: !insertmacro InstallPhase "acquiring_installation_lock" | |
| 302 | 355 | !insertmacro AcquireInstallationMutex |
| 303 | 356 | StrCpy $TransactionRecord "$INSTDIR.cage-installation.json" |
| 304 | 357 | ${If} ${FileExists} "$TransactionRecord" |
| 305 | 358 | SetErrorLevel 2 |
| 306 | 359 | Abort "存在未处理的安装事务记录:$TransactionRecord。请先按记录恢复保留的目录,再重试。" |
| 307 | 360 | ${EndIf} |
| 361 | 新增: !insertmacro InstallPhase "checking_destination" | |
| 308 | 362 | Call CheckDestination |
| 309 | 363 | ${GetParent} "$INSTDIR" $0 |
| 310 | 364 | CreateDirectory "$0" |
| 311 | 365 | GetTempFileName $StageDir "$0" |
| 312 | 366 | Delete "$StageDir" |
| 313 | 367 | CreateDirectory "$StageDir" |
| 368 | 新增: !insertmacro InstallPhase "unpacking_application" | |
| 314 | 369 | SetOutPath "$StageDir" |
| 315 | 370 | ClearErrors |
| 316 | 371 | !ifdef NSIS_WIN32_MAKENSIS |
| @@ -327,6 +382,7 @@ Section "Cage" Main | ||
| 327 | 382 | ${EndIf} |
| 328 | 383 | |
| 329 | 384 | ; Install the bundled offline runtime only when WebView2 is absent. |
| 385 | 新增: !insertmacro InstallPhase "detecting_webview_runtime" | |
| 330 | 386 | SetRegView 32 |
| 331 | 387 | ReadRegStr $0 HKLM "SOFTWARE\Microsoft\EdgeUpdate\Clients\${WEBVIEW2_APP_ID}" "pv" |
| 332 | 388 | ReadRegStr $1 HKCU "Software\Microsoft\EdgeUpdate\Clients\${WEBVIEW2_APP_ID}" "pv" |
| @@ -336,7 +392,10 @@ Section "Cage" Main | ||
| 336 | 392 | ${If} $1 == "" |
| 337 | 393 | ${OrIf} $1 == "0.0.0.0" |
| 338 | 394 | DetailPrint "Installing the bundled Microsoft WebView2 runtime..." |
| 395 | 新增: !insertmacro InstallPhase "installing_webview_runtime" | |
| 339 | 396 | ExecWait '"$StageDir\resources\runtime\MicrosoftEdgeWebView2RuntimeInstallerX64.exe" /silent /install' $0 |
| 397 | 新增: StrCpy $HelperExit $0 | |
| 398 | 新增: Call WriteInstallDiagnostic | |
| 340 | 399 | ${If} $0 != 0 |
| 341 | 400 | SetOutPath "$TEMP" |
| 342 | 401 | RMDir /r "$StageDir" |
| @@ -358,9 +417,12 @@ Section "Cage" Main | ||
| 358 | 417 | File /oname=installation-files.ps1 "installation-files.ps1" |
| 359 | 418 | File /oname=verified-file-deletion.cs "verified-file-deletion.cs" |
| 360 | 419 | DetailPrint "正在检查并保留已有项目和修改文件…" |
| 361 | 删除: nsExec::ExecToStack '"$SYSDIR\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -ExecutionPolicy Bypass -File "$PLUGINSDIR\installation-files.ps1" -Operation prepare -Target "$StageDir" -Source "$INSTDIR" -Backup "$BackupDir" -Receipt "$TransactionRecord"' | |
| 420 | 新增: !insertmacro InstallPhase "preparing_file_transaction" | |
| 421 | 新增: nsExec::ExecToStack '"$SYSDIR\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -ExecutionPolicy Bypass -File "$PLUGINSDIR\installation-files.ps1" -Operation prepare -Target "$StageDir" -Source "$INSTDIR" -Backup "$BackupDir" -Receipt "$TransactionRecord" $DiagnosticArguments' | |
| 362 | 422 | Pop $0 |
| 363 | 423 | Pop $1 |
| 424 | 新增: StrCpy $HelperExit $0 | |
| 425 | 新增: Call WriteInstallDiagnostic | |
| 364 | 426 | DetailPrint "$1" |
| 365 | 427 | ${If} $0 != 0 |
| 366 | 428 | SetOutPath "$TEMP" |
| @@ -370,10 +432,11 @@ Section "Cage" Main | ||
| 370 | 432 | ${EndIf} |
| 371 | 433 | SetOutPath "$TEMP" |
| 372 | 434 | ${If} $ExistingInstall == "1" |
| 435 | 新增: !insertmacro InstallPhase "moving_previous_application" | |
| 373 | 436 | ClearErrors |
| 374 | 437 | Rename "$INSTDIR" "$BackupDir" |
| 375 | 438 | ${If} ${Errors} |
| 376 | 删除: nsExec::ExecToStack '"$SYSDIR\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -ExecutionPolicy Bypass -File "$PLUGINSDIR\installation-files.ps1" -Operation complete -Target "$INSTDIR" -Receipt "$TransactionRecord"' | |
| 439 | 新增: nsExec::ExecToStack '"$SYSDIR\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -ExecutionPolicy Bypass -File "$PLUGINSDIR\installation-files.ps1" -Operation complete -Target "$INSTDIR" -Receipt "$TransactionRecord" $DiagnosticArguments' | |
| 377 | 440 | Pop $0 |
| 378 | 441 | Pop $1 |
| 379 | 442 | RMDir /r "$StageDir" |
| @@ -381,9 +444,12 @@ Section "Cage" Main | ||
| 381 | 444 | Abort "Could not move the installed application. Quit Cage and retry." |
| 382 | 445 | ${EndIf} |
| 383 | 446 | DetailPrint "正在迁入个人文件并保留原有链接…" |
| 384 | 删除: nsExec::ExecToStack '"$SYSDIR\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -ExecutionPolicy Bypass -File "$PLUGINSDIR\installation-files.ps1" -Operation move -Target "$StageDir" -Source "$BackupDir" -Receipt "$TransactionRecord"' | |
| 447 | 新增: !insertmacro InstallPhase "moving_personal_files" | |
| 448 | 新增: nsExec::ExecToStack '"$SYSDIR\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -ExecutionPolicy Bypass -File "$PLUGINSDIR\installation-files.ps1" -Operation move -Target "$StageDir" -Source "$BackupDir" -Receipt "$TransactionRecord" $DiagnosticArguments' | |
| 385 | 449 | Pop $0 |
| 386 | 450 | Pop $1 |
| 451 | 新增: StrCpy $HelperExit $0 | |
| 452 | 新增: Call WriteInstallDiagnostic | |
| 387 | 453 | DetailPrint "$1" |
| 388 | 454 | ${If} $0 != 0 |
| 389 | 455 | Call RestorePreservedFiles |
| @@ -394,6 +460,7 @@ Section "Cage" Main | ||
| 394 | 460 | ${Else} |
| 395 | 461 | RMDir "$INSTDIR" |
| 396 | 462 | ${EndIf} |
| 463 | 新增: !insertmacro InstallPhase "publishing_application" | |
| 397 | 464 | ClearErrors |
| 398 | 465 | Rename "$StageDir" "$INSTDIR" |
| 399 | 466 | ${If} ${Errors} |
| @@ -405,10 +472,13 @@ Section "Cage" Main | ||
| 405 | 472 | Abort "Could not install Cage. The previous installation has been restored." |
| 406 | 473 | ${EndIf} |
| 407 | 474 | ${If} $BackupDir != "" |
| 475 | 新增: !insertmacro InstallPhase "cleaning_previous_application" | |
| 408 | 476 | DetailPrint "正在清理已核对的旧程序文件…" |
| 409 | 删除: nsExec::ExecToStack '"$SYSDIR\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -ExecutionPolicy Bypass -File "$PLUGINSDIR\installation-files.ps1" -Operation cleanup -Target "$INSTDIR" -Source "$BackupDir" -Receipt "$TransactionRecord"' | |
| 477 | 新增: nsExec::ExecToStack '"$SYSDIR\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -ExecutionPolicy Bypass -File "$PLUGINSDIR\installation-files.ps1" -Operation cleanup -Target "$INSTDIR" -Source "$BackupDir" -Receipt "$TransactionRecord" $DiagnosticArguments' | |
| 410 | 478 | Pop $0 |
| 411 | 479 | Pop $1 |
| 480 | 新增: StrCpy $HelperExit $0 | |
| 481 | 新增: Call WriteInstallDiagnostic | |
| 412 | 482 | DetailPrint "$1" |
| 413 | 483 | ${If} $0 != 0 |
| 414 | 484 | DetailPrint "旧目录中仍有需要保留的文件:$BackupDir" |
| @@ -416,14 +486,18 @@ Section "Cage" Main | ||
| 416 | 486 | Abort "安装仍有待恢复的文件。请保留 $TransactionRecord 及其中记录的目录,再处理恢复。" |
| 417 | 487 | ${EndIf} |
| 418 | 488 | ${Else} |
| 419 | 删除: nsExec::ExecToStack '"$SYSDIR\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -ExecutionPolicy Bypass -File "$PLUGINSDIR\installation-files.ps1" -Operation complete -Target "$INSTDIR" -Receipt "$TransactionRecord"' | |
| 489 | 新增: !insertmacro InstallPhase "completing_file_transaction" | |
| 490 | 新增: nsExec::ExecToStack '"$SYSDIR\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -ExecutionPolicy Bypass -File "$PLUGINSDIR\installation-files.ps1" -Operation complete -Target "$INSTDIR" -Receipt "$TransactionRecord" $DiagnosticArguments' | |
| 420 | 491 | Pop $0 |
| 421 | 492 | Pop $1 |
| 493 | 新增: StrCpy $HelperExit $0 | |
| 494 | 新增: Call WriteInstallDiagnostic | |
| 422 | 495 | ${If} $0 != 0 |
| 423 | 496 | SetErrorLevel 2 |
| 424 | 497 | Abort "安装回执未能完成,记录保留在 $TransactionRecord。" |
| 425 | 498 | ${EndIf} |
| 426 | 499 | ${EndIf} |
| 500 | 新增: !insertmacro InstallPhase "registering_installation" | |
| 427 | 501 | WriteRegStr HKCU "${UNINSTALL_KEY}" "DisplayName" "Cage" |
| 428 | 502 | WriteRegStr HKCU "${UNINSTALL_KEY}" "DisplayVersion" "${VERSION}" |
| 429 | 503 | WriteRegStr HKCU "${UNINSTALL_KEY}" "Publisher" "Cage contributors" |
| @@ -450,6 +524,7 @@ Section "Cage" Main | ||
| 450 | 524 | ${EndIf} |
| 451 | 525 | WriteRegDWORD HKCU "${UNINSTALL_KEY}" "DesktopShortcut" $DesktopShortcut |
| 452 | 526 | WriteRegDWORD HKCU "${UNINSTALL_KEY}" "StartMenuShortcuts" $StartMenuShortcuts |
| 527 | 新增: !insertmacro InstallPhase "completed" | |
| 453 | 528 | SetErrorLevel 0 |
| 454 | 529 | SectionEnd |
| 455 | 530 | |
| @@ -7,9 +7,29 @@ param( | ||
| 7 | 7 | [string]$Receipt, |
| 8 | 8 | [string]$Manifest, |
| 9 | 9 | [string]$Backup, |
| 10 | 新增: [string]$Diagnostics, | |
| 10 | 11 | [switch]$LegacyTarget |
| 11 | 12 | ) |
| 12 | 13 | $ErrorActionPreference = 'Stop' |
| 14 | 新增:$diagnosticStep = 'initializing' | |
| 15 | 新增:trap { | |
| 16 | 新增: $failure = $_ | |
| 17 | 新增: if ($Diagnostics) { | |
| 18 | 新增: try { | |
| 19 | 新增: if (!(Test-Path -LiteralPath $Diagnostics)) { | |
| 20 | 新增: $chain = @() | |
| 21 | 新增: $exception = $failure.Exception | |
| 22 | 新增: for ($index = 0; $exception -and $index -lt 4; $index++) { | |
| 23 | 新增: $chain += @{type = $exception.GetType().FullName; hresult = $exception.HResult} | |
| 24 | 新增: $exception = $exception.InnerException | |
| 25 | 新增: } | |
| 26 | 新增: @{operation = $Operation; phase = $diagnosticStep; pointerSize = [IntPtr]::Size; errors = $chain} | ConvertTo-Json -Depth 4 | | |
| 27 | 新增: Set-Content -LiteralPath $Diagnostics -Encoding UTF8 | |
| 28 | 新增: } | |
| 29 | 新增: } catch { } | |
| 30 | 新增: } | |
| 31 | 新增: throw $failure | |
| 32 | 新增:} | |
| 13 | 33 | $manifestName = 'Cage.install-files.json' |
| 14 | 34 | $identityName = 'Cage.install-id' |
| 15 | 35 | |
| @@ -144,6 +164,7 @@ foreach ($rootPath in @($Target, $Source)) { | ||
| 144 | 164 | } |
| 145 | 165 | } |
| 146 | 166 | if ($Operation -eq 'prepare') { |
| 167 | 新增: $diagnosticStep = 'reading_new_manifest' | |
| 147 | 168 | if (Test-Path -LiteralPath $Receipt) { throw ('仍有未完成的安装事务,请保留并检查回执:' + $Receipt) } |
| 148 | 169 | $current = Read-FileManifest (Join-Path $Target $manifestName) |
| 149 | 170 | $legacySnapshot = !$current.Count -and $LegacyTarget |
| @@ -152,6 +173,7 @@ if ($Operation -eq 'prepare') { | ||
| 152 | 173 | try { $current[$identityName] = Stream-Hash $identity } finally { $identity.Dispose() } |
| 153 | 174 | } |
| 154 | 175 | if (!$current.Count) { throw '新程序缺少有效文件清单,安装已停止。' } |
| 176 | 新增: $diagnosticStep = 'reading_new_uninstaller' | |
| 155 | 177 | $uninstaller = Open-ReadLocked (Join-Path $Target 'Uninstall.exe') |
| 156 | 178 | try { $current['Uninstall.exe'] = Stream-Hash $uninstaller } finally { $uninstaller.Dispose() } |
| 157 | 179 | $transfers = [Collections.Generic.List[object]]::new() |
| @@ -160,6 +182,7 @@ if ($Operation -eq 'prepare') { | ||
| 160 | 182 | $recovery = 'Cage-preserved-files/' + [guid]::NewGuid().ToString('N') |
| 161 | 183 | $programDirectories = Directory-Paths @($current.Keys) |
| 162 | 184 | if ($Source -and (Test-Path -LiteralPath $Source -PathType Container)) { |
| 185 | 新增: $diagnosticStep = 'scanning_previous_installation' | |
| 163 | 186 | $Source = [IO.Path]::GetFullPath($Source).TrimEnd([IO.Path]::DirectorySeparatorChar) |
| 164 | 187 | $previous = Read-FileManifest (Join-Path $Source $manifestName) |
| 165 | 188 | $previousDirectories = Directory-Paths @($previous.Keys) |
| @@ -220,8 +243,10 @@ if ($Operation -eq 'prepare') { | ||
| 220 | 243 | } |
| 221 | 244 | } |
| 222 | 245 | } |
| 246 | 新增: $diagnosticStep = 'writing_new_manifest' | |
| 223 | 247 | $files = @($current.Keys | Sort-Object | ForEach-Object { @{ path = $_; sha256 = $current[$_] } }) |
| 224 | 248 | @{ version = 1; files = $files } | ConvertTo-Json -Depth 4 | Set-Content -LiteralPath (Join-Path $Target $manifestName) -Encoding UTF8 |
| 249 | 新增: $diagnosticStep = 'writing_transaction_receipt' | |
| 225 | 250 | $record = @{kind = 'cage-installation'; version = 1; installPath = $Source; stagePath = $Target; backupPath = $Backup; files = @($transfers); directories = $directories; moves = @($moves)} |
| 226 | 251 | $encoding = [Text.UTF8Encoding]::new($true) |
| 227 | 252 | [byte[]]$bytes = $encoding.GetPreamble() + $encoding.GetBytes(($record | ConvertTo-Json -Depth 6)) |
| @@ -232,6 +257,7 @@ if ($Operation -eq 'prepare') { | ||
| 232 | 257 | [IO.File]::Move($temporary, $Receipt) |
| 233 | 258 | } finally { if (Test-Path -LiteralPath $temporary) { [IO.File]::Delete($temporary) } } |
| 234 | 259 | } elseif ($Operation -in @('move','restore')) { |
| 260 | 新增: $diagnosticStep = 'moving_preserved_files' | |
| 235 | 261 | $transfer = Get-Content -LiteralPath $Receipt -Raw -Encoding UTF8 | ConvertFrom-Json |
| 236 | 262 | $moves = @($transfer.moves) |
| 237 | 263 | if ($Operation -eq 'restore') { [Array]::Reverse($moves) } |
| @@ -263,6 +289,7 @@ if ($Operation -eq 'prepare') { | ||
| 263 | 289 | Write-Output ('同名修改或旧程序文件已保留在 ' + (Join-Path $Target 'Cage-preserved-files')) |
| 264 | 290 | } |
| 265 | 291 | } elseif ($Operation -eq 'cleanup') { |
| 292 | 新增: $diagnosticStep = 'verifying_previous_file_ownership' | |
| 266 | 293 | $transfer = Get-Content -LiteralPath $Receipt -Raw -Encoding UTF8 | ConvertFrom-Json |
| 267 | 294 | $actual = @(Read-Tree $Source @($transfer.files.path) | Where-Object { !($_.Attributes -band [IO.FileAttributes]::ReparsePoint) } | ForEach-Object { Relative-Path $Source $_.FullName }) |
| 268 | 295 | foreach ($entry in $transfer.files) { |
| @@ -284,6 +311,7 @@ if ($Operation -eq 'prepare') { | ||
| 284 | 311 | } else { [IO.Directory]::Delete($Source) } |
| 285 | 312 | Complete-Transfer |
| 286 | 313 | } elseif ($Operation -eq 'complete') { |
| 314 | 新增: $diagnosticStep = 'completing_transaction_receipt' | |
| 287 | 315 | Complete-Transfer |
| 288 | 316 | } else { |
| 289 | 317 | # The payload list comes from this uninstaller's embedded build manifest. |
| @@ -16,13 +16,26 @@ function Assert-PersonalData { | ||
| 16 | 16 | } |
| 17 | 17 | function Run-Installer { |
| 18 | 18 | param([switch]$Update, [int]$ExpectedExitCode = 0, [string[]]$ShortcutOptions = @()) |
| 19 | 删除: $arguments = @('/S') | |
| 19 | 新增: $installationReport = Join-Path (Get-WindowsWorkbenchTestBase) ('cage-smoke-installation-' + [guid]::NewGuid().ToString('N') + '.json') | |
| 20 | 新增: $arguments = @('/S', "/DIAGNOSTICS=$installationReport") | |
| 20 | 21 | if ($Update) { $arguments += '/UPDATE' } |
| 21 | 22 | $arguments += $ShortcutOptions |
| 22 | 23 | $arguments += "/D=$target" |
| 23 | 24 | $process = Start-Process -FilePath $Installer -ArgumentList $arguments -PassThru |
| 24 | 25 | if (-not $process.WaitForExit(300000)) { throw 'Installer exceeded five minutes.' } |
| 25 | 删除: if ($process.ExitCode -ne $ExpectedExitCode) { throw "Installer returned $($process.ExitCode), expected $ExpectedExitCode" } | |
| 26 | 新增: if ($process.ExitCode -ne $ExpectedExitCode) { | |
| 27 | 新增: foreach ($path in @($installationReport, "$installationReport.helper.json")) { | |
| 28 | 新增: try { | |
| 29 | 新增: if ((Test-Path -LiteralPath $path -PathType Leaf) -and (Get-Item -LiteralPath $path).Length -le 8192) { | |
| 30 | 新增: $value = Get-Content -LiteralPath $path -Raw | ConvertFrom-Json -AsHashtable | |
| 31 | 新增: $safe = @{phase = $value['phase']; status = $value['status']; helperExit = $value['helperExit']; operation = $value['operation']; pointerSize = $value['pointerSize']} | |
| 32 | 新增: if ($value['errors']) { $safe.errors = @($value['errors'] | Select-Object -First 4 | ForEach-Object { @{type = $_['type']; hresult = $_['hresult']} }) } | |
| 33 | 新增: Write-Host ('Cage installer diagnostic: ' + ($safe | ConvertTo-Json -Depth 4 -Compress)) | |
| 34 | 新增: } | |
| 35 | 新增: } catch { Write-Warning 'The bounded installer diagnostic could not be read.' } | |
| 36 | 新增: } | |
| 37 | 新增: throw "Installer returned $($process.ExitCode), expected $ExpectedExitCode" | |
| 38 | 新增: } | |
| 26 | 39 | } |
| 27 | 40 | $desktopShortcut = Join-Path ([Environment]::GetFolderPath('DesktopDirectory')) 'Cage.lnk' |
| 28 | 41 | $startMenuDirectory = Join-Path ([Environment]::GetFolderPath('Programs')) 'Cage' |
| @@ -63,6 +63,26 @@ function Commit([string]$Old, [string]$Stage, [string]$Receipt) { | ||
| 63 | 63 | return $backup |
| 64 | 64 | } |
| 65 | 65 | try { |
| 66 | 新增: # A new install has no backup path or existing ownership manifest. | |
| 67 | 新增: $scenario = Join-Path $root 'first-install' | |
| 68 | 新增: $old = Join-Path $scenario 'empty-destination'; $stage = Join-Path $scenario 'staged'; $receipt = Join-Path $scenario 'receipt.json' | |
| 69 | 新增: [IO.Directory]::CreateDirectory($old) | Out-Null | |
| 70 | 新增: App $stage 'fresh' | |
| 71 | 新增: Invoke-Helper @('-Operation','prepare','-Source',$old,'-Target',$stage,'-Receipt',$receipt) | |
| 72 | 新增: $transfer = Get-Content -LiteralPath $receipt -Raw | ConvertFrom-Json | |
| 73 | 新增: Check (!$transfer.backupPath -and @($transfer.moves).Count -eq 0) 'First install invented a backup or personal file transfer.' | |
| 74 | 新增: [IO.Directory]::Delete($old); [IO.Directory]::Move($stage, $old) | |
| 75 | 新增: Invoke-Helper @('-Operation','complete','-Target',$old,'-Receipt',$receipt) | |
| 76 | 新增: Check (!(Test-Path -LiteralPath $receipt)) 'First install did not finish its transaction.' | |
| 77 | 新增: | |
| 78 | 新增: $diagnostic = Join-Path $scenario 'diagnostic.json' | |
| 79 | 新增: Write-File (Join-Path $old 'Cage.install-files.json') 'invalid-private-manifest' | |
| 80 | 新增: Invoke-Helper @('-Operation','prepare','-Target',$old,'-Receipt',$receipt,'-Diagnostics',$diagnostic) 1 | |
| 81 | 新增: $text = Get-Content -LiteralPath $diagnostic -Raw | |
| 82 | 新增: $failure = $text | ConvertFrom-Json | |
| 83 | 新增: Check ($failure.operation -eq 'prepare' -and $failure.phase -eq 'reading_new_manifest' -and @($failure.errors).Count -gt 0) 'Helper omitted its safe failure classification.' | |
| 84 | 新增: Check (!$text.Contains($root) -and !$text.Contains('invalid-private-manifest') -and !$text.Contains('message')) 'Helper diagnostic contains file paths or private error text.' | |
| 85 | 新增: | |
| 66 | 86 | foreach ($manifestState in @('current','missing','invalid')) { |
| 67 | 87 | $scenario = Join-Path $root $manifestState |
| 68 | 88 | $old = Join-Path $scenario 'installed'; $stage = Join-Path $scenario 'staged'; $receipt = Join-Path $scenario 'receipt.json' |

