-
Notifications
You must be signed in to change notification settings - Fork 30
/
Update-WinSCPCore.ps1
76 lines (61 loc) · 2.64 KB
/
Update-WinSCPCore.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#requires -Modules PSAppVeyor
[CmdletBinding()]
[OutputType()]
param ()
$uri = "https://winscp.net"
# Current version of dll in PowerShell build.
[Version]$currentVersion = (Get-Item -Path "${pwd}\WinSCP\lib\netstandard2.0\WinSCPnet.dll").VersionInfo.ProductVersion
try {
$payloadName = ((Invoke-WebRequest -Uri "${uri}/eng/downloads.php" -UseBasicParsing -ErrorAction Stop).Links | Select-String -Pattern "WinSCP-.*?\d+-Automation\.zip").Matches.Value
} catch {
$PSCmdlet.ThrowTerminatingError(
$_
)
exit
}
# Lastest version of dll on WinSCP.net.
[Version]$publishedVersion = ($payloadName | Select-String -Pattern "\d.*\d").Matches.Value
if ($publishedVersion -gt $currentVersion) {
try {
$payloadPage = Invoke-WebRequest -Uri "${uri}/download/${payloadName}" -UseBasicParsing
$payload = ($payloadPage.Links | Select-String -Pattern "https://cdn.+?(?=`")").Matches.Value[0]
$downloader = New-Object -TypeName System.Net.WebClient
$downloader.DownloadFile(
$payload, "${env:TEMP}\$payloadName"
)
Unblock-File -Path "${env:TEMP}\$payloadName"
Expand-Archive -Path "${env:TEMP}\$payloadName" -DestinationPath "${env:TEMP}\WinSCP\" -Force
$downloader.Dispose()
} catch {
Write-Error $_
exit
}
try {
Move-Item -Path "${env:TEMP}\WinSCP\*.txt" -Destination "${pwd}\WinSCP\en-US\" -Force -Confirm:$false -ErrorAction Stop
Move-Item -Path "${env:TEMP}\WinSCP\*.exe" -Destination "${pwd}\WinSCP\bin\" -Force -Confirm:$false -ErrorAction Stop
Move-Item -Path "${env:TEMP}\WinSCP\net40\*.dll" -Destination "${pwd}\WinSCP\lib\net40\" -Force -Confirm:$false -ErrorAction Stop
Move-Item -Path "${env:TEMP}\WinSCP\netstandard2.0\*.dll" -Destination "${pwd}\WinSCP\lib\netstandard2.0\" -Force -Confirm:$false -ErrorAction Stop
} catch {
Write-Error $_
exit
}
# Update AppVeyor yml build info.
$buildFile = "${pwd}\.github\workflows\Build.yml"
$yml = Get-Content -Path $buildFile
$yml = $yml -replace ($yml | Select-String -Pattern "\d.*\d").Matches.Value[0], $publishedVersion
Set-Content -Path $buildFile -Value $yml
# TODO
# Ensure PlatyPS is updated to the latest module version.
# Recompile help files.
# Clean up downloaded and extracted files.
Remove-Item -Path "${env:TEMP}\$payloadName" -Force -Confirm:$false
Remove-Item -Path "${env:TEMP}\WinSCP" -Recurse -Force -Confirm:$false
try {
git add .
git commit -a -m "[Publish] - Updating WinSCP Core to $publishedVersion."
git push
} catch {
Write-Error $_
exit
}
}