@@ -63,18 +63,6 @@ function Optimize-SecurityProtocol {
63
63
}
64
64
}
65
65
66
- function Get-Encoding ($wc ) {
67
- if ($null -ne $wc.ResponseHeaders -and $wc.ResponseHeaders [' Content-Type' ] -match ' charset=([^;]*)' ) {
68
- return [System.Text.Encoding ]::GetEncoding($Matches [1 ])
69
- } else {
70
- return [System.Text.Encoding ]::GetEncoding(' utf-8' )
71
- }
72
- }
73
-
74
- function Get-UserAgent () {
75
- return " Scoop/1.0 (+http://scoop.sh/) PowerShell/$ ( $PSVersionTable.PSVersion.Major ) .$ ( $PSVersionTable.PSVersion.Minor ) (Windows NT $ ( [System.Environment ]::OSVersion.Version.Major) .$ ( [System.Environment ]::OSVersion.Version.Minor) ; $ ( if (${env: ProgramFiles(Arm)} ){' ARM64; ' }elseif ($env: PROCESSOR_ARCHITECTURE -eq ' AMD64' ){' Win64; x64; ' }) $ ( if ($env: PROCESSOR_ARCHITEW6432 -in ' AMD64' , ' ARM64' ){' WOW64; ' }) $PSEdition )"
76
- }
77
-
78
66
function Show-DeprecatedWarning {
79
67
<#
80
68
. SYNOPSIS
@@ -228,35 +216,6 @@ function Complete-ConfigChange {
228
216
}
229
217
}
230
218
231
- function setup_proxy () {
232
- # note: '@' and ':' in password must be escaped, e.g. 'p@ssword' -> p\@ssword'
233
- $proxy = get_config PROXY
234
- if (! $proxy ) {
235
- return
236
- }
237
- try {
238
- $credentials , $address = $proxy -split ' (?<!\\)@'
239
- if (! $address ) {
240
- $address , $credentials = $credentials , $null # no credentials supplied
241
- }
242
-
243
- if ($address -eq ' none' ) {
244
- [net.webrequest ]::defaultwebproxy = $null
245
- } elseif ($address -ne ' default' ) {
246
- [net.webrequest ]::defaultwebproxy = new-object net.webproxy " http://$address "
247
- }
248
-
249
- if ($credentials -eq ' currentuser' ) {
250
- [net.webrequest ]::defaultwebproxy.credentials = [net.credentialcache ]::defaultcredentials
251
- } elseif ($credentials ) {
252
- $username , $password = $credentials -split ' (?<!\\):' | ForEach-Object { $_ -replace ' \\([@:])' , ' $1' }
253
- [net.webrequest ]::defaultwebproxy.credentials = new-object net.networkcredential($username , $password )
254
- }
255
- } catch {
256
- warn " Failed to use proxy '$proxy ': $ ( $_.exception.message ) "
257
- }
258
- }
259
-
260
219
function Invoke-Git {
261
220
[CmdletBinding ()]
262
221
[OutputType ([String ])]
@@ -584,10 +543,6 @@ function Test-HelperInstalled {
584
543
return ! [String ]::IsNullOrWhiteSpace((Get-HelperPath - Helper $Helper ))
585
544
}
586
545
587
- function Test-Aria2Enabled {
588
- return (Test-HelperInstalled - Helper Aria2) -and (get_config ' aria2-enabled' $true )
589
- }
590
-
591
546
function app_status ($app , $global ) {
592
547
$status = @ {}
593
548
$status.installed = installed $app $global
@@ -639,28 +594,6 @@ function fname($path) { split-path $path -leaf }
639
594
function strip_ext ($fname ) { $fname -replace ' \.[^\.]*$' , ' ' }
640
595
function strip_filename ($path ) { $path -replace [regex ]::escape((fname $path )) }
641
596
function strip_fragment ($url ) { $url -replace (new-object uri $url ).fragment }
642
-
643
- function url_filename ($url ) {
644
- (split-path $url - leaf).split(' ?' ) | Select-Object - First 1
645
- }
646
- # Unlike url_filename which can be tricked by appending a
647
- # URL fragment (e.g. #/dl.7z, useful for coercing a local filename),
648
- # this function extracts the original filename from the URL.
649
- function url_remote_filename ($url ) {
650
- $uri = (New-Object URI $url )
651
- $basename = Split-Path $uri.PathAndQuery - Leaf
652
- If ($basename -match " .*[?=]+([\w._-]+)" ) {
653
- $basename = $matches [1 ]
654
- }
655
- If (($basename -notlike " *.*" ) -or ($basename -match " ^[v.\d]+$" )) {
656
- $basename = Split-Path $uri.AbsolutePath - Leaf
657
- }
658
- If (($basename -notlike " *.*" ) -and ($uri.Fragment -ne " " )) {
659
- $basename = $uri.Fragment.Trim (' /' , ' #' )
660
- }
661
- return $basename
662
- }
663
-
664
597
function ensure ($dir ) {
665
598
if (! (Test-Path - Path $dir )) {
666
599
New-Item - Path $dir - ItemType Directory | Out-Null
@@ -1282,112 +1215,6 @@ function substitute($entity, [Hashtable] $params, [Bool]$regexEscape = $false) {
1282
1215
return $newentity
1283
1216
}
1284
1217
1285
- function format_hash ([String ] $hash ) {
1286
- $hash = $hash.toLower ()
1287
- switch ($hash.Length )
1288
- {
1289
- 32 { $hash = " md5:$hash " } # md5
1290
- 40 { $hash = " sha1:$hash " } # sha1
1291
- 64 { $hash = $hash } # sha256
1292
- 128 { $hash = " sha512:$hash " } # sha512
1293
- default { $hash = $null }
1294
- }
1295
- return $hash
1296
- }
1297
-
1298
- function format_hash_aria2 ([String ] $hash ) {
1299
- $hash = $hash -split ' :' | Select-Object - Last 1
1300
- switch ($hash.Length )
1301
- {
1302
- 32 { $hash = " md5=$hash " } # md5
1303
- 40 { $hash = " sha-1=$hash " } # sha1
1304
- 64 { $hash = " sha-256=$hash " } # sha256
1305
- 128 { $hash = " sha-512=$hash " } # sha512
1306
- default { $hash = $null }
1307
- }
1308
- return $hash
1309
- }
1310
-
1311
- function get_hash ([String ] $multihash ) {
1312
- $type , $hash = $multihash -split ' :'
1313
- if (! $hash ) {
1314
- # no type specified, assume sha256
1315
- $type , $hash = ' sha256' , $multihash
1316
- }
1317
-
1318
- if (@ (' md5' , ' sha1' , ' sha256' , ' sha512' ) -notcontains $type ) {
1319
- return $null , " Hash type '$type ' isn't supported."
1320
- }
1321
-
1322
- return $type , $hash.ToLower ()
1323
- }
1324
-
1325
- function Get-GitHubToken {
1326
- return $env: SCOOP_GH_TOKEN , (get_config GH_TOKEN) | Where-Object - Property Length - Value 0 -GT | Select-Object - First 1
1327
- }
1328
-
1329
- function handle_special_urls ($url )
1330
- {
1331
- # FossHub.com
1332
- if ($url -match " ^(?:.*fosshub.com\/)(?<name>.*)(?:\/|\?dwl=)(?<filename>.*)$" ) {
1333
- $Body = @ {
1334
- projectUri = $Matches.name ;
1335
- fileName = $Matches.filename ;
1336
- source = ' CF' ;
1337
- isLatestVersion = $true
1338
- }
1339
- if ((Invoke-RestMethod - Uri $url ) -match ' "p":"(?<pid>[a-f0-9]{24}).*?"r":"(?<rid>[a-f0-9]{24})' ) {
1340
- $Body.Add (" projectId" , $Matches.pid )
1341
- $Body.Add (" releaseId" , $Matches.rid )
1342
- }
1343
- $url = Invoke-RestMethod - Method Post - Uri " https://api.fosshub.com/download/" - ContentType " application/json" - Body (ConvertTo-Json $Body - Compress)
1344
- if ($null -eq $url.error ) {
1345
- $url = $url.data.url
1346
- }
1347
- }
1348
-
1349
- # Sourceforge.net
1350
- if ($url -match " (?:downloads\.)?sourceforge.net\/projects?\/(?<project>[^\/]+)\/(?:files\/)?(?<file>.*?)(?:$|\/download|\?)" ) {
1351
- # Reshapes the URL to avoid redirections
1352
- $url = " https://downloads.sourceforge.net/project/$ ( $matches [' project' ]) /$ ( $matches [' file' ]) "
1353
- }
1354
-
1355
- # Github.com
1356
- if ($url -match ' github.com/(?<owner>[^/]+)/(?<repo>[^/]+)/releases/download/(?<tag>[^/]+)/(?<file>[^/#]+)(?<filename>.*)' -and ($token = Get-GitHubToken )) {
1357
- $headers = @ { " Authorization" = " token $token " }
1358
- $privateUrl = " https://api.github.com/repos/$ ( $Matches.owner ) /$ ( $Matches.repo ) "
1359
- $assetUrl = " https://api.github.com/repos/$ ( $Matches.owner ) /$ ( $Matches.repo ) /releases/tags/$ ( $Matches.tag ) "
1360
-
1361
- if ((Invoke-RestMethod - Uri $privateUrl - Headers $headers ).Private) {
1362
- $url = ((Invoke-RestMethod - Uri $assetUrl - Headers $headers ).Assets | Where-Object - Property Name -EQ - Value $Matches.file ).Url, $Matches.filename -join ' '
1363
- }
1364
- }
1365
-
1366
- return $url
1367
- }
1368
-
1369
- function get_magic_bytes ($file ) {
1370
- if (! (Test-Path $file )) {
1371
- return ' '
1372
- }
1373
-
1374
- if ((Get-Command Get-Content ).parameters.ContainsKey(' AsByteStream' )) {
1375
- # PowerShell Core (6.0+) '-Encoding byte' is replaced by '-AsByteStream'
1376
- return Get-Content $file - AsByteStream - TotalCount 8
1377
- }
1378
- else {
1379
- return Get-Content $file - Encoding byte - TotalCount 8
1380
- }
1381
- }
1382
-
1383
- function get_magic_bytes_pretty ($file , $glue = ' ' ) {
1384
- if (! (Test-Path $file )) {
1385
- return ' '
1386
- }
1387
-
1388
- return (get_magic_bytes $file | ForEach-Object { $_.ToString (' x2' ) }) -join $glue
1389
- }
1390
-
1391
1218
function Out-UTF8File {
1392
1219
param (
1393
1220
[Parameter (Mandatory = $True , Position = 0 )]
@@ -1473,6 +1300,3 @@ $scoopPathEnvVar = switch (get_config USE_ISOLATED_PATH) {
1473
1300
1474
1301
# OS information
1475
1302
$WindowsBuild = [System.Environment ]::OSVersion.Version.Build
1476
-
1477
- # Setup proxy globally
1478
- setup_proxy
0 commit comments