App-Ariza.git | resources/templates/ | uninstall-windows.ps1.j2


<#
.SYNOPSIS
    {{ app_display }} uninstaller (Windows).

.DESCRIPTION
    Generated by ariza from {{ app_name }}'s ariza.toml. Do not edit this
    file: edit ariza's resources/templates/uninstall-windows.ps1.j2 and
    re-run `ariza installers --app=<this repository>`.

    Removes exactly what install.ps1 created: the versions directory, the
    `current` junction, and the PATH entry it added. Anything
    {{ app_display }} itself wrote — your data, your configuration — is left
    alone, and this says where it is rather than deciding for you.

.EXAMPLE
    irm {{ raw_base }}/uninstall.ps1 | iex
#>
[CmdletBinding()]
param()

$AppDisplay = '{{ app_display }}'
$AppExec    = '{{ app_exec }}'

$ArizaRoot   = Join-Path $env:LOCALAPPDATA $AppDisplay
$ArizaBinDir = Join-Path (Join-Path $ArizaRoot 'current') 'bin'

############################# common runtime ##################################
{{ lib_windows | safe }}
###############################################################################

function Ariza-Main {
    Ariza-Log "uninstalling $AppDisplay"

    # The PATH entry goes first: it names a path under $ArizaRoot, and
    # removing the tree before the entry would leave a dangling PATH
    # element if anything below failed.
    Ariza-UnpersistPath $ArizaBinDir

    if (Test-Path -LiteralPath $ArizaRoot) {
        # The junction is deleted as a link first; a recursive remove
        # would otherwise walk through it and delete the same version
        # directory twice, which on some Windows builds fails noisily
        # half way. Anything else at that path is left for Remove-Item.
        $current = Join-Path $ArizaRoot 'current'
        if ((Test-Path -LiteralPath $current) -and
            (Get-Item -LiteralPath $current -Force).LinkType) {
            Ariza-RemoveLink $current
        }
        Remove-Item -LiteralPath $ArizaRoot -Recurse -Force
        Ariza-Ok "removed $ArizaRoot"
    }
    else {
        Ariza-Log "nothing installed at $ArizaRoot"
    }

    Write-Host ''
    Ariza-Ok "$AppDisplay uninstalled"
    Write-Host '    Not touched, because this installer never wrote them:'
    Write-Host "      $(Join-Path $env:LOCALAPPDATA $AppExec)"
    Write-Host "      any data or configuration $AppDisplay created for you"
}

Ariza-Main