mirror of
https://github.com/cmderdev/cmder.git
synced 2024-11-10 17:59:11 +08:00
update psget to the latest version
This commit is contained in:
parent
91f5c5379a
commit
72ab0f064f
77
vendor/psmodules/PsGet/PsGet.psm1
vendored
77
vendor/psmodules/PsGet/PsGet.psm1
vendored
@ -9,8 +9,16 @@
|
|||||||
#region Setup
|
#region Setup
|
||||||
|
|
||||||
Write-Debug 'Set up the global scope config variables.'
|
Write-Debug 'Set up the global scope config variables.'
|
||||||
|
if ([Environment]::GetFolderPath('MyDocuments')) {
|
||||||
$global:UserModuleBasePath = Join-Path -Path ([Environment]::GetFolderPath('MyDocuments')) -ChildPath 'WindowsPowerShell\Modules'
|
$global:UserModuleBasePath = Join-Path -Path ([Environment]::GetFolderPath('MyDocuments')) -ChildPath 'WindowsPowerShell\Modules'
|
||||||
$global:CommonGlobalModuleBasePath = Join-Path -Path $env:CommonProgramFiles -ChildPath 'Modules'
|
}
|
||||||
|
else {
|
||||||
|
# Support scenarios where PSGet is running without a MyDocuments special folder (e.g. executing within a DSC resource)
|
||||||
|
$global:UserModuleBasePath = Join-Path -Path $env:ProgramFiles -ChildPath 'WindowsPowerShell\Modules'
|
||||||
|
}
|
||||||
|
|
||||||
|
# NOTE: Path changed to align with current MS conventions
|
||||||
|
$global:CommonGlobalModuleBasePath = Join-Path -Path $env:ProgramFiles -ChildPath 'WindowsPowerShell\Modules'
|
||||||
|
|
||||||
if (-not (Test-Path -Path:variable:global:PsGetDirectoryUrl)) {
|
if (-not (Test-Path -Path:variable:global:PsGetDirectoryUrl)) {
|
||||||
$global:PsGetDirectoryUrl = 'https://github.com/psget/psget/raw/master/Directory.xml'
|
$global:PsGetDirectoryUrl = 'https://github.com/psget/psget/raw/master/Directory.xml'
|
||||||
@ -96,16 +104,16 @@ Set-Variable -Name PSGET_PSD1 -Value 'PSD1' -Option Constant -Scope Script
|
|||||||
.PARAMETER DoNotPostInstall
|
.PARAMETER DoNotPostInstall
|
||||||
If defined, the PostInstallHook is not executed.
|
If defined, the PostInstallHook is not executed.
|
||||||
|
|
||||||
.PARAMERTER PostInstallHook
|
.PARAMETER PostInstallHook
|
||||||
Defines the name of a script inside the installed module folder which should be executed after installation.
|
Defines the name of a script inside the installed module folder which should be executed after installation.
|
||||||
Default: definition in directory file or 'Install.ps1'
|
Default: definition in directory file or 'Install.ps1'
|
||||||
|
|
||||||
.PARAMETER Force
|
.PARAMETER Force
|
||||||
OBSOLATE
|
OBSOLETE
|
||||||
Alternative name for 'Update'.
|
Alternative name for 'Update'.
|
||||||
|
|
||||||
.PARAMETER Startup
|
.PARAMETER Startup
|
||||||
OBSOLATE
|
OBSOLETE
|
||||||
Alternative name for 'AddToProfile'.
|
Alternative name for 'AddToProfile'.
|
||||||
|
|
||||||
.LINK
|
.LINK
|
||||||
@ -349,7 +357,7 @@ function Install-Module {
|
|||||||
.PARAMETER DoNotPostInstall
|
.PARAMETER DoNotPostInstall
|
||||||
If defined, the PostInstallHook is not executed.
|
If defined, the PostInstallHook is not executed.
|
||||||
|
|
||||||
.PARAMERTER PostInstallHook
|
.PARAMETER PostInstallHook
|
||||||
Defines the name of a script inside the installed module folder which should be executed after installation.
|
Defines the name of a script inside the installed module folder which should be executed after installation.
|
||||||
Will not be check in combination with -All switch.
|
Will not be check in combination with -All switch.
|
||||||
Default: 'Install.ps1'
|
Default: 'Install.ps1'
|
||||||
@ -414,7 +422,7 @@ function Update-Module {
|
|||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Install-Module -Module:$Module -Destination:$Destination -ModuleHash:$ModuleHash -Global:$Global -DoNotImport:$DoNotImport -AddToProfile:$AddToProfile -DirectoryUrl:$DirectoryUrl -Updat -DoNotPostInstall:$DoNotPostInstall -PostInstallHook:$PostInstallHook
|
Install-Module -Module:$Module -Destination:$Destination -ModuleHash:$ModuleHash -Global:$Global -DoNotImport:$DoNotImport -AddToProfile:$AddToProfile -DirectoryUrl:$DirectoryUrl -Update -DoNotPostInstall:$DoNotPostInstall -PostInstallHook:$PostInstallHook
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -480,7 +488,9 @@ function Get-PsGetModuleInfo {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
Write-Verbose "Downloading modules repository from $DirectoryUrl"
|
Write-Verbose "Downloading modules repository from $DirectoryUrl"
|
||||||
$repoRaw = $client.DownloadString($DirectoryUrl)
|
$stream = $client.OpenRead($DirectoryUrl)
|
||||||
|
$repoXmlTemp = New-Object -TypeName System.Xml.XmlDocument
|
||||||
|
$repoXmlTemp.Load($stream)
|
||||||
$StatusCode = 200
|
$StatusCode = 200
|
||||||
}
|
}
|
||||||
catch [System.Net.WebException] {
|
catch [System.Net.WebException] {
|
||||||
@ -489,7 +499,7 @@ function Get-PsGetModuleInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($StatusCode -eq 200) {
|
if ($StatusCode -eq 200) {
|
||||||
$repoXml = [xml]$repoRaw
|
$repoXml = [xml]$repoXmlTemp
|
||||||
|
|
||||||
$CacheEntry.ETag = $client.ResponseHeaders['ETag']
|
$CacheEntry.ETag = $client.ResponseHeaders['ETag']
|
||||||
if (-not (Test-Path -Path $PsGetDataPath)) {
|
if (-not (Test-Path -Path $PsGetDataPath)) {
|
||||||
@ -629,7 +639,7 @@ function Get-PsGetModuleHash {
|
|||||||
.PARAMETER DoNotPostInstall
|
.PARAMETER DoNotPostInstall
|
||||||
If defined, the PostInstallHook is not executed.
|
If defined, the PostInstallHook is not executed.
|
||||||
|
|
||||||
.PARAMERTER PostInstallHook
|
.PARAMETER PostInstallHook
|
||||||
Defines the name of a script inside the installed module folder which should be executed after installation.
|
Defines the name of a script inside the installed module folder which should be executed after installation.
|
||||||
Default: definition in directory file or 'Install.ps1'
|
Default: definition in directory file or 'Install.ps1'
|
||||||
#>
|
#>
|
||||||
@ -754,7 +764,7 @@ function Install-ModuleFromDirectory {
|
|||||||
.PARAMETER DoNotPostInstall
|
.PARAMETER DoNotPostInstall
|
||||||
If defined, the PostInstallHook is not executed.
|
If defined, the PostInstallHook is not executed.
|
||||||
|
|
||||||
.PARAMERTER PostInstallHook
|
.PARAMETER PostInstallHook
|
||||||
Defines the name of a script inside the installed module folder which should be executed after installation.
|
Defines the name of a script inside the installed module folder which should be executed after installation.
|
||||||
Default: 'Install.ps1'
|
Default: 'Install.ps1'
|
||||||
#>
|
#>
|
||||||
@ -863,7 +873,7 @@ function Install-ModuleFromWeb {
|
|||||||
.PARAMETER DoNotPostInstall
|
.PARAMETER DoNotPostInstall
|
||||||
If defined, the PostInstallHook is not executed.
|
If defined, the PostInstallHook is not executed.
|
||||||
|
|
||||||
.PARAMERTER PostInstallHook
|
.PARAMETER PostInstallHook
|
||||||
Defines the name of a script inside the installed module folder which should be executed after installation.
|
Defines the name of a script inside the installed module folder which should be executed after installation.
|
||||||
Default: 'Install.ps1'
|
Default: 'Install.ps1'
|
||||||
#>
|
#>
|
||||||
@ -1010,7 +1020,7 @@ function Install-ModuleFromLocal {
|
|||||||
.PARAMETER DoNotPostInstall
|
.PARAMETER DoNotPostInstall
|
||||||
If defined, the PostInstallHook is not executed.
|
If defined, the PostInstallHook is not executed.
|
||||||
|
|
||||||
.PARAMERTER PostInstallHook
|
.PARAMETER PostInstallHook
|
||||||
Defines the name of a script inside the installed module folder which should be executed after installation.
|
Defines the name of a script inside the installed module folder which should be executed after installation.
|
||||||
Default: 'Install.ps1'
|
Default: 'Install.ps1'
|
||||||
#>
|
#>
|
||||||
@ -1311,6 +1321,13 @@ function Import-ModuleGlobally {
|
|||||||
Write-Verbose "Importing installed module '$ModuleName' from '$($installedModule.ModuleBase)'"
|
Write-Verbose "Importing installed module '$ModuleName' from '$($installedModule.ModuleBase)'"
|
||||||
Import-Module -Name $ModuleBase -Global -Force:$Force
|
Import-Module -Name $ModuleBase -Global -Force:$Force
|
||||||
|
|
||||||
|
# For psget no further checks are needed and their execution cause
|
||||||
|
# an error for the update process of 'psget'
|
||||||
|
# https://github.com/psget/psget/issues/186
|
||||||
|
if ($ModuleName -eq 'PsGet') {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
$IdentityExtension = [System.IO.Path]::GetExtension((Get-ModuleFile -Path $ModuleBase -ModuleName $ModuleName))
|
$IdentityExtension = [System.IO.Path]::GetExtension((Get-ModuleFile -Path $ModuleBase -ModuleName $ModuleName))
|
||||||
if ($IdentityExtension -eq '.dll') {
|
if ($IdentityExtension -eq '.dll') {
|
||||||
# import module twice for binary modules to workaround PowerShell bug:
|
# import module twice for binary modules to workaround PowerShell bug:
|
||||||
@ -1514,7 +1531,7 @@ function Invoke-DownloadModuleFromWeb {
|
|||||||
.PARAMETER DoNotPostInstall
|
.PARAMETER DoNotPostInstall
|
||||||
If defined, the PostInstallHook is not executed.
|
If defined, the PostInstallHook is not executed.
|
||||||
|
|
||||||
.PARAMERTER PostInstallHook
|
.PARAMETER PostInstallHook
|
||||||
Defines the name of a script inside the installed module folder which should be executed after installation.
|
Defines the name of a script inside the installed module folder which should be executed after installation.
|
||||||
#>
|
#>
|
||||||
function Install-ModuleToDestination {
|
function Install-ModuleToDestination {
|
||||||
@ -1628,7 +1645,7 @@ function Install-ModuleToDestination {
|
|||||||
|
|
||||||
$isDestinationInPSModulePath = $env:PSModulePath.Contains($Destination)
|
$isDestinationInPSModulePath = $env:PSModulePath.Contains($Destination)
|
||||||
if ($isDestinationInPSModulePath) {
|
if ($isDestinationInPSModulePath) {
|
||||||
if (-not (Get-Module $ModuleName -ListAvailable)) {
|
if (-not (Get-Module $InstallWithModuleName -ListAvailable)) {
|
||||||
throw 'For some unexpected reasons module was not installed.'
|
throw 'For some unexpected reasons module was not installed.'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1639,14 +1656,14 @@ function Install-ModuleToDestination {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($Update) {
|
if ($Update) {
|
||||||
Write-Host "Module $ModuleName was successfully updated." -Foreground Green
|
Write-Host "Module $InstallWithModuleName was successfully updated." -Foreground Green
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Write-Host "Module $ModuleName was successfully installed." -Foreground Green
|
Write-Host "Module $InstallWithModuleName was successfully installed." -Foreground Green
|
||||||
}
|
}
|
||||||
|
|
||||||
if (-not $DoNotImport) {
|
if (-not $DoNotImport) {
|
||||||
Import-ModuleGlobally -ModuleName:$ModuleName -ModuleBase:$targetFolderPath -Force:$Update
|
Import-ModuleGlobally -ModuleName:$InstallWithModuleName -ModuleBase:$targetFolderPath -Force:$Update
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($isDestinationInPSModulePath -and $AddToProfile) {
|
if ($isDestinationInPSModulePath -and $AddToProfile) {
|
||||||
@ -1657,8 +1674,8 @@ function Install-ModuleToDestination {
|
|||||||
New-Item $PROFILE -Type File -Force -ErrorAction Stop
|
New-Item $PROFILE -Type File -Force -ErrorAction Stop
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Select-String $PROFILE -Pattern "Import-Module $ModuleName") {
|
if (Select-String $PROFILE -Pattern "Import-Module $InstallWithModuleName") {
|
||||||
Write-Verbose "Import-Module $ModuleName command already in your profile"
|
Write-Verbose "Import-Module $InstallWithModuleName command already in your profile"
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$signature = Get-AuthenticodeSignature -FilePath $PROFILE
|
$signature = Get-AuthenticodeSignature -FilePath $PROFILE
|
||||||
@ -1667,8 +1684,8 @@ function Install-ModuleToDestination {
|
|||||||
Write-Error "PsGet cannot modify code-signed profile '$PROFILE'."
|
Write-Error "PsGet cannot modify code-signed profile '$PROFILE'."
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Write-Verbose "Add Import-Module $ModuleName command to the profile"
|
Write-Verbose "Add Import-Module $InstallWithModuleName command to the profile"
|
||||||
"`nImport-Module $ModuleName" | Add-Content $PROFILE
|
"`nImport-Module $InstallWithModuleName" | Add-Content $PROFILE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1736,7 +1753,7 @@ function Test-ModuleInstalledAndImport {
|
|||||||
return $false
|
return $false
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Warning "The module '$ModuleName' was installed at more then one location. Installed paths:`n`t$($installedModule.ModuleBase | Format-List | Out-String)`n'$($firstInstalledModule.ModuleBase)' is the searched destination."
|
Write-Warning "The module '$ModuleName' was installed at more than one location. Installed paths:`n`t$($installedModule.ModuleBase | Format-List | Out-String)`n'$($firstInstalledModule.ModuleBase)' is the searched destination."
|
||||||
$installedModule = $targetModule
|
$installedModule = $targetModule
|
||||||
}
|
}
|
||||||
elseif ((Split-Path $installedModule.ModuleBase) -ne $Destination) {
|
elseif ((Split-Path $installedModule.ModuleBase) -ne $Destination) {
|
||||||
@ -1801,7 +1818,7 @@ function Expand-ZipModule {
|
|||||||
|
|
||||||
# Check if powershell v3+ and .net v4.5 is available
|
# Check if powershell v3+ and .net v4.5 is available
|
||||||
$netFailed = $true
|
$netFailed = $true
|
||||||
if ( $PSVersionTable.PSVersion.Major -ge 3 -and (Get-ChildItem -Path 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4' -Recurse | Get-ItemProperty -Name Version | Where-Object { $_.Version -like '4.5*' }) ) {
|
if ( $PSVersionTable.PSVersion.Major -ge 3 -and (Get-ChildItem -Path 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4' -Recurse | Get-ItemProperty -Name Version | Where-Object { $_.Version -like '4.5*' -Or $_.Version -ge '4.5' }) ) {
|
||||||
Write-Debug 'Attempting unzip using the .NET Framework...'
|
Write-Debug 'Attempting unzip using the .NET Framework...'
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -1910,15 +1927,21 @@ function Invoke-DownloadNuGetPackage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Write-Verbose "Querying '$Source' repository for package with Id '$NuGetPackageId'"
|
Write-Verbose "Querying '$Source' repository for package with Id '$NuGetPackageId'"
|
||||||
$Url = "{1}Packages()?`$filter=tolower(Id)+eq+'{0}'&`$orderby=Id" -f $NuGetPackageId.ToLower(), $Source
|
|
||||||
Write-Debug "NuGet query url: $Url"
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
$Url = "{1}Packages()?`$filter=tolower(Id)+eq+'{0}'&`$orderby=Id" -f $NuGetPackageId.ToLower(), $Source
|
||||||
|
Write-Debug "Trying NuGet query url: $Url"
|
||||||
|
$XmlDoc = [xml]$WebClient.DownloadString($Url)
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
try {
|
||||||
|
$Url = "{1}Packages(Id='{0}')?`$orderby=Id" -f $NuGetPackageId, $Source
|
||||||
|
Write-Debug "Trying NuGet query url: $Url"
|
||||||
$XmlDoc = [xml]$WebClient.DownloadString($Url)
|
$XmlDoc = [xml]$WebClient.DownloadString($Url)
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
throw "Unable to download from NuGet feed: $($_.Exception.InnerException.Message)"
|
throw "Unable to download from NuGet feed: $($_.Exception.InnerException.Message)"
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($PackageVersion) {
|
if ($PackageVersion) {
|
||||||
# version regexs can be found in the NuGet.SemanticVersion class
|
# version regexs can be found in the NuGet.SemanticVersion class
|
||||||
@ -2110,7 +2133,7 @@ function TabExpansion {
|
|||||||
Get-PsGetModuleInfo -ModuleName "$lastword*" | % { $_.Id } | sort -Unique
|
Get-PsGetModuleInfo -ModuleName "$lastword*" | % { $_.Id } | sort -Unique
|
||||||
}
|
}
|
||||||
elseif ( Test-Path -Path Function:\$tabExpansionBackup ) {
|
elseif ( Test-Path -Path Function:\$tabExpansionBackup ) {
|
||||||
& $teBackup $line $lastWord
|
& $tabExpansionBackup $line $lastWord
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user