forked from lapce/lapce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproxy.ps1
47 lines (37 loc) · 1.2 KB
/
proxy.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
[CmdletBinding()]
param(
[string]$version,
[string]$directory
)
$proxy = (Join-Path $directory 'lapce.exe')
$LapceProcesses = (Get-Process -Name 'lapce' -EA SilentlyContinue).Count
if ($LapceProcesses -ne 0) {
Write-Host 'Proxy currently in use. Aborting installation'
exit
}
if (Test-Path $proxy) {
Write-Host 'Proxy already installed'
exit
}
switch ($env:PROCESSOR_ARCHITECTURE) {
# Only x86_64 is supported currently
'AMD64' {
$arch = 'x86_64'
}
}
$url = "https://github.com/lapce/lapce/releases/download/${version}/lapce-proxy-windows-${arch}.gz"
$gzip = Join-Path "${env:TMP}" "lapce-proxy-windows-${arch}.gz"
$webclient = [System.Net.WebClient]::new()
$webclient.DownloadFile($url, $gzip)
$webclient.Dispose()
[System.IO.Directory]::CreateDirectory($directory)
$archive = [System.IO.File]::Open($gzip, [System.IO.FileMode]::Open)
$proxy_file = [System.IO.File]::Create($proxy)
$compressor = [System.IO.Compression.GZipStream]::new($archive, [System.IO.Compression.CompressionMode]::Decompress)
$compressor.CopyTo($proxy_file)
Start-Sleep -Seconds 3
$compressor.close()
$proxy_file.close()
$archive.close()
[System.IO.File]::Delete($gzip)
Write-Host 'lapce-proxy installed'