Skip to content

Commit

Permalink
Improved comments and variable names
Browse files Browse the repository at this point in the history
  • Loading branch information
Emilio0404 committed Sep 27, 2023
1 parent 730fc4f commit b689309
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions install/uninstall.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ function Uninstall {
$uninstallDirectory = Get-UninstallDirectory
Remove-InstallationFolder $uninstallDirectory
Remove-FromPath $uninstallDirectory
Write-Verbose "Custom installations that were not in `$env:Path could not be deleted."
Write-Output "Uninstalled AzureAuth!"
}

Expand All @@ -24,10 +23,10 @@ function Remove-InstallationFolder {
param ([string]$directory)

if (Test-Path -Path $directory) {
Write-Verbose "Removing installations at ${directory}"
Write-Verbose "Removing installations at '${directory}'"
Remove-Item -Force -Recurse $directory
} else {
Write-Verbose "There were no existing installations of AzureAuth found"
Write-Verbose "There were no installations found at '${directory}'"
}
}

Expand All @@ -37,25 +36,27 @@ function Remove-FromPath {
$registryPath = 'Registry::HKEY_CURRENT_USER\Environment'
$currentPath = (Get-ItemProperty -Path $registryPath -Name PATH -ErrorAction SilentlyContinue).Path

# We try to find any other AzureAuth installations that are not in default location.
# Installations in custom locations that are not listed in PATH cannot be found.
$azureauthsInPath = (Get-Command -Name azureauth -ErrorAction SilentlyContinue -CommandType Application -All).Source
$azureauthsInstallationFolders = [System.Collections.ArrayList]@()
$otherDirectories = [System.Collections.ArrayList]@()
ForEach($az in $azureauthsInPath) {
if (!$az.Contains($uninstallDirectory)) {
$additionalDirectory = (Get-Item $az).Directory.FullName
Write-Verbose "Additional installation found in ${additionalDirectory}"
$index = $azureauthsInstallationFolders.Add($additionalDirectory)
$index = $otherDirectories.Add($additionalDirectory)
Remove-InstallationFolder ($additionalDirectory)
}
}

# Reconstruct the $PATH without any azureauth directories.
$updatedPath = "";
if (($null) -ne $currentPath) {
$paths = $currentPath.Split(";")
$pathArr = @()
# We reconstruct the $PATH as an array without any azureauth directories.
ForEach($path in $paths){
if(!$path.Equals("") -And !$path.Contains($uninstallDirectory) -And `
!$azureauthsInstallationFolders.Contains($path)) {
!$otherDirectories.Contains($path)) {
$pathArr += "${path}"
}
elseif (!$path.Equals("")) {
Expand All @@ -67,6 +68,7 @@ function Remove-FromPath {

Set-ItemProperty -Path $registryPath -Name PATH -Value $updatedPath
Send-SettingChange
Write-Verbose "Custom installations that were not in `$env:Path could not be deleted."
}

# Send WM_SETTINGCHANGE after changing Environment variables.
Expand Down

0 comments on commit b689309

Please sign in to comment.