From 3ba9e9cb621d4055c38b80b0b6df8d8d75a3b0b6 Mon Sep 17 00:00:00 2001 From: "Kim J. Nordmo" Date: Mon, 21 Mar 2022 17:10:00 +0100 Subject: [PATCH] (#6) Remove helpers moved to compatibility package This commit updates the core extension package by removing the helpers that are available now in the compatibility package instead. Recommendation going forward is to take a reference on the compatibility package instead of the core extension if compatibility is of concern. Co-authored-by: Joel Sallow (/u/ta11ow) <32407840+vexx32@users.noreply.github.com> --- src/chocolatey-core.extension/CHANGELOG.md | 3 +- src/chocolatey-core.extension/README.md | 18 +++- .../chocolatey-core.extension.nuspec | 20 +++- .../extensions/Get-PackageParameters.ps1 | 35 ------ .../extensions/Get-UninstallRegistryKey.ps1 | 102 ------------------ 5 files changed, 31 insertions(+), 147 deletions(-) delete mode 100644 src/chocolatey-core.extension/extensions/Get-PackageParameters.ps1 delete mode 100644 src/chocolatey-core.extension/extensions/Get-UninstallRegistryKey.ps1 diff --git a/src/chocolatey-core.extension/CHANGELOG.md b/src/chocolatey-core.extension/CHANGELOG.md index bd1af18..2b98b45 100644 --- a/src/chocolatey-core.extension/CHANGELOG.md +++ b/src/chocolatey-core.extension/CHANGELOG.md @@ -1,9 +1,10 @@ # CHANGELOG -## 1.3.6 +## 1.4.0 - Bugfix: Expand all aliases used in helper scripts ([#8](https://github.com/chocolatey-community/chocolatey-extensions/issues/8)) - Add dependency of compatibility packages to prevent breaking changes ([#7](https://github.com/chocolatey-community/chocolatey-extensions/issues/7)) +- Remove `Get-PackageParameters` and `Get-UninstallRegistryKey` that are moved to [chocolatey-compatibility.extension](https://community.chocolatey.org/packages/chocolatey-compatibility.extension) package instead ([#6](https://github.com/chocolatey-community/chocolatey-extensions/issues/6)) ## 1.3.5 diff --git a/src/chocolatey-core.extension/README.md b/src/chocolatey-core.extension/README.md index 500e701..b98f971 100644 --- a/src/chocolatey-core.extension/README.md +++ b/src/chocolatey-core.extension/README.md @@ -1,6 +1,15 @@ # chocolatey-core.extension -This is the Powershell module that extends Chocolatey with new functions. +This is a extension package that provides helper functions installed as a Chocolatey extension. +These functions may be used in Chocolatey install/uninstall scripts by declaring this package a dependency in your package's nuspec. +This package provides helper functions that can be used to enhance what is already available out of the box with Chocolatey CLI. +This includes both features that are being tested for Chocolatey CLI itself, and other helpers to make the maintenance of +Chocolatey packages easier. + +Helpers that were available in this package, and were later added to Chocolatey CLI, will be moved to +the package [chocolatey-compatibility.extension](https://community.chocolatey.org/packages/chocolatey-compatibility.extension). + +Backwards compatibility is not considered for helpers available in this package, see the Notes below. ## Installation @@ -40,11 +49,10 @@ To get the list of functions, load the module directly and invoke the following To get the help for the specific function use `man`: - man Get-UninstallRegistryKey + man Get-EffectiveProxy ## Notes -- There is [a known bug](https://github.com/chocolatey-community/chocolatey-coreteampackages/issues/784) in the function `Get-AppInstallLocation` with parameter `$AppNamePattern` which is internally used both as wildcard and regex patterns. This usually doesn't create any problems, but may do so if application contains regex symbols in the name, such as [notepad++](https://github.com/chocolatey-community/chocolatey-coreteampackages/issues/1198). - - +- There is [a known bug](https://github.com/chocolatey-community/chocolatey-extensions/issues/11) in the function `Get-AppInstallLocation` with parameter `$AppNamePattern` which is internally used both as wildcard and regex patterns. This usually doesn't create any problems, but may do so if application contains regex symbols in the name, such as [notepad++](https://github.com/chocolatey-community/chocolatey-coreteampackages/issues/1198). +- This package itself are not concerted of keeping backwards compatibility, if compatibility is of concern take a dependency on [chocolatey-compatibility.extension](https://community.chocolatey.org/packages/chocolatey-compatibility.extension) instead diff --git a/src/chocolatey-core.extension/chocolatey-core.extension.nuspec b/src/chocolatey-core.extension/chocolatey-core.extension.nuspec index f5bd24f..44d9245 100644 --- a/src/chocolatey-core.extension/chocolatey-core.extension.nuspec +++ b/src/chocolatey-core.extension/chocolatey-core.extension.nuspec @@ -3,15 +3,27 @@ chocolatey-core.extension - 1.3.6 + 1.4.0 Chocolatey Core Extensions Helper functions extending core choco functionality chocolatey chocolatey-community - -This package provides helper functions installed as a Chocolatey extension. + +This package provides helper functions that can be used to enhance what is already available out of the box with Chocolatey CLI. +This includes both features that are being tested for Chocolatey CLI itself, and other helpers to make the maintenance of +Chocolatey packages easier. + +Helpers that were available in this package, and were later added to Chocolatey CLI, will be moved to +the package [chocolatey-compatibility.extension](https://community.chocolatey.org/packages/chocolatey-compatibility.extension). + +Backwards compatibility is not considered for helpers available in this package, see the Notes below. + +## Notes + +- There is [a known bug](https://github.com/chocolatey-community/chocolatey-extensions/issues/11) in the function `Get-AppInstallLocation` with parameter `$AppNamePattern` which is internally used both as wildcard and regex patterns. This usually doesn't create any problems, but may do so if application contains regex symbols in the name, such as [notepad++](https://github.com/chocolatey-community/chocolatey-coreteampackages/issues/1198). +- This package itself is not concerned with keeping backwards compatibility with Chocolatey CLI. If compatibility is of concern, instead take a dependency on [chocolatey-compatibility.extension](https://community.chocolatey.org/packages/chocolatey-compatibility.extension). +]]> chocolatey core extension admin https://github.com/chocolatey-community/chocolatey-extensions diff --git a/src/chocolatey-core.extension/extensions/Get-PackageParameters.ps1 b/src/chocolatey-core.extension/extensions/Get-PackageParameters.ps1 deleted file mode 100644 index 2b5f6a5..0000000 --- a/src/chocolatey-core.extension/extensions/Get-PackageParameters.ps1 +++ /dev/null @@ -1,35 +0,0 @@ -<# -.SYNOPSIS - Parses parameters of the package - -.EXAMPLE - Get-PackageParameters "/Shortcut /InstallDir:'c:\program files\xyz' /NoStartup" | set r - if ($r.Shortcut) {... } - Write-Host $r.InstallDir - -.OUTPUTS - [HashTable] -#> -function Get-PackageParameters { - [CmdletBinding()] - param( - [string] $Parameters = $Env:ChocolateyPackageParameters, - # Allows splatting with arguments that do not apply and future expansion. Do not use directly. - [parameter(ValueFromRemainingArguments = $true)] - [Object[]] $IgnoredArguments - ) - - $res = @{} - - $re = "\/([a-zA-Z0-9]+)(:[`"'].+?[`"']|[^ ]+)?" - $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 - - $a = $m.Value -split ':' - $opt = $a[0].Substring(1); $val = $a[1..100] -join ':' - if ($val -match '^(".+")|(''.+'')$') {$val = $val -replace '^.|.$'} - $res[ $opt ] = if ($val) { $val } else { $true } - } - $res -} diff --git a/src/chocolatey-core.extension/extensions/Get-UninstallRegistryKey.ps1 b/src/chocolatey-core.extension/extensions/Get-UninstallRegistryKey.ps1 deleted file mode 100644 index 062868e..0000000 --- a/src/chocolatey-core.extension/extensions/Get-UninstallRegistryKey.ps1 +++ /dev/null @@ -1,102 +0,0 @@ -<# -.SYNOPSIS - Retrieve registry key(s) for system-installed applications from an exact or wildcard search. - -.DESCRIPTION - This function will attempt to retrieve a matching registry key for an already installed application, - usually to be used with a chocolateyUninstall.ps1 automation script. - - The function also prevents `Get-ItemProperty` from failing when handling wrongly encoded registry keys. - -.PARAMETER SoftwareName - Part or all of the Display Name as you see it in Programs and Features. - It should be enough to be unique. - The syntax follows the rules of the PowerShell `-like` operator, so the `*` character is interpreted - as a wildcard, which matches any (zero or more) characters. - - If the display name contains a version number, such as "Launchy (2.5)", it is recommended you use a - fuzzy search `"Launchy (*)"` (the wildcard `*`) so if Launchy auto-updates or is updated outside - of chocolatey, the uninstall script will not fail. - - Take care not to abuse fuzzy/glob pattern searches. Be conscious of programs that may have shared - or common root words to prevent overmatching. For example, "SketchUp*" would match two keys with software - names "SketchUp 2016" and "SketchUp Viewer" that are different programs released by the same company. - -.PARAMETER IgnoredArguments - Allows splatting with arguments that do not apply and future expansion. Do not use directly. - -.INPUTS - System.String - -.OUTPUTS - PSCustomObject - -.EXAMPLE - [array]$key = Get-UninstallRegistryKey -SoftwareName "VLC media player" - $key.UninstallString - - Exact match: software name in Programs and Features is "VLC media player" - -.EXAMPLE - [array]$key = Get-UninstallRegistryKey -SoftwareName "Gpg4win (*)" - $key.UninstallString - - Version match: software name is "Gpg4Win (2.3.0)" - -.EXAMPLE - [array]$key = Get-UninstallRegistryKey -SoftwareName "SketchUp [0-9]*" - $key.UninstallString - - Version match: software name is "SketchUp 2016" - Note that the similar software name "SketchUp Viewer" would not be matched. - -.LINK - Uninstall-ChocolateyPackage -#> -function Get-UninstallRegistryKey { - [CmdletBinding()] - param( - [Parameter(Mandatory=$true, ValueFromPipeline=$true)] - [ValidateNotNullOrEmpty()] - [string] $SoftwareName, - [parameter(ValueFromRemainingArguments = $true)] - [Object[]] $IgnoredArguments - ) - Write-Debug "Running 'Get-UninstallRegistryKey' for `'$env:ChocolateyPackageName`' with SoftwareName:`'$SoftwareName`'"; - - $ErrorActionPreference = 'Stop' - $local_key = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*' - $machine_key = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*' - $machine_key6432 = 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*' - - Write-Verbose "Retrieving all uninstall registry keys" - [array]$keys = Get-ChildItem -Path @($machine_key6432, $machine_key, $local_key) -ea 0 - Write-Debug "Registry uninstall keys on system: $($keys.Count)" - - Write-Debug "Error handling check: `'Get-ItemProperty`' fails if a registry key is encoded incorrectly." - [int]$maxAttempts = $keys.Count - for ([int]$attempt = 1; $attempt -le $maxAttempts; $attempt++) - { - $success = $false - - $keyPaths = $keys | Select-Object -ExpandProperty PSPath - try { - [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 | Where-Object { $badKey -NotContains $_.PsPath } - } - - if ($success) { break; } - if ($attempt -eq 10) { - Write-Warning "Found more than 10 bad registry keys. Run command again with `'--verbose --debug`' for more info." - Write-Debug "Each key searched should correspond to an installed program. It is very unlikely to have more than a few programs with incorrectly encoded keys, if any at all. This may be indicative of one or more corrupted registry branches." - } - } - - Write-Debug "Found $($foundKey.Count) uninstall registry key(s) with SoftwareName:`'$SoftwareName`'"; - return $foundKey -}