Skip to content

Commit

Permalink
Align code to project standards
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronparker committed Feb 18, 2024
1 parent 19b2d5e commit 628ae7a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
7 changes: 4 additions & 3 deletions Evergreen/Public/Export-EvergreenApp.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ function Export-EvergreenApp {
$InputObject += $Content
}

# Normalise URLs that can change on each request
foreach ($AppLibInfo in $InputObject) {
if (([System.Uri]$AppLibInfo.URI).Host -like '*.dl.sourceforge.net') {
Write-Verbose "Normalise Sourceforge download mirror URL"
$AppLibInfo.URI = $AppLibInfo.URI -replace ([System.Uri]$AppLibInfo.URI).Host,"nchc.dl.sourceforge.net"
if (([System.Uri]$AppLibInfo.URI).Host -like "*.dl.sourceforge.net") {
Write-Verbose -Message "$($MyInvocation.MyCommand): Normalise Sourceforge download mirror URL"
$AppLibInfo.URI = $AppLibInfo.URI -replace ([System.Uri]$AppLibInfo.URI).Host, "nchc.dl.sourceforge.net"
}
}

Expand Down
34 changes: 17 additions & 17 deletions Evergreen/Public/Invoke-EvergreenLibraryUpdate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -40,30 +40,30 @@ function Invoke-EvergreenLibraryUpdate {
$Library = Get-Content -Path $LibraryFile -ErrorAction "Stop" | ConvertFrom-Json -ErrorAction "Stop"

# Get current list of install media files present in library
$LibContentBefore = Get-ChildItem -Path $Path -File -Recurse -Exclude "*.json" | Select-Object FullName | Sort-Object FullName
$LibContentBefore = Get-ChildItem -Path $Path -File -Recurse -Exclude "*.json" | `
Select-Object -Property "FullName" | Sort-Object -Property "FullName"

# Return the application details
foreach ($Application in $Library.Applications) {

# Return the application details
$AppPath = $(Join-Path -Path $Path -ChildPath $Application.Name)
Write-Verbose -Message "Application path: $AppPath."
Write-Verbose -Message "Query Evergreen for: $($Application.Name)."
Write-Verbose -Message "$($MyInvocation.MyCommand): Application path: $AppPath."
Write-Verbose -Message "$($MyInvocation.MyCommand): Query Evergreen for: $($Application.Name)."

try {
Write-Verbose -Message "Filter: $($Application.Filter)."
Write-Verbose -Message "$($MyInvocation.MyCommand): Filter: $($Application.Filter)."
$WhereBlock = [ScriptBlock]::Create($Application.Filter)
}
catch {
throw $_
}

# Gather the application version information from Get-EvergreenApp
[array]$App = @()
[System.Array]$App = @()
$App = Get-EvergreenApp -Name $Application.EvergreenApp @params | Where-Object $WhereBlock

# If something returned, add to the library
if ($Null -ne $App) {
Write-Verbose -Message "Download count for $($Application.EvergreenApp): $($App.Count)."
if ($null -ne $App) {
Write-Verbose -Message "$($MyInvocation.MyCommand): Download count for $($Application.EvergreenApp): $($App.Count)."

# Save the installers to the library
if ($PSCmdlet.ShouldProcess("Downloading $($App.Count) application installers.", "Save-EvergreenApp")) {
Expand All @@ -74,12 +74,12 @@ function Invoke-EvergreenLibraryUpdate {
if ($Saved.Count -gt 1) {
for ($i = 0; $i -lt $App.Count; $i++) {
$Item = $Saved | Where-Object { $_.FullName -match $App[$i].Version -and ((Split-Path $_.FullName -Leaf) -eq (Split-Path $App[$i].URI -Leaf)) }
Write-Verbose -Message "Add path to object: $($Item.FullName)"
Write-Verbose -Message "$($MyInvocation.MyCommand): Add path to object: $($Item.FullName)"
$App[$i] | Add-Member -MemberType "NoteProperty" -Name "Path" -Value $Item.FullName
}
}
else {
Write-Verbose -Message "Add path to object: $($Saved.FullName)"
Write-Verbose -Message "$($MyInvocation.MyCommand): Add path to object: $($Saved.FullName)"
$App | Add-Member -MemberType "NoteProperty" -Name "Path" -Value $Saved.FullName
}

Expand All @@ -92,22 +92,22 @@ function Invoke-EvergreenLibraryUpdate {
$LibContentAfter = Get-ChildItem -Path $Path -File -Recurse -Exclude "*.json" | Select-Object FullName | Sort-Object FullName

# Output details of library updates
if ($Null -eq $LibContentAfter) {
Write-Output "No Installer Media found in Evergreen Library"
if ($null -eq $LibContentAfter) {
Write-Warning -Message "$($MyInvocation.MyCommand): No media found in Evergreen Library"
}
elseif ($Null -ne $LibContentBefore) {
elseif ($null -ne $LibContentBefore) {
(Compare-Object $LibContentBefore $LibContentAfter -Property FullName -IncludeEqual | ForEach-Object {
[PSCustomObject]@{
Installer = $_.Fullname
Status = $_.SideIndicator -replace '=>','NEW' -replace '==','UNCHANGED' -replace '<=','DELETED'
Status = $_.SideIndicator -replace "=>", "NEW" -replace "==", "UNCHANGED" -replace "<=", "DELETED"
}
})
}
else {
($LibContentAfter | ForEach-Object {
[PSCustomObject]@{
Installer = $_.Fullname
Status = 'NEW'
Installer = $_.FullName
Status = "NEW"
}
})
}
Expand Down

0 comments on commit 628ae7a

Please sign in to comment.