# Geschichten-Werkstatt entfernen (ARCHITEKTUR.md Abschnitt 9, Punkt 5). # # Über Einstellungen > Apps > Geschichten-Werkstatt > Deinstallieren, oder: # powershell -NoProfile -ExecutionPolicy Bypass -File "$env:LOCALAPPDATA\Geschichtenkiste\deinstallieren.ps1" # # Beendet die Werkstatt und löscht Programm, venv, Verknüpfungen und den Eintrag unter Apps. Die Bibliothek mit den # Geschichten und die Einstellungen bleiben, ausser bei -AuchBibliothek (oder der Frage mit j beantwortet). # Python und ffmpeg bleiben installiert (andere Programme brauchen sie vielleicht). Datei mit BOM. param( [switch]$AuchBibliothek, [switch]$Still # ohne Rückfragen (Tests, Fachleute) ) $ErrorActionPreference = 'Stop' $Name = 'Geschichten-Werkstatt' $Uninstall = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\Geschichten-Werkstatt' function Gut([string]$t) { Write-Host (' ok ' + $t) -ForegroundColor Green } function Hinweis([string]$t) { Write-Host (' ' + $t) } function Frage([string]$text, [bool]$vorgabe) { $a = (Read-Host $text).Trim().ToLowerInvariant() if (-not $a) { return $vorgabe } $a -in @('j', 'ja', 'y', 'yes') } function Wiederholen([scriptblock]$tun) { for ($i = 1; ; $i++) { try { & $tun; return } catch { if ($i -ge 10) { throw }; Start-Sleep -Milliseconds 300 } } } function Sperre-Lesen([string]$bibliothek) { try { return ([IO.File]::ReadAllText((Join-Path $bibliothek 'werkstatt.lock')) | ConvertFrom-Json) } catch { return $null } } function Werkstatt-Beenden([string]$programm, [string]$bibliothek) { # wie in einrichten.ps1: freundlich über /api/beenden, sonst hart; dazu jedes Python aus dem Programmordner $d = Sperre-Lesen $bibliothek if ($d -and $d.port) { try { $basis = 'http://127.0.0.1:{0}' -f $d.port $seite = Invoke-WebRequest -UseBasicParsing -Uri ($basis + '/') -TimeoutSec 5 if ($seite.Content -match 'name="kiste-schluessel" content="([^"]+)"') { Write-Host 'Werkstatt wird beendet ...' Invoke-WebRequest -UseBasicParsing -Method Post -Uri ($basis + '/api/beenden') -Headers @{ 'X-Kiste' = $Matches[1] } ` -ContentType 'application/json' -Body '{}' -TimeoutSec 5 | Out-Null if ($d.pid) { Wait-Process -Id $d.pid -Timeout 30 -ErrorAction SilentlyContinue } } } catch { } } $w = $programm.TrimEnd('\') + '\' foreach ($p in @(Get-Process -Name python*, pythonw*, deno*, ffmpeg*, ffprobe* -ErrorAction SilentlyContinue)) { if ($p.Path -and $p.Path.StartsWith($w, [StringComparison]::OrdinalIgnoreCase)) { Stop-Process -Id $p.Id -Force -ErrorAction SilentlyContinue Wait-Process -Id $p.Id -Timeout 10 -ErrorAction SilentlyContinue } } } $code = 1 try { $programm = $env:KISTE_PROGRAMM if (-not $programm) { $programm = Join-Path $env:LOCALAPPDATA 'Geschichtenkiste' } $einstDatei = if ($env:KISTE_EINSTELLUNGEN) { $env:KISTE_EINSTELLUNGEN } else { Join-Path $programm 'einstellungen.json' } $bibliothek = $env:KISTE_BIBLIOTHEK if (-not $bibliothek) { try { $bibliothek = ([IO.File]::ReadAllText($einstDatei, [Text.Encoding]::UTF8) | ConvertFrom-Json).bibliothek } catch { } } if (-not $bibliothek) { $bibliothek = Join-Path $env:USERPROFILE 'Geschichtenkiste' } Write-Host '' Write-Host 'Geschichten-Werkstatt entfernen' -ForegroundColor Cyan if (-not $Still) { if (-not (Frage 'Werkstatt jetzt entfernen? Die Bibliothek mit den Geschichten bleibt. [J/n]' $true)) { Write-Host 'Nichts geändert.' exit 0 } if (Test-Path -LiteralPath $bibliothek) { Write-Host ('Bibliothek: {0}' -f $bibliothek) $AuchBibliothek = Frage 'Auch die Bibliothek mit allen Geschichten löschen? Das lässt sich nicht rückgängig machen. [j/N]' $false } } Werkstatt-Beenden $programm $bibliothek # nichts im Programmordner offen halten (sonst lässt Windows ihn nicht löschen) Set-Location -LiteralPath ([IO.Path]::GetTempPath()) [Environment]::CurrentDirectory = [IO.Path]::GetTempPath() $orte = if ($env:KISTE_VERKNUEPFUNGEN) { @((Join-Path $env:KISTE_VERKNUEPFUNGEN 'Desktop'), (Join-Path $env:KISTE_VERKNUEPFUNGEN 'Startmenue')) } else { @([Environment]::GetFolderPath('Desktop'), [Environment]::GetFolderPath('Programs')) } foreach ($o in $orte) { $lnk = Join-Path $o ($Name + '.lnk') if (Test-Path -LiteralPath $lnk) { Remove-Item -LiteralPath $lnk -Force } } Gut 'Verknüpfungen entfernt' if (Test-Path -LiteralPath $Uninstall) { Remove-Item -LiteralPath $Uninstall -Recurse -Force } Gut 'Eintrag unter Apps entfernt' $rest = @() if (Test-Path -LiteralPath $programm) { foreach ($e in @(Get-ChildItem -LiteralPath $programm -Force)) { if (-not $AuchBibliothek -and $e.FullName -eq (Resolve-Path -LiteralPath $einstDatei -ErrorAction SilentlyContinue).ProviderPath) { continue } if ($e.PSIsContainer -and ($e.Attributes -band [IO.FileAttributes]::ReparsePoint)) { # die Junction aktuell nur als Verweis entfernen: rekursiv folgte Windows PowerShell 5.1 ihr ins Ziel try { Wiederholen { [IO.Directory]::Delete($e.FullName) } } catch { $rest += $e.FullName } continue } try { Wiederholen { Remove-Item -LiteralPath $e.FullName -Recurse -Force } } catch { $rest += $e.FullName } } if (-not @(Get-ChildItem -LiteralPath $programm -Force).Count) { Remove-Item -LiteralPath $programm -Force } } if ($rest) { Write-Host ('Diese Teile liessen sich nicht löschen (Neustart, dann nochmal): {0}' -f ($rest -join ', ')) -ForegroundColor Yellow } else { Gut ('Programm entfernt: {0}' -f $programm) } if ($AuchBibliothek) { if (Test-Path -LiteralPath $einstDatei) { Remove-Item -LiteralPath $einstDatei -Force } if (Test-Path -LiteralPath $bibliothek) { Wiederholen { Remove-Item -LiteralPath $bibliothek -Recurse -Force } } Gut ('Bibliothek gelöscht: {0}' -f $bibliothek) } else { Gut ('Bibliothek bleibt: {0}' -f $bibliothek) if (Test-Path -LiteralPath $einstDatei) { Hinweis ('Einstellungen bleiben für eine spätere Installation: {0}' -f $einstDatei) } } Hinweis 'Python und ffmpeg bleiben installiert; entfernen bei Bedarf unter Einstellungen > Apps.' $code = if ($rest) { 1 } else { 0 } } catch { Write-Host ('Fehler: ' + $_.Exception.Message) -ForegroundColor Red $code = 1 } if (-not $Still) { Write-Host 'Eine Taste schliesst das Fenster.' try { [void][Console]::ReadKey($true) } catch { } } exit $code