Treasury & Bank Transfer Management System — سامانه مدیریت خزانه‌داری و حواله‌های بانکی

1 param([Parameter(Mandatory=$true)][string]$InstalledFolder)
2 $ErrorActionPreference='Stop'
3 $evidence=Join-Path $env:RUNNER_TEMP 'treasuryflow-vm-evidence'
4 New-Item -ItemType Directory -Path $evidence -Force | Out-Null
5 $report=[ordered]@{
6 schema='treasuryflow-windows-nsis-uninstall-v1'
7 mode='ACTUAL_INSTALLED_NSIS_UNINSTALL'
8 installerRootFound=$false
9 uninstallerFound=$false
10 uninstallerExitCode=$null
11 remainingDesktopProcessesStopped=0
12 removalWaitSeconds=0
13 executableRemoved=$false
14 outcome='NOT_RUN'
15 }
16 try{
17 if(!(Test-Path -LiteralPath $InstalledFolder)){throw 'INSTALLED_FOLDER_MISSING'}
18 $report.installerRootFound=$true
19 $apps=@(Get-ChildItem -LiteralPath $InstalledFolder -Recurse -File -Filter 'TreasuryFlow.exe' -ErrorAction SilentlyContinue)
20 if($apps.Count -ne 1){throw 'INSTALLED_EXE_NOT_UNIQUE'}
21 $uninstallers=@(Get-ChildItem -LiteralPath $InstalledFolder -Recurse -File -ErrorAction SilentlyContinue |
22 Where-Object {$_.Name -match '^uninstall.*\.exe$'})
23 if($uninstallers.Count -ne 1){throw 'NSIS_UNINSTALLER_NOT_UNIQUE'}
24 $report.uninstallerFound=$true
25 # Dispose of the synthetic installed app first; Windows holds running EXEs open.
26 $running=@(Get-Process -Name 'TreasuryFlow' -ErrorAction SilentlyContinue)
27 foreach($instance in $running){
28 try{Stop-Process -Id $instance.Id -Force -ErrorAction Stop;$report.remainingDesktopProcessesStopped++}catch{}
29 }
30 Start-Sleep -Milliseconds 800
31 $process=Start-Process -FilePath $uninstallers[0].FullName -ArgumentList '/S' -PassThru
32 if(!$process.WaitForExit(90000)){
33 try{$process.Kill()}catch{}
34 throw 'NSIS_UNINSTALL_TIMEOUT'
35 }
36 $report.uninstallerExitCode=$process.ExitCode
37 if($process.ExitCode -ne 0){throw 'NSIS_UNINSTALL_NONZERO_EXIT'}
38 $startWait=[System.Diagnostics.Stopwatch]::StartNew()
39 while($startWait.Elapsed.TotalSeconds -lt 90){
40 if(!(Test-Path -LiteralPath $apps[0].FullName)){$report.executableRemoved=$true;break}
41 Start-Sleep -Seconds 1
42 }
43 $report.removalWaitSeconds=[math]::Round($startWait.Elapsed.TotalSeconds,1)
44 if(!$report.executableRemoved){throw 'NSIS_UNINSTALL_LEFT_INSTALLED_EXE_AFTER_90_SECONDS'}
45 $report.outcome='NSIS_REAL_UNINSTALL_PASS'
46 'Uninstalled real disposable TreasuryFlow NSIS installation with /S and verified EXE removal.' >> $env:GITHUB_STEP_SUMMARY
47 }catch{
48 $report.outcome='FAILED'
49 $report.failureCode=$_.Exception.Message
50 throw
51 }finally{
52 $report | ConvertTo-Json -Depth 4 | Set-Content (Join-Path $evidence 'uninstall-runtime.json') -Encoding UTF8
53 }