forked from scriptcs/scriptcs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchocolateyInstall.ps1
More file actions
43 lines (37 loc) · 1.45 KB
/
chocolateyInstall.ps1
File metadata and controls
43 lines (37 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
try {
$tools = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)"
if (Test-Path "$tools\..\lib") {
Remove-Item "$tools\..\lib" -Recurse -Force
}
# Handle upgrade from previous packages that installed to the %AppData%/scriptcs folders.
$oldPaths = @(
"$env:APPDATA\scriptcs",
"$env:LOCALAPPDATA\scriptcs"
)
$oldPaths | foreach {
# Remove the old user-specific scriptcs folders.
if (Test-Path $_) {
Remove-Item $_ -Recurse -Force
}
# Remove the user-specific path that got added in previous installs.
# There's no Uninstall-ChocolateyPath yet so we need to do it manually.
# https://github.com/chocolatey/chocolatey/issues/97
$envPath = $env:PATH
if ($envPath.ToLower().Contains($_.ToLower())) {
$userPath = [Environment]::GetEnvironmentVariable("Path","User")
if($userPath) {
$actualPath = [System.Collections.ArrayList]($userPath).Split(";")
$actualPath.Remove($_)
$newPath = $actualPath -Join ";"
[Environment]::SetEnvironmentVariable("Path", $newPath, "User")
}
}
Write-Host "'$_' has been removed." -ForegroundColor DarkYellow
}
Update-SessionEnvironment
# End upgrade handling.
Write-ChocolateySuccess 'scriptcs'
} catch {
Write-ChocolateyFailure 'scriptcs' "$($_.Exception.Message)"
throw
}