Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion bin/checkver.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ $Queue | ForEach-Object {
}
$regex = ''
$jsonpath = ''
$xpath = ''
$replace = ''

if ($json.checkver -eq 'github') {
Expand Down Expand Up @@ -140,12 +141,15 @@ $Queue | ForEach-Object {
if ($json.checkver.jsonpath) {
$jsonpath = $json.checkver.jsonpath
}
if ($json.checkver.xpath) {
$xpath = $json.checkver.xpath
}

if ($json.checkver.replace -and $json.checkver.replace.GetType() -eq [System.String]) {
$replace = $json.checkver.replace
}

if (!$jsonpath -and !$regex) {
if (!$jsonpath -and !$regex -and !$xpath) {
$regex = $json.checkver
}

Expand All @@ -159,6 +163,7 @@ $Queue | ForEach-Object {
regex = $regex;
json = $json;
jsonpath = $jsonpath;
xpath = $xpath;
reverse = $reverse;
replace = $replace;
}
Expand All @@ -185,6 +190,7 @@ while ($in_progress -gt 0) {
$url = $state.url
$regexp = $state.regex
$jsonpath = $state.jsonpath
$xpath = $state.xpath
$reverse = $state.reverse
$replace = $state.replace
$expected_ver = $json.version
Expand Down Expand Up @@ -214,6 +220,15 @@ while ($in_progress -gt 0) {
}
}

if ($xpath) {
# Getting version from XML, using XPath
$ver = ([xml]$page).SelectSingleNode($xpath).'#text'
if (!$ver) {
next "couldn't find '$xpath' in $url"
continue
}
}

if ($jsonpath -and $regexp) {
Comment thread
chawyehsu marked this conversation as resolved.
$page = $ver
$ver = ''
Expand Down
32 changes: 32 additions & 0 deletions lib/autoupdate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,29 @@ function find_hash_in_json([String] $url, [Hashtable] $substitutions, [String] $
return format_hash $hash
}

function find_hash_in_xml([String] $url, [Hashtable] $substitutions, [String] $xpath) {
$xml = $null

try {
$wc = New-Object Net.Webclient
$wc.Headers.Add('Referer', (strip_filename $url))
$wc.Headers.Add('User-Agent', (Get-UserAgent))
$xml = [xml]$wc.downloadstring($url)
} catch [system.net.webexception] {
write-host -f darkred $_
write-host -f darkred "URL $url is not valid"
return
}

# Replace placeholders
if ($substitutions) {
$xpath = substitute $xpath $substitutions
}

$hash = $xml.SelectSingleNode($xpath).'#text'
return format_hash $hash
}

function find_hash_in_headers([String] $url) {
$hash = $null

Expand Down Expand Up @@ -178,6 +201,12 @@ function get_hash_for_app([String] $app, $config, [String] $version, [String] $u
$regex = $config.regex
}

$xpath = ''
if ($config.xpath) {
$xpath = $config.xpath
$hashmode = 'xpath'
}

if (!$hashfile_url -and $url -match "^(?:.*fosshub.com\/).*(?:\/|\?dwl=)(?<filename>.*)$") {
$hashmode = 'fosshub'
}
Expand All @@ -193,6 +222,9 @@ function get_hash_for_app([String] $app, $config, [String] $version, [String] $u
'json' {
$hash = find_hash_in_json $hashfile_url $substitutions $jsonpath
}
'xpath' {
$hash = find_hash_in_xml $hashfile_url $substitutions $xpath
}
'rdf' {
$hash = find_hash_in_rdf $hashfile_url $basename
}
Expand Down
7 changes: 7 additions & 0 deletions schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,15 @@
"pattern": "^\\$[.[].*$",
"type": "string"
},
"xpath": {
"type": "string"
},
"mode": {
"enum": [
"download",
"extract",
"json",
"xpath",
"rdf",
"metalink",
"fosshub",
Expand Down Expand Up @@ -237,6 +241,9 @@
"pattern": "^\\$[.[].*$",
"type": "string"
},
"xpath": {
"type": "string"
},
"reverse": {
"description": "Reverse the order of regex matches",
"type": "boolean"
Expand Down