提交记录修改packaging/windows/Cage.nsi+61 −1看文件
修改packaging/windows/installation-files.ps1+3 −0看文件
修改scripts/test-windows-installation-files.ps1+7 −2看文件
| @@ -117,6 +117,44 @@ FunctionEnd | ||
| 117 | 117 | Call WriteInstallDiagnostic |
| 118 | 118 | !macroend |
| 119 | 119 | |
| 120 | 新增:Function un.WriteInstallDiagnostic | |
| 121 | 新增: ${If} $DiagnosticFile != "" | |
| 122 | 新增: Push $2 | |
| 123 | 新增: Push $3 | |
| 124 | 新增: StrCpy $3 0 | |
| 125 | 新增: IfErrors 0 +2 | |
| 126 | 新增: StrCpy $3 1 | |
| 127 | 新增: ClearErrors | |
| 128 | 新增: FileOpen $2 "$DiagnosticFile" w | |
| 129 | 新增: ${IfNot} ${Errors} | |
| 130 | 新增: FileWrite $2 '{"phase":"$InstallPhase","status":"$InstallOutcome","helperExit":"$HelperExit"}$\r$\n' | |
| 131 | 新增: FileClose $2 | |
| 132 | 新增: ${EndIf} | |
| 133 | 新增: ${If} $3 == 1 | |
| 134 | 新增: SetErrors | |
| 135 | 新增: ${Else} | |
| 136 | 新增: ClearErrors | |
| 137 | 新增: ${EndIf} | |
| 138 | 新增: Pop $3 | |
| 139 | 新增: Pop $2 | |
| 140 | 新增: ${EndIf} | |
| 141 | 新增:FunctionEnd | |
| 142 | 新增: | |
| 143 | 新增:!macro UninstallPhase NAME | |
| 144 | 新增: StrCpy $InstallPhase "${NAME}" | |
| 145 | 新增: Call un.WriteInstallDiagnostic | |
| 146 | 新增:!macroend | |
| 147 | 新增: | |
| 148 | 新增:Function un.onUninstFailed | |
| 149 | 新增: StrCpy $InstallOutcome "failed" | |
| 150 | 新增: Call un.WriteInstallDiagnostic | |
| 151 | 新增:FunctionEnd | |
| 152 | 新增: | |
| 153 | 新增:Function un.onUninstSuccess | |
| 154 | 新增: StrCpy $InstallOutcome "success" | |
| 155 | 新增: !insertmacro UninstallPhase "completed" | |
| 156 | 新增:FunctionEnd | |
| 157 | 新增: | |
| 120 | 158 | Function .onInstFailed |
| 121 | 159 | StrCpy $InstallOutcome "failed" |
| 122 | 160 | Call WriteInstallDiagnostic |
| @@ -250,6 +288,7 @@ FunctionEnd | ||
| 250 | 288 | ; Exclusive write access also detects images whose VM/controller has no window. |
| 251 | 289 | System::Call 'kernel32::CreateFileW(w "$INSTDIR\${FILE}", i 0x40000000, i 0, p 0, i 3, i 0, p 0) p .r0' |
| 252 | 290 | ${If} $0 == -1 |
| 291 | 新增: StrCpy $HelperExit "application_file_in_use" | |
| 253 | 292 | SetErrorLevel 2 |
| 254 | 293 | Abort "Quit Cage and stop its environment before installing or uninstalling." |
| 255 | 294 | ${EndIf} |
| @@ -529,15 +568,27 @@ Section "Cage" Main | ||
| 529 | 568 | SectionEnd |
| 530 | 569 | |
| 531 | 570 | Function un.onInit |
| 571 | 新增: StrCpy $InstallOutcome "running" | |
| 572 | 新增: StrCpy $HelperExit "" | |
| 573 | 新增: StrCpy $DiagnosticArguments "" | |
| 574 | 新增: ${GetParameters} $0 | |
| 575 | 新增: ${GetOptions} $0 "/DIAGNOSTICS=" $DiagnosticFile | |
| 576 | 新增: ${If} $DiagnosticFile != "" | |
| 577 | 新增: StrCpy $DiagnosticArguments '-Diagnostics "$DiagnosticFile.helper.json"' | |
| 578 | 新增: ${EndIf} | |
| 579 | 新增: !insertmacro UninstallPhase "checking_installation_identity" | |
| 532 | 580 | SetShellVarContext current |
| 533 | 581 | SetRegView 64 |
| 534 | 582 | FileOpen $0 "$INSTDIR\Cage.install-id" r |
| 535 | 583 | FileRead $0 $1 |
| 536 | 584 | FileClose $0 |
| 537 | 585 | ${If} $1 != "${APP_ID}" |
| 586 | 新增: StrCpy $HelperExit "identity_mismatch" | |
| 587 | 新增: Call un.WriteInstallDiagnostic | |
| 538 | 588 | SetErrorLevel 2 |
| 539 | 589 | Abort "This is not a Cage installation folder." |
| 540 | 590 | ${EndIf} |
| 591 | 新增: !insertmacro UninstallPhase "checking_stopped_processes" | |
| 541 | 592 | !insertmacro CheckStopped "Cage.exe" |
| 542 | 593 | !insertmacro CheckStopped "resources\cage.exe" |
| 543 | 594 | !insertmacro CheckStopped "resources\mihomo.exe" |
| @@ -545,8 +596,12 @@ Function un.onInit | ||
| 545 | 596 | FunctionEnd |
| 546 | 597 | |
| 547 | 598 | Section "Uninstall" |
| 599 | 新增: !insertmacro UninstallPhase "acquiring_installation_lock" | |
| 548 | 600 | !insertmacro AcquireInstallationMutex |
| 601 | 新增: !insertmacro UninstallPhase "checking_pending_transaction" | |
| 549 | 602 | ${If} ${FileExists} "$INSTDIR.cage-installation.json" |
| 603 | 新增: StrCpy $HelperExit "pending_install_transaction" | |
| 604 | 新增: Call un.WriteInstallDiagnostic | |
| 550 | 605 | SetErrorLevel 2 |
| 551 | 606 | Abort "存在待恢复的安装事务,请先处理 $INSTDIR.cage-installation.json 中记录的目录。" |
| 552 | 607 | ${EndIf} |
| @@ -555,18 +610,23 @@ Section "Uninstall" | ||
| 555 | 610 | File /oname=installation-files.ps1 "installation-files.ps1" |
| 556 | 611 | File /oname=verified-file-deletion.cs "verified-file-deletion.cs" |
| 557 | 612 | File /oname=install-files.json "${FILE_MANIFEST}" |
| 558 | 删除: nsExec::ExecToStack '"$SYSDIR\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -ExecutionPolicy Bypass -File "$PLUGINSDIR\installation-files.ps1" -Operation uninstall -Target "$INSTDIR" -Manifest "$PLUGINSDIR\install-files.json"' | |
| 613 | 新增: !insertmacro UninstallPhase "removing_owned_files" | |
| 614 | 新增: nsExec::ExecToStack '"$SYSDIR\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -ExecutionPolicy Bypass -File "$PLUGINSDIR\installation-files.ps1" -Operation uninstall -Target "$INSTDIR" -Manifest "$PLUGINSDIR\install-files.json" $DiagnosticArguments' | |
| 559 | 615 | Pop $0 |
| 560 | 616 | Pop $1 |
| 617 | 新增: StrCpy $HelperExit $0 | |
| 618 | 新增: Call un.WriteInstallDiagnostic | |
| 561 | 619 | DetailPrint "$1" |
| 562 | 620 | ${If} $0 != 0 |
| 563 | 621 | SetErrorLevel 2 |
| 564 | 622 | Abort "部分程序文件正在使用或无法读取,卸载未完成。个人文件已保留,请关闭占用程序后重试。" |
| 565 | 623 | ${EndIf} |
| 624 | 新增: !insertmacro UninstallPhase "removing_shortcuts_and_registration" | |
| 566 | 625 | Delete "$DESKTOP\Cage.lnk" |
| 567 | 626 | Delete "$SMPROGRAMS\Cage\Cage.lnk" |
| 568 | 627 | Delete "$SMPROGRAMS\Cage\Uninstall Cage.lnk" |
| 569 | 628 | RMDir "$SMPROGRAMS\Cage" |
| 570 | 629 | DeleteRegKey HKCU "${UNINSTALL_KEY}" |
| 630 | 新增: !insertmacro UninstallPhase "removing_install_directory" | |
| 571 | 631 | RMDir "$INSTDIR" |
| 572 | 632 | SectionEnd |
| @@ -316,11 +316,13 @@ if ($Operation -eq 'prepare') { | ||
| 316 | 316 | Complete-Transfer |
| 317 | 317 | } else { |
| 318 | 318 | # The payload list comes from this uninstaller's embedded build manifest. |
| 319 | 新增: $diagnosticStep = 'reading_uninstall_manifest' | |
| 319 | 320 | $owned = Read-FileManifest $Manifest |
| 320 | 321 | if (!$owned.Count) { throw '卸载文件清单无效,原文件已保留。' } |
| 321 | 322 | $installed = Read-FileManifest (Join-Path $Target $manifestName) |
| 322 | 323 | if ($installed.ContainsKey('Uninstall.exe')) { $owned['Uninstall.exe'] = $installed['Uninstall.exe'] } |
| 323 | 324 | $actual = @(Read-Tree $Target @($owned.Keys) | Where-Object { !($_.Attributes -band [IO.FileAttributes]::ReparsePoint) } | ForEach-Object { Relative-Path $Target $_.FullName }) |
| 325 | 新增: $diagnosticStep = 'deleting_verified_program_files' | |
| 324 | 326 | foreach ($relative in $owned.Keys) { |
| 325 | 327 | if ($relative -ne $identityName -and $relative -in $actual) { Remove-MatchingFile $Target $relative $owned[$relative] } |
| 326 | 328 | } |
| @@ -334,6 +336,7 @@ if ($Operation -eq 'prepare') { | ||
| 334 | 336 | $directory = Split-Path $relative -Parent |
| 335 | 337 | while ($directory) { $directories += $directory.Replace('\', '/'); $directory = Split-Path $directory -Parent } |
| 336 | 338 | } |
| 339 | 新增: $diagnosticStep = 'removing_program_directories' | |
| 337 | 340 | Remove-EmptyDirectories $Target $directories |
| 338 | 341 | # A retained identity lets a later installation reuse this data-bearing folder. |
| 339 | 342 | $remaining = @(Get-ChildItem -LiteralPath $Target -Force | Where-Object Name -ne $identityName) |
| @@ -101,7 +101,7 @@ function Test-InstallerTransaction { | ||
| 101 | 101 | try { |
| 102 | 102 | if (!$process.WaitForExit(30000)) { $process.Kill($true); $process.WaitForExit(); throw 'The owned NSIS fixture exceeded 30 seconds.' } |
| 103 | 103 | if ($process.ExitCode -ne 0) { |
| 104 | 删除: foreach ($path in @($report, "$report.helper.json")) { | |
| 104 | 新增: foreach ($path in @($report, "$report.helper.json", "$report.uninstall.json", "$report.uninstall.json.helper.json")) { | |
| 105 | 105 | if ((Test-Path -LiteralPath $path) -and (Get-Item -LiteralPath $path).Length -le 8192) { Write-Output ('Quick NSIS diagnostic: ' + (Get-Content -LiteralPath $path -Raw)) } |
| 106 | 106 | } |
| 107 | 107 | throw "The NSIS fixture returned $($process.ExitCode)." |
| @@ -117,7 +117,7 @@ function Test-InstallerTransaction { | ||
| 117 | 117 | } finally { |
| 118 | 118 | if (Test-Path $key) { |
| 119 | 119 | if ((Get-ItemProperty $key).InstallLocation -ne $target) { throw 'NSIS fixture registration changed owner; retained for inspection.' } |
| 120 | 删除: Run-Fixture (Join-Path $target 'Uninstall.exe') @('/S') | |
| 120 | 新增: Run-Fixture (Join-Path $target 'Uninstall.exe') @('/S',('/DIAGNOSTICS="' + $report + '.uninstall.json"')) | |
| 121 | 121 | # NSIS can return from its bootstrapper while the TEMP worker is |
| 122 | 122 | # still running. Its helper removes the target before NSIS clears |
| 123 | 123 | # registration and shortcuts, so target disappearance is not done. |
| @@ -126,6 +126,11 @@ function Test-InstallerTransaction { | ||
| 126 | 126 | } |
| 127 | 127 | } |
| 128 | 128 | $remaining = @{target = (Test-Path -LiteralPath $target); registration = (Test-Path $key); desktopShortcut = (Test-Path -LiteralPath $desktop); startMenu = (Test-Path -LiteralPath $menu)} |
| 129 | 新增: if ($remaining.Values -contains $true) { | |
| 130 | 新增: foreach ($path in @("$report.uninstall.json", "$report.uninstall.json.helper.json")) { | |
| 131 | 新增: if ((Test-Path -LiteralPath $path) -and (Get-Item -LiteralPath $path).Length -le 8192) { Write-Output ('Quick NSIS uninstall diagnostic: ' + (Get-Content -LiteralPath $path -Raw)) } | |
| 132 | 新增: } | |
| 133 | 新增: } | |
| 129 | 134 | Check (!($remaining.Values -contains $true)) ('NSIS fixture did not finish uninstalling owned artifacts: ' + ($remaining | ConvertTo-Json -Compress)) |
| 130 | 135 | Write-Output 'PASS: production NSIS silently installed/uninstalled its text-only fixture through PowerShell 5.1 transactions; no application or VM was started.' |
| 131 | 136 | } |

