diff --git a/automatic/wps-office-free/_update.ps1 b/automatic/wps-office-free/_update.ps1 deleted file mode 100644 index 032b51be989..00000000000 --- a/automatic/wps-office-free/_update.ps1 +++ /dev/null @@ -1,37 +0,0 @@ -import-module au -import-module "$PSScriptRoot\..\..\scripts\au_extensions.psm1" - -$releases = 'https://www.wps.com/download/?lang=en' -$padVersionUnder = '10.2.1' - -function global:au_SearchReplace { - @{ - ".\tools\chocolateyInstall.ps1" = @{ - "(^[$]version\s*=\s*)('.*')" = "`$1'$($Latest.Version)'" - "(^\s*packageName\s*=\s*)('.*')" = "`$1'$($Latest.PackageName)'" - "(^\s*url\s*=\s*)('.*')" = "`$1'$($Latest.URL32)'" - "(^\s*checksum\s*=\s*)('.*')" = "`$1'$($Latest.Checksum32)'" - "(^\s*checksumType\s*=\s*)('.*')" = "`$1'$($Latest.ChecksumType32)'" - } - } -} - -function global:au_GetLatest { - $download_page = Invoke-WebRequest -UseBasicParsing -Uri $releases - - if ($download_page.Content -match 'location="(https\:\/\/.*latest_package[^"]*)') { - $url = $Matches[1] - $urlRedirected = Get-RedirectedUrl $url - $version = $urlRedirected -split '\/' | select -last 1 -skip 1 - } - else { - throw "Unable to grab installer url" - } - - @{ - URL32 = $url - Version = Get-FixVersion $version -OnlyFixBelowVersion $padVersionUnder - } -} - -update diff --git a/automatic/wps-office-free/update.ps1 b/automatic/wps-office-free/update.ps1 new file mode 100644 index 00000000000..526397cb6cb --- /dev/null +++ b/automatic/wps-office-free/update.ps1 @@ -0,0 +1,24 @@ +import-module au + . ".\update_helper.ps1" + +function global:au_SearchReplace { + @{ + ".\tools\chocolateyInstall.ps1" = @{ + "(^[$]version\s*=\s*)('.*')" = "`$1'$($Latest.Version)'" + "(^\s*packageName\s*=\s*)('.*')" = "`$1'$($Latest.PackageName)'" + "(^\s*url\s*=\s*)('.*')" = "`$1'$($Latest.URL32)'" + "(^\s*checksum\s*=\s*)('.*')" = "`$1'$($Latest.Checksum32)'" + "(^\s*checksumType\s*=\s*)('.*')" = "`$1'$($Latest.ChecksumType32)'" + } + } +} + +function global:au_GetLatest { + $streams = [ordered] @{ + wps = Get-JavaSiteUpdates -package "wps-office-free" -Title "WPS Office Free" + } + + return @{ Streams = $streams } +} + +update diff --git a/automatic/wps-office-free/update_helper.ps1 b/automatic/wps-office-free/update_helper.ps1 new file mode 100644 index 00000000000..72c816a4756 --- /dev/null +++ b/automatic/wps-office-free/update_helper.ps1 @@ -0,0 +1,71 @@ + + +function Get-PackageName() { +param( + [string]$a +) + +switch -w ( $a ) { + + 'wps-office-free' { + $PackageUrl = "https://www.wps.com/en-US/office/windows/" + } + +} + +return $PackageUrl + +} + +function Get-JavaSiteUpdates { +# $wait number can be adjusted per the package needs + param( + [string]$package, + [string]$Title, + [string]$padVersionUnder = '10.2.1', + [string]$wait = 4 + ) + +$OS_caption = ( Get-CimInstance win32_operatingsystem -Property Caption ) +$check = @{$true=$true;$false=$false}[ ( $OS_caption -match 'Server' ) ] +$regex = '([\d]{0,2}[\.][\d]{0,2}[\.][\d]{0,2}[\.][\d]{0,5})' +$url = Get-PackageName $package +$ie = New-Object -comobject InternetExplorer.Application +$ie.Navigate2($url) +$ie.Visible = $false +while($ie.ReadyState -ne $wait) { + start-sleep -Seconds 20 +} + if ( $check ) { + $url32 = $ie.Document.IHTMLDocument3_getElementsByTagName("a") | % { $_.href } | where { $_ -match $regex } | select -First 1 + } else { + $url32 = $ie.Document.getElementsByTagName("a") | % { $_.href } | where { $_ -match $regex } | select -First 1 + } + + foreach ( $_ in $ie.Document.getElementsByTagName("a") ) { + $url = $_.href; + if ( $url -match $regex) { + $yes = $url | select -last 1 + $version = $Matches[0] + $the_match = $yes -match( $rev_regex ); + $revision = $Matches[0]; + break; + } + } +$ie.quit() +if ($package -match 'wps') { +$version = $version +} else { +$version = $version + $revision +} + + + @{ + PackageName = $package + Title = $Title + fileType = 'exe' + Version = Get-FixVersion $version -OnlyFixBelowVersion $padVersionUnder + URL32 = $yes + } + +} diff --git a/automatic/wps-office-free/wps-office-free.json b/automatic/wps-office-free/wps-office-free.json new file mode 100644 index 00000000000..408cd48a079 --- /dev/null +++ b/automatic/wps-office-free/wps-office-free.json @@ -0,0 +1,3 @@ +{ + "wps": "10.2.0.7549" +}