-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsourceforge.ps1
48 lines (35 loc) · 1.31 KB
/
sourceforge.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#Requires -Version 5.0
class SourceForge {
[string] $Project = $Null
[PSCustomObject]$LatestRelease = $Null
SourceForge([string] $project) {
$this.Project = $project
$this.GetLatestRelease()
}
[void] GetLatestRelease() {
$originalSecurityProtocol = [Net.ServicePointManager]::SecurityProtocol
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$this.GetLatestRelease('https://sourceforge.net/projects/{0}/best_release.json')
[Net.ServicePointManager]::SecurityProtocol = $originalSecurityProtocol
}
[void] GetLatestRelease([string] $url) {
$url = $url -f @($this.Project)
Write-Debug "[SourceForge].GetLatestRelease URL: ${url}"
$this.LatestRelease = ConvertFrom-Json (Invoke-WebRequest $url -UseBasicParsing).Content
}
[string] LatestVersion() {
if (-not $this.LatestRelease) {
$this.GetLatestRelease()
}
return $this.LatestRelease.release.filename.Split('/')[2]
}
[hashtable] LatestHash() {
if (-not $this.LatestRelease) {
$this.GetLatestRelease()
}
return @{
'Algorithm' = 'MD5';
'Hash' = $this.LatestRelease.release.md5sum.ToUpper();
}
}
}