Skip to content

Commit

Permalink
Move around variables and ETag cache creation for improved cohesion
Browse files Browse the repository at this point in the history
  • Loading branch information
brogers5 committed Oct 26, 2023
1 parent 8d04a66 commit 0186585
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions update.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,6 @@ function global:au_GetLatest {

$softwareVersion = [version] [regex]::Matches($versionHistoryPage.Content, '(?i)<h3[^>]*>(Foxit Reader|Version) (.*)</h3>').Groups[2].Value

if ($softwareVersion.Build -eq 0) {
$fileNameVersion = "$($softwareVersion.Major)$($softwareVersion.Minor)"
}
else {
$fileNameVersion = "$($softwareVersion.Major)$($softwareVersion.Minor)$($softwareVersion.Build)"
}

# Using a non-English language selection to be directed toward the L10N installer binary.
$canonicalUrl = 'https://www.foxit.com/downloads/latest.html?product=Foxit-Reader&platform=Windows&softwareVersion=&package_type=exe&language=L10N'

Expand All @@ -82,11 +75,17 @@ function global:au_GetLatest {
$redirectedUriSegments = $redirectedRequestUri.Segments
$redirectedUriLocalDirectory = $redirectedRequestUri.AbsolutePath.TrimEnd($redirectedUriSegments[$redirectedUriSegments.Length - 1])

if ($softwareVersion.Build -eq 0) {
$fileNameVersion = "$($softwareVersion.Major)$($softwareVersion.Minor)"
}
else {
$fileNameVersion = "$($softwareVersion.Major)$($softwareVersion.Minor)$($softwareVersion.Build)"
}

# Probe specifically for Multi-Language Promotion with Editor EXE installer, as the canonical URL may sometimes point to a different installer type
# Using cdn01 specifically to avoid HTTP 403 (Forbidden) errors
$url32 = "https://cdn01.foxitsoftware.com$($redirectedUriLocalDirectory)FoxitPDFReader$($fileNameVersion)_L10N_Setup_Prom.exe"

$packageVersion = $softwareVersion.ToString()
$headRequest = Invoke-WebRequest -Uri $url32 -Method Head -UserAgent $userAgent
$currentETagValue = $headRequest.Headers['ETag']
$etagFilePath = '.\ETag.txt'
Expand All @@ -105,6 +104,10 @@ function global:au_GetLatest {
}
}

$currentETagValue | Out-File -FilePath $etagFilePath -Encoding UTF8

$packageVersion = $softwareVersion.ToString()

if ($global:au_Force -or $Force) {
if ($softwareVersion -le $lastPackageVersion) {
#Bump the package version number manually, since AU won't do it for us with a populated revision
Expand All @@ -118,8 +121,6 @@ function global:au_GetLatest {
}
}

$currentETagValue | Out-File -FilePath $etagFilePath -Encoding UTF8

return @{
Url32 = $url32
Version = $packageVersion
Expand Down

0 comments on commit 0186585

Please sign in to comment.