34 lines
1.1 KiB
PowerShell
34 lines
1.1 KiB
PowerShell
|
function Get-ChocoPackageFromPath {
|
||
|
<#
|
||
|
.SYNOPSIS
|
||
|
Given a path, determine the package name from the path.
|
||
|
May return null
|
||
|
#>
|
||
|
[CmdletBinding()]
|
||
|
[OutputType([System.String],[System.Void])]
|
||
|
param(
|
||
|
[Parameter(Mandatory=$true)]
|
||
|
[ValidateNotNullOrEmpty()]
|
||
|
[string]$Path
|
||
|
)
|
||
|
|
||
|
$logLead = (Get-LogLeadName)
|
||
|
|
||
|
$chocolateyRootPath = (Get-ChocolateyInstallPath)
|
||
|
|
||
|
if (!($Path.ToLower().StartsWith($chocolateyRootPath.ToLower()))) {
|
||
|
Write-Warning "$logLead : Path isn't in a chocolatey subfolder"
|
||
|
Write-Verbose "$logLead : Path [$Path] does not start with [$chocolateyRootPath], returning $null"
|
||
|
return $null
|
||
|
}
|
||
|
|
||
|
$pathRemainder = $Path.Substring($chocolateyRootPath.Length)
|
||
|
|
||
|
$lastSplitPath = ''
|
||
|
while (($pathRemainder -ne '\lib') -and ($pathRemainder -ne '\lib-bad') -and ($pathRemainder -ne '\lib-bkp') -and ($pathRemainder -ne '\') -and ![string]::IsNullOrWhiteSpace($pathRemainder)) {
|
||
|
$lastSplitPath = (Split-Path $pathRemainder -Leaf)
|
||
|
$pathRemainder = (Split-Path $pathRemainder -Parent)
|
||
|
}
|
||
|
|
||
|
return $lastSplitPath
|
||
|
}
|