mirror of
https://github.com/hansjone/netx.git
synced 2026-10-09 00:50:46 +08:00
Choose bundled or external PostgreSQL in the Setup wizard with connection validation; optional NETX_CREDENTIAL_SECRET_KEY; single desktop shortcut; faster uninstall and tray startup for offline Windows packages. Co-authored-by: Cursor <cursoragent@cursor.com>
53 lines
1.5 KiB
PowerShell
53 lines
1.5 KiB
PowerShell
param(
|
|
[string]$DataRoot = ""
|
|
)
|
|
|
|
# Post-uninstall optional data wipe with retries (handles briefly locked runtime logs).
|
|
|
|
$ErrorActionPreference = "Continue"
|
|
if (-not $DataRoot) {
|
|
$DataRoot = Join-Path ([Environment]::GetFolderPath("CommonApplicationData")) "NetX"
|
|
}
|
|
|
|
if (-not (Test-Path -LiteralPath $DataRoot)) {
|
|
Write-Host "==> Data root already gone: $DataRoot"
|
|
exit 0
|
|
}
|
|
|
|
Write-Host "==> Deleting data root: $DataRoot"
|
|
|
|
# Kill anything still holding files under data root.
|
|
Get-CimInstance Win32_Process -ErrorAction SilentlyContinue | Where-Object {
|
|
$_.CommandLine -and ($_.CommandLine.IndexOf($DataRoot, [StringComparison]::OrdinalIgnoreCase) -ge 0)
|
|
} | ForEach-Object {
|
|
try { Stop-Process -Id $_.ProcessId -Force -ErrorAction SilentlyContinue } catch {}
|
|
try { & taskkill.exe /F /PID $_.ProcessId 2>$null | Out-Null } catch {}
|
|
}
|
|
|
|
$ok = $false
|
|
for ($i = 1; $i -le 5; $i++) {
|
|
try {
|
|
cmd /c "rmdir /s /q `"$DataRoot`""
|
|
} catch {}
|
|
if (-not (Test-Path -LiteralPath $DataRoot)) {
|
|
$ok = $true
|
|
break
|
|
}
|
|
Start-Sleep -Seconds 1
|
|
}
|
|
|
|
if (-not $ok -and (Test-Path -LiteralPath $DataRoot)) {
|
|
try {
|
|
takeown /F $DataRoot /R /D Y | Out-Null
|
|
icacls $DataRoot /grant Administrators:F /T | Out-Null
|
|
cmd /c "rmdir /s /q `"$DataRoot`""
|
|
} catch {}
|
|
}
|
|
|
|
if (Test-Path -LiteralPath $DataRoot) {
|
|
Write-Host "[WARN] Could not fully delete $DataRoot"
|
|
exit 1
|
|
}
|
|
|
|
Write-Host "==> Data root deleted"
|
|
exit 0
|