Skip to content

Commit b3b7519

Browse files
committed
Added upgrade support from old install
Added a routine to deal with removing the per-user install of scriptcs and per-user PATH setting on upgrade.
1 parent 06d5aff commit b3b7519

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

src/ScriptCs/Properties/chocolateyInstall.ps1

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,37 @@
1818
Remove-Item "$tools\..\lib" -Recurse -Force
1919
}
2020

21+
# Handle upgrade from previous packages that installed to the %AppData%/scriptcs folders.
22+
$oldPaths = @(
23+
"$env:APPDATA\scriptcs",
24+
"$env:LOCALAPPDATA\scriptcs"
25+
)
26+
27+
$oldPaths | foreach {
28+
# Remove the old user-specific scriptcs folders.
29+
if (Test-Path $_) {
30+
Remove-Item $_ -Recurse -Force
31+
}
32+
33+
# Remove the user-specific path that got added in previous installs.
34+
# There's no Uninstall-ChocolateyPath yet so we need to do it manually.
35+
# https://github.com/chocolatey/chocolatey/issues/97
36+
$envPath = $env:PATH
37+
if ($envPath.ToLower().Contains($_.ToLower())) {
38+
$userPath = Get-EnvironmentVariable -Name 'Path' -Scope "User"
39+
if($userPath) {
40+
$actualPath = [System.Collections.ArrayList]($userPath).Split(";")
41+
$actualPath.Remove($_)
42+
$newPath = $actualPath -Join ";"
43+
Set-EnvironmentVariable -Name 'Path' -Value $newPath -Scope "User"
44+
}
45+
}
46+
47+
Write-Host "'$_' has been removed." -ForegroundColor DarkYellow
48+
}
49+
Update-SessionEnvironment
50+
# End upgrade handling.
51+
2152
Write-ChocolateySuccess 'scriptcs'
2253
} catch {
2354
Write-ChocolateyFailure 'scriptcs' "$($_.Exception.Message)"

0 commit comments

Comments
 (0)