|
1 |
| -# list manifests which do not specify a checkver regex |
| 1 | +<# |
| 2 | +.SYNOPSIS |
| 3 | + List manifests which do not have valid URLs. |
| 4 | +.PARAMETER App |
| 5 | + Manifest name to search. |
| 6 | + Placeholder is supported. |
| 7 | +.PARAMETER Dir |
| 8 | + Where to search for manifest(s). |
| 9 | +.PARAMETER Timeout |
| 10 | + How long (seconds) the request can be pending before it times out. |
| 11 | +.PARAMETER SkipValid |
| 12 | + Manifests will all valid URLs will not be shown. |
| 13 | +#> |
2 | 14 | param(
|
3 |
| - [String]$app, |
4 |
| - [String]$dir, |
5 |
| - [Int]$timeout = 5 |
| 15 | + [String] $App = '*', |
| 16 | + [ValidateScript( { |
| 17 | + if (!(Test-Path $_ -Type Container)) { |
| 18 | + throw "$_ is not a directory!" |
| 19 | + } else { |
| 20 | + $true |
| 21 | + } |
| 22 | + })] |
| 23 | + [String] $Dir = "$PSScriptRoot\\..\bucket", |
| 24 | + [Int] $Timeout = 5, |
| 25 | + [Switch] $SkipValid |
6 | 26 | )
|
7 | 27 |
|
8 |
| -if(!$dir) { $dir = "$psscriptroot\..\bucket" } |
9 |
| -$dir = resolve-path $dir |
10 |
| - |
11 |
| -$search = "*" |
12 |
| -if($app) { $search = $app } |
| 28 | +. "$PSScriptRoot\..\lib\core.ps1" |
| 29 | +. "$PSScriptRoot\..\lib\manifest.ps1" |
| 30 | +. "$PSScriptRoot\..\lib\config.ps1" |
| 31 | +. "$PSScriptRoot\..\lib\install.ps1" |
13 | 32 |
|
14 |
| -. "$psscriptroot\..\lib\core.ps1" |
15 |
| -. "$psscriptroot\..\lib\manifest.ps1" |
16 |
| -. "$psscriptroot\..\lib\config.ps1" |
17 |
| -. "$psscriptroot\..\lib\install.ps1" |
| 33 | +$Dir = Resolve-Path $Dir |
| 34 | +$Queue = @() |
18 | 35 |
|
19 |
| -if(!$dir) { $dir = "$psscriptroot\..\bucket" } |
20 |
| -$dir = resolve-path $dir |
21 |
| - |
22 |
| -# get apps to check |
23 |
| -$queue = @() |
24 |
| -Get-ChildItem $dir "$search.json" | ForEach-Object { |
25 |
| - $manifest = parse_json "$dir\$($_.Name)" |
26 |
| - $queue += ,@($_.Name, $manifest) |
| 36 | +Get-ChildItem $Dir "$App.json" | ForEach-Object { |
| 37 | + $manifest = parse_json "$Dir\$($_.Name)" |
| 38 | + $Queue += , @($_.Name, $manifest) |
27 | 39 | }
|
28 | 40 |
|
29 | 41 | $original = use_any_https_protocol
|
30 | 42 |
|
31 |
| -write-host "[" -nonewline |
32 |
| -write-host -f cyan "U" -nonewline |
33 |
| -write-host "]RLs" |
34 |
| -write-host " | [" -nonewline |
35 |
| -write-host -f green "O" -nonewline |
36 |
| -write-host "]kay" |
37 |
| -write-host " | | [" -nonewline |
38 |
| -write-host -f red "F" -nonewline |
39 |
| -write-host "]ailed" |
40 |
| -write-host " | | |" |
41 |
| - |
42 |
| -function test_dl($url, $cookies) { |
43 |
| - $wreq = [net.webrequest]::create($url) |
44 |
| - $wreq.timeout = $timeout * 1000 |
45 |
| - if($wreq -is [net.httpwebrequest]) { |
46 |
| - $wreq.useragent = Get-UserAgent |
47 |
| - $wreq.referer = strip_filename $url |
48 |
| - if($cookies) { |
49 |
| - $wreq.headers.add('Cookie', (cookie_header $cookies)) |
| 43 | +Write-Host '[' -NoNewLine |
| 44 | +Write-Host 'U' -NoNewLine -ForegroundColor Cyan |
| 45 | +Write-Host ']RLs' |
| 46 | +Write-Host ' | [' -NoNewLine |
| 47 | +Write-Host 'O' -NoNewLine -ForegroundColor Green |
| 48 | +Write-Host ']kay' |
| 49 | +Write-Host ' | | [' -NoNewLine |
| 50 | +Write-Host 'F' -NoNewLine -ForegroundColor Red |
| 51 | +Write-Host ']ailed' |
| 52 | +Write-Host ' | | |' |
| 53 | + |
| 54 | +function test_dl([String] $url, $cookies) { |
| 55 | + $wreq = [Net.WebRequest]::Create($url) |
| 56 | + $wreq.Timeout = $Timeout * 1000 |
| 57 | + if ($wreq -is [Net.HttpWebRequest]) { |
| 58 | + $wreq.UserAgent = Get-UserAgent |
| 59 | + $wreq.Referer = strip_filename $url |
| 60 | + if ($cookies) { |
| 61 | + $wreq.Headers.Add('Cookie', (cookie_header $cookies)) |
50 | 62 | }
|
51 | 63 | }
|
52 | 64 | $wres = $null
|
53 | 65 | try {
|
54 |
| - $wres = $wreq.getresponse() |
55 |
| - return $url, $wres.statuscode, $null |
| 66 | + $wres = $wreq.GetResponse() |
| 67 | + |
| 68 | + return $url, $wres.StatusCode, $null |
56 | 69 | } catch {
|
57 |
| - $e = $_.exception |
58 |
| - if($e.innerexception) { $e = $e.innerexception } |
59 |
| - return $url, "Error", $e.message |
| 70 | + $e = $_.Exception |
| 71 | + if ($e.InnerException) { $e = $e.InnerException } |
| 72 | + |
| 73 | + return $url, 'Error', $e.Message |
60 | 74 | } finally {
|
61 |
| - if($null -ne $wres -and $wres -isnot [net.ftpwebresponse]) { |
62 |
| - $wres.close() |
| 75 | + if ($null -ne $wres -and $wres -isnot [Net.FtpWebResponse]) { |
| 76 | + $wres.Close() |
63 | 77 | }
|
64 | 78 | }
|
65 | 79 | }
|
66 | 80 |
|
67 |
| -$queue | ForEach-Object { |
68 |
| - $name, $manifest = $_ |
| 81 | +foreach ($man in $Queue) { |
| 82 | + $name, $manifest = $man |
69 | 83 | $urls = @()
|
70 | 84 | $ok = 0
|
71 | 85 | $failed = 0
|
72 | 86 | $errors = @()
|
73 | 87 |
|
74 |
| - if($manifest.url) { |
| 88 | + if ($manifest.url) { |
75 | 89 | $manifest.url | ForEach-Object { $urls += $_ }
|
76 | 90 | } else {
|
77 |
| - url $manifest "64bit" | ForEach-Object { $urls += $_ } |
78 |
| - url $manifest "32bit" | ForEach-Object { $urls += $_ } |
| 91 | + url $manifest '64bit' | ForEach-Object { $urls += $_ } |
| 92 | + url $manifest '32bit' | ForEach-Object { $urls += $_ } |
79 | 93 | }
|
80 | 94 |
|
81 | 95 | $urls | ForEach-Object {
|
82 | 96 | $url, $status, $msg = test_dl $_ $manifest.cookie
|
83 |
| - if($msg) { $errors += "$msg ($url)" } |
84 |
| - if($status -eq "OK" -or $status -eq "OpeningData") { $ok += 1 } else { $failed += 1 } |
| 97 | + if ($msg) { $errors += "$msg ($url)" } |
| 98 | + if ($status -eq 'OK' -or $status -eq 'OpeningData') { $ok += 1 } else { $failed += 1 } |
85 | 99 | }
|
86 | 100 |
|
87 |
| - write-host "[" -nonewline |
88 |
| - write-host -f cyan -nonewline $urls.length |
89 |
| - write-host "]" -nonewline |
| 101 | + if (($ok -eq $urls.Length) -and $SkipValid) { continue } |
| 102 | + |
| 103 | + # URLS |
| 104 | + Write-Host '[' -NoNewLine |
| 105 | + Write-Host $urls.Length -NoNewLine -ForegroundColor Cyan |
| 106 | + Write-Host ']' -NoNewLine |
90 | 107 |
|
91 |
| - write-host "[" -nonewline |
92 |
| - if($ok -eq $urls.length) { |
93 |
| - write-host -f green -nonewline $ok |
94 |
| - } elseif($ok -eq 0) { |
95 |
| - write-host -f red -nonewline $ok |
| 108 | + # Okay |
| 109 | + Write-Host '[' -NoNewLine |
| 110 | + if ($ok -eq $urls.Length) { |
| 111 | + Write-Host $ok -NoNewLine -ForegroundColor Green |
| 112 | + } elseif ($ok -eq 0) { |
| 113 | + Write-Host $ok -NoNewLine -ForegroundColor Red |
96 | 114 | } else {
|
97 |
| - write-host -f yellow -nonewline $ok |
| 115 | + Write-Host $ok -NoNewLine -ForegroundColor Yellow |
98 | 116 | }
|
99 |
| - write-host "]" -nonewline |
| 117 | + Write-Host ']' -NoNewLine |
100 | 118 |
|
101 |
| - write-host "[" -nonewline |
102 |
| - if($failed -eq 0) { |
103 |
| - write-host -f green -nonewline $failed |
| 119 | + # Failed |
| 120 | + Write-Host '[' -NoNewLine |
| 121 | + if ($failed -eq 0) { |
| 122 | + Write-Host $failed -NoNewLine -ForegroundColor Green |
104 | 123 | } else {
|
105 |
| - write-host -f red -nonewline $failed |
| 124 | + Write-Host $failed -NoNewLine -ForegroundColor Red |
106 | 125 | }
|
107 |
| - write-host "] " -nonewline |
108 |
| - write-host (strip_ext $name) |
| 126 | + Write-Host '] ' -NoNewLine |
| 127 | + Write-Host (strip_ext $name) |
109 | 128 |
|
110 | 129 | $errors | ForEach-Object {
|
111 |
| - write-host -f darkred " > $_" |
| 130 | + Write-Host " > $_" -ForegroundColor DarkRed |
112 | 131 | }
|
113 | 132 | }
|
114 | 133 |
|
115 |
| - |
116 | 134 | set_https_protocols $original
|
0 commit comments