Files
piik/scripts/reset-beta-app-data.ps1
AAA 179ecd0e53 fix(tools): offer a backup-preserving beta reset entry
Add a double-click CMD wrapper for the existing beta reset script. Reuse the running-App check, explicit RESET confirmation and directory backup, and clarify the difference between a full beta profile reset and room attachment cleanup.

Validation: actual Windows CMD controls on owned synthetic data cover running-App rejection, cancellation, backup preservation and paths containing spaces, non-ASCII characters and exclamation marks. No actual user profile was reset. The desktop entry is separately bound to the current test profile.
2026-11-24 20:24:21 -05:00

50 lines
2.2 KiB
PowerShell

param(
[string]$DataDirectory = $env:PIIK_CHANNEL_APP_DATA_DIR,
[switch]$Yes
)
$ErrorActionPreference = "Stop"
if ([string]::IsNullOrWhiteSpace($DataDirectory)) {
$localAppData = [Environment]::GetFolderPath("LocalApplicationData")
if ([string]::IsNullOrWhiteSpace($localAppData)) { throw "Local application data directory is unavailable." }
$DataDirectory = Join-Path $localAppData "Piik\channel-app"
}
$appProcesses = @(Get-Process -Name "piik-app", "piik-channel-app" -ErrorAction SilentlyContinue)
if ($appProcesses.Count -gt 0) {
throw "Piik App is still running. Close it normally, then run this script again."
}
if (-not (Test-Path -LiteralPath $DataDirectory -PathType Container)) {
Write-Host "No App data directory found: $DataDirectory"
exit 0
}
$resolvedDataDirectory = (Resolve-Path -LiteralPath $DataDirectory).Path
if (-not (Test-Path -LiteralPath (Join-Path $resolvedDataDirectory "app.sqlite") -PathType Leaf)) {
throw "This is not a Piik App data directory: $resolvedDataDirectory"
}
if ((Get-Item -LiteralPath $resolvedDataDirectory).Attributes -band [IO.FileAttributes]::ReparsePoint) {
throw "Choose the actual App data directory, not a directory link."
}
$parentDirectory = Split-Path -Parent $resolvedDataDirectory
$leaf = Split-Path -Leaf $resolvedDataDirectory
$stamp = [DateTime]::UtcNow.ToString("yyyyMMdd-HHmmss-fffZ")
$backupDirectory = Join-Path $parentDirectory "$leaf.beta-backup.$stamp"
if (Test-Path -LiteralPath $backupDirectory) { throw "Backup already exists: $backupDirectory" }
if (-not $Yes) {
Write-Host "This beta-only action will rename the old data directory and keep it as a backup:"
Write-Host " $resolvedDataDirectory"
Write-Host "-> $backupDirectory"
Write-Host "The next launch starts without this directory's saved sites, App settings, local identities and rooms."
Write-Host "To clear one room's attachments, use Room settings > Records > Clear local room cache."
$answer = Read-Host "Type RESET to continue"
if ($answer -cne "RESET") { Write-Host "Cancelled."; exit 1 }
}
Move-Item -LiteralPath $resolvedDataDirectory -Destination $backupDirectory
Write-Host "The next App start will create a fresh beta data directory."
Write-Host "Old data kept at: $backupDirectory"