Skip to content

Commit

Permalink
Enhance Get-MicrosoftWindowsApp function to handle missing Content-Di…
Browse files Browse the repository at this point in the history
…sposition header for filename and version extraction
  • Loading branch information
aaronparker committed Dec 16, 2024
1 parent b1e12f4 commit 7aa2dd8
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions Evergreen/Apps/Get-MicrosoftWindowsApp.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,27 @@ function Get-MicrosoftWindowsApp {
$Headers = Invoke-EvergreenWebRequest @params
if ($null -ne $Headers) {

# Match filename
$Filename = [RegEx]::Match($Headers['Content-Disposition'], $res.Get.Download.MatchFilename).Captures.Groups[1].Value
if ([System.String]::IsNullOrWhiteSpace($Headers['Content-Disposition'])) {
# Match filename
$Filename = [RegEx]::Match($ResolvedUrl.URI, $res.Get.Download.MatchFilename).Captures.Groups[1].Value

# Match version
$Version = [RegEx]::Match($Headers['Content-Disposition'], $res.Get.Download.MatchVersion).Captures.Value
if ($Version.Length -eq 0) { $Version = "Unknown" }
# Match version
$Version = [RegEx]::Match($ResolvedUrl.URI, $res.Get.Download.MatchVersion).Captures.Value
if ($Version.Length -eq 0) { $Version = "Unknown" }
}
else {
# Match filename
$Filename = [RegEx]::Match($Headers['Content-Disposition'], $res.Get.Download.MatchFilename).Captures.Groups[1].Value

# Match version
$Version = [RegEx]::Match($Headers['Content-Disposition'], $res.Get.Download.MatchVersion).Captures.Value
if ($Version.Length -eq 0) { $Version = "Unknown" }
}

# Construct the output; Return the custom object to the pipeline
$PSObject = [PSCustomObject] @{
Version = $Version
Date = $Headers['Last-Modified'] | Select-Object -First 1
#Date = $Headers['Last-Modified'] | Select-Object -First 1
Architecture = Get-Architecture -String $Filename
Filename = $Filename
URI = $ResolvedUrl.URI
Expand Down

0 comments on commit 7aa2dd8

Please sign in to comment.