# remove-sagex-windows.ps1 — leave only the Mango wallet and the official Sage wallet. # # Run in an ordinary (not administrator) PowerShell, AFTER opening the new Mango wallet once: # powershell -ExecutionPolicy Bypass -File .\remove-sagex-windows.ps1 # # What it does, and what it never does: # * finds SageX by its uninstall entry (DisplayName "SageX"), stops only processes running # from SageX's own install folder, and runs SageX's own uninstaller silently; # * MOVES (never deletes) every SageX data folder — com.web3utxos.sagex and net.namid.sagex, # under Roaming and Local AppData — into %USERPROFILE%\SageX-backup-\, and only after # checking that Mango holds a copy of the same keys.bin. Your recovery phrase still opens # everything; this folder is a second copy you can delete yourself later; # * moves SageX Start-menu and Desktop shortcuts into the same backup folder; # * never touches the official Sage wallet (com.rigidnetwork.sage) or Mango (net.namid.mango). $ErrorActionPreference = 'Stop' $stamp = Get-Date -Format 'yyyyMMdd-HHmmss' $backup = Join-Path $env:USERPROFILE "SageX-backup-$stamp" $roam = $env:APPDATA $local = $env:LOCALAPPDATA $mangoKeys = Join-Path $roam 'net.namid.mango\keys.bin' function Say($m) { Write-Host " $m" } Write-Host "Removing SageX (backup folder: $backup)" # 1. Mango must already hold the wallet, or nothing is moved. $oldDirs = @() foreach ($root in @($roam, $local)) { foreach ($id in @('net.namid.sagex', 'com.web3utxos.sagex')) { $p = Join-Path $root $id if (Test-Path $p) { $oldDirs += $p } } } $oldKeys = $oldDirs | ForEach-Object { Join-Path $_ 'keys.bin' } | Where-Object { Test-Path $_ } if ($oldKeys.Count -gt 0) { if (-not (Test-Path $mangoKeys)) { Write-Host "Mango has no wallet yet. Open the Mango wallet once (it copies your SageX wallet), close it, then run this again." -ForegroundColor Yellow exit 1 } $mangoHash = (Get-FileHash $mangoKeys -Algorithm SHA256).Hash $match = $oldKeys | Where-Object { (Get-FileHash $_ -Algorithm SHA256).Hash -eq $mangoHash } if (-not $match) { Write-Host "Mango's keys.bin differs from every SageX keys.bin. Nothing was moved. Send this message to info@namid.net." -ForegroundColor Yellow exit 1 } Say "Mango holds the same keys.bin as $($match | Select-Object -First 1)" } # 2. Uninstall SageX with its own uninstaller. $entries = Get-ChildItem 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall', 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall' -ErrorAction SilentlyContinue | ForEach-Object { Get-ItemProperty $_.PSPath } | Where-Object { $_.DisplayName -match '^SageX' } foreach ($e in $entries) { $dir = $e.InstallLocation if ($dir) { Get-Process -ErrorAction SilentlyContinue | Where-Object { $_.Path -and $_.Path.StartsWith($dir, [StringComparison]::OrdinalIgnoreCase) } | ForEach-Object { Say "stopping $($_.Name)"; $_ | Stop-Process -Force } } $cmd = $e.QuietUninstallString; if (-not $cmd) { $cmd = $e.UninstallString } if ($cmd) { $exe = ($cmd -replace '^"([^"]+)".*$', '$1') if (Test-Path $exe) { Say "uninstalling $($e.DisplayName)"; Start-Process -FilePath $exe -ArgumentList '/S' -Wait } } } if (-not $entries) { Say "no SageX uninstall entry found (already removed?)" } # 3. Move the data folders and shortcuts aside. New-Item -ItemType Directory -Force -Path $backup | Out-Null foreach ($p in $oldDirs) { if (Test-Path $p) { $dest = Join-Path $backup ((Split-Path (Split-Path $p -Parent) -Leaf) + '-' + (Split-Path $p -Leaf)) Move-Item -LiteralPath $p -Destination $dest Say "moved $p" } } $links = @( (Join-Path $env:APPDATA 'Microsoft\Windows\Start Menu\Programs'), [Environment]::GetFolderPath('Desktop') ) | ForEach-Object { Get-ChildItem -Path $_ -Recurse -Filter 'SageX*.lnk' -ErrorAction SilentlyContinue } foreach ($l in $links) { Move-Item -LiteralPath $l.FullName -Destination $backup; Say "moved shortcut $($l.Name)" } Write-Host "Done. Mango wallet and the official Sage wallet are untouched. SageX's data is in $backup." -ForegroundColor Green