Skip to content

Commit

Permalink
(#8) Expand aliases on core extension package
Browse files Browse the repository at this point in the history
This commit updates all helper scripts to expand the
aliases that are currently being used, to instead use
the concrete cmdlet instead.
  • Loading branch information
AdmiringWorm committed Apr 7, 2022
1 parent cd9fa7a commit 4030154
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 21 deletions.
4 changes: 4 additions & 0 deletions src/chocolatey-core.extension/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## 1.3.6

- Bugfix: Expand all aliases used in helper scripts ([#8](https://github.com/chocolatey-community/chocolatey-extensions/issues/8))

## 1.3.5

- Bugfix `Remove-Process`: Fixed Powershell v2 compatibility issue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2015/06/nuspec.xsd">
<metadata>
<id>chocolatey-core.extension</id>
<version>1.3.5.1</version>
<version>1.3.6</version>
<title>Chocolatey Core Extensions</title>
<summary>Helper functions extending core choco functionality</summary>
<authors>chocolatey</authors>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
. "$PSScriptRoot\Get-UninstallRegistryKey.ps1"
. "$PSScriptRoot\Get-UninstallRegistryKey.ps1"
<#
.SYNOPSIS
Get application install location
Expand Down Expand Up @@ -35,7 +35,7 @@ function Get-AppInstallLocation {

function strip($path) { if ($path.EndsWith('\')) { return $path -replace '.$' } else { $path } }

function is_dir( $path ) { $path -and (gi $path -ea 0).PsIsContainer -eq $true }
function is_dir( $path ) { $path -and (Get-Item $path -ea 0).PsIsContainer -eq $true }

$ErrorActionPreference = "SilentlyContinue"

Expand All @@ -58,18 +58,18 @@ function Get-AppInstallLocation {
} else { Write-Verbose "Found $($key.Count) keys, aborting this method" }

$dirs = $Env:ProgramFiles, "$Env:ProgramFiles\*\*"
if (Get-ProcessorBits 64) { $dirs += ${ENV:ProgramFiles(x86)}, "${ENV:ProgramFiles(x86)}\*\*" }
if (Get-OSArchitectureWidth 64) { $dirs += ${ENV:ProgramFiles(x86)}, "${ENV:ProgramFiles(x86)}\*\*" }
Write-Verbose "Trying Program Files with 2 levels depth: $dirs"
$location = (ls $dirs | ? {$_.PsIsContainer}) -match $AppNamePattern | select -First 1 | % {$_.FullName}
$location = (Get-ChildItem $dirs | Where-Object {$_.PsIsContainer}) -match $AppNamePattern | Select-Object -First 1 | ForEach-Object {$_.FullName}
if (is_dir $location) { return strip $location }

Write-Verbose "Trying native commands on PATH"
$location = (Get-Command -CommandType Application) -match $AppNamePattern | select -First 1 | % { Split-Path $_.Source }
$location = (Get-Command -CommandType Application) -match $AppNamePattern | Select-Object -First 1 | ForEach-Object { Split-Path $_.Source }
if (is_dir $location) { return strip $location }

$appPaths = "\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths"
Write-Verbose "Trying Registry: $appPaths"
$location = (ls "HKCU:\$appPaths", "HKLM:\$appPaths") -match $AppNamePattern | select -First 1
$location = (Get-ChildItem "HKCU:\$appPaths", "HKLM:\$appPaths") -match $AppNamePattern | Select-Object -First 1
if ($location) { $location = Split-Path $location }
if (is_dir $location) { return strip $location }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function Get-AvailableDriveLetter {
$i = @()

#getting all the used Drive letters reported by the Operating System
$(Get-PSDrive -PSProvider filesystem) | %{$i += $_.name}
$(Get-PSDrive -PSProvider filesystem) | ForEach-Object{$i += $_.name}

#Adding the excluded letter
$i+=$ExcludedLetters
Expand Down
10 changes: 5 additions & 5 deletions src/chocolatey-core.extension/extensions/Get-EffectiveProxy.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<#
<#
.SYNOPSIS
Get the current proxy using several methods
Expand Down Expand Up @@ -40,16 +40,16 @@ function Get-EffectiveProxy(){
}

# Try chocolatey config file
[xml] $cfg = gc $env:ChocolateyInstall\config\chocolatey.config
$p = $cfg.chocolatey.config | % { $_.add } | ? { $_.key -eq 'proxy' } | select -Expand value
[xml] $cfg = Get-Content $env:ChocolateyInstall\config\chocolatey.config
$p = $cfg.chocolatey.config | ForEach-Object { $_.add } | Where-Object { $_.key -eq 'proxy' } | Select-Object -Expand value
if ($p) {
Write-Verbose "Using choco config proxy"
return $p
}

# Try winhttp proxy
(netsh.exe winhttp show proxy) -match 'Proxy Server\(s\)' | set proxy
$proxy = $proxy -split ' :' | select -Last 1
(netsh.exe winhttp show proxy) -match 'Proxy Server\(s\)' | Set-Variable proxy
$proxy = $proxy -split ' :' | Select-Object -Last 1
$proxy = $proxy.Trim()
if ($proxy) {
Write-Verbose "Using winhttp proxy server"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function Get-PackageParameters {
$res = @{}

$re = "\/([a-zA-Z0-9]+)(:[`"'].+?[`"']|[^ ]+)?"
$results = $Parameters | Select-String $re -AllMatches | select -Expand Matches
$results = $Parameters | Select-String $re -AllMatches | Select-Object -Expand Matches
foreach ($m in $results) {
if (!$m) { continue } # must because of posh 2.0 bug: https://github.com/chocolatey/chocolatey-coreteampackages/issues/465

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ function Get-UninstallRegistryKey {

$keyPaths = $keys | Select-Object -ExpandProperty PSPath
try {
[array]$foundKey = Get-ItemProperty -Path $keyPaths -ea 0 | ? { $_.DisplayName -like $SoftwareName }
[array]$foundKey = Get-ItemProperty -Path $keyPaths -ea 0 | Where-Object { $_.DisplayName -like $SoftwareName }
$success = $true
} catch {
Write-Debug "Found bad key."
foreach ($key in $keys){ try{ Get-ItemProperty $key.PsPath > $null } catch { $badKey = $key.PsPath }}
Write-Verbose "Skipping bad key: $badKey"
[array]$keys = $keys | ? { $badKey -NotContains $_.PsPath }
[array]$keys = $keys | Where-Object { $badKey -NotContains $_.PsPath }
}

if ($success) { break; }
Expand Down
10 changes: 5 additions & 5 deletions src/chocolatey-core.extension/extensions/Remove-Process.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<#
<#
.SYNOPSIS
Ensure that process is stopped in reliable way
Expand Down Expand Up @@ -71,7 +71,7 @@ function Remove-Process {
# Process might spawn multiple children, typical for browsers; remove all children as parent will handle them
if (!$WithChildren) {
Write-Verbose "Remove all children processes"
$proc = $proc | ? { $proc.Id -notcontains $_.ParentId }
$proc = $proc | Where-Object { $proc.Id -notcontains $_.ParentId }
}

foreach ($p in $proc) {
Expand All @@ -81,20 +81,20 @@ function Remove-Process {
# wait for app to shut down for some time, max 5s
for ($i=0; $i -lt 5; $i++) {
Start-Sleep 1
$p2 = ps -PID $p.id -ea 0
$p2 = Get-Process -PID $p.id -ea 0
if (!$p2) { break }
}
}

# Return value of CloseMainWindow() 'True' is not reliable
# so if process is still active kill it
$p2 = ps -PID $p.id -ea 0
$p2 = Get-Process -PID $p.id -ea 0
if (($p.Process.Name -eq $p2.Name) -and ($p.Process.StartTime -eq $p2.StartTime)) {
$p | Stop-Process -ea STOP
Start-Sleep 1 # Running to fast here still gets the killed process in next line
}

$p2 = ps -PID $p.id -ea 0
$p2 = Get-Process -PID $p.id -ea 0
if (($p.Process.Name -eq $p2.Name) -and ($p.Process.StartTime -eq $p2.StartTime)) {
Write-Warning "Process '$($p.Name)' run by user '$($p.Username)' can't be closed"
}
Expand Down

0 comments on commit 4030154

Please sign in to comment.