Skip to content

Commit

Permalink
Improve error handling
Browse files Browse the repository at this point in the history
* Simplify regex and fix unconverted characters.
* Also use Start-BitsTransfer for cmdline downloads (Closes #56).
* Also remove -DisableProgress now that we use Start-BitsTransfer.
  • Loading branch information
pbatard committed Feb 6, 2023
1 parent 4b24ae5 commit 10acbf9
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 41 deletions.
5 changes: 3 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
root = true

[*]
trim_trailing_whitespace = true
insert_final_newline = true
# Must use a BOM else Unicode strings will not display
charset = utf-8-bom
insert_final_newline = true
indent_style = space
trim_trailing_whitespace = true
69 changes: 31 additions & 38 deletions Fido.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Fido v1.42 - Feature ISO Downloader, for retail Windows images and UEFI Shell
# Fido v1.43 - Feature ISO Downloader, for retail Windows images and UEFI Shell
# Copyright © 2019-2023 Pete Batard <pete@akeo.ie>
# Command line support: Copyright © 2021 flx5
# ConvertTo-ImageSource: Copyright © 2016 Chris Carter
Expand Down Expand Up @@ -45,9 +45,7 @@ param(
# (Optional) Only display the download URL [Toggles commandline mode]
[switch]$GetUrl = $False,
# (Optional) Increase verbosity
[switch]$Verbose = $False,
# (Optional) Disable the progress bar
[switch]$DisableProgress = $False
[switch]$Verbose = $False
)
#endregion

Expand Down Expand Up @@ -830,13 +828,11 @@ function Get-Windows-Download-Links([int]$SelectedVersion, [int]$SelectedRelease
$ref = "https://www.microsoft.com/software-download/windows11"
$r = Invoke-WebRequest -Method Post -Headers @{ "Referer" = $ref } -UseBasicParsing -UserAgent $UserAgent -WebSession $Session $url
if ($r -match "errorModalMessage") {
$regex = New-Object Text.RegularExpressions.Regex '<p id="errorModalMessage">(.+?)<\/p>'
$m = $regex.Match($r)
# Make the typical error message returned by Microsoft's servers more presentable
$Alt = $m.Groups[1] -replace "<[^>]+>" -replace "\s+", " "
$Alt += " " + $SessionId + "."
$Alt = [regex]::Match($r, '<p id="errorModalMessage">(.+?)<\/p>').Groups[1].Value -replace "<[^>]+>" -replace "\s+", " " -replace "\?\?\?", "-"
if (-not $Alt) {
$Alt = "Could not retrieve architectures from server"
} else {
$Alt += " " + $SessionId + "."
}
Throw-Error -Req $r -Alt $Alt
}
Expand Down Expand Up @@ -886,10 +882,7 @@ function Process-Download-Link([string]$Url)
$tmp_size = [uint64]::Parse($str_size)
$Size = Size-To-Human-Readable $tmp_size
Write-Host "Downloading '$File' ($Size)..."
if ($DisableProgress) {
$ProgressPreference = 'SilentlyContinue'
}
Invoke-WebRequest -UseBasicParsing -Uri $Url -OutFile $File
Start-BitsTransfer -Source $Url -Destination $File
} else {
Write-Host Download Link: $Url
Start-Process -FilePath $Url
Expand Down Expand Up @@ -1218,8 +1211,8 @@ exit $ExitCode
# SIG # Begin signature block
# MIIkWAYJKoZIhvcNAQcCoIIkSTCCJEUCAQExDzANBglghkgBZQMEAgEFADB5Bgor
# BgEEAYI3AgEEoGswaTA0BgorBgEEAYI3AgEeMCYCAwEAAAQQH8w7YFlLCE63JNLG
# KX7zUQIBAAIBAAIBAAIBAAIBADAxMA0GCWCGSAFlAwQCAQUABCDa8PrIe1NSjXqW
# rwtj7a1ha0/FMIwXSDFruNwgp2G8haCCElkwggVvMIIEV6ADAgECAhBI/JO0YFWU
# KX7zUQIBAAIBAAIBAAIBAAIBADAxMA0GCWCGSAFlAwQCAQUABCAin+3j4moQLVFU
# tqR8rGAmmgj13m89LOKayGbAncwfZqCCElkwggVvMIIEV6ADAgECAhBI/JO0YFWU
# jTanyYqJ1pQWMA0GCSqGSIb3DQEBDAUAMHsxCzAJBgNVBAYTAkdCMRswGQYDVQQI
# DBJHcmVhdGVyIE1hbmNoZXN0ZXIxEDAOBgNVBAcMB1NhbGZvcmQxGjAYBgNVBAoM
# EUNvbW9kbyBDQSBMaW1pdGVkMSEwHwYDVQQDDBhBQUEgQ2VydGlmaWNhdGUgU2Vy
Expand Down Expand Up @@ -1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ZOD0JIRVp3RpZ9Q+Qlu34qc=
# DQEJAzENBgsqhkiG9w0BCRABBDAcBgkqhkiG9w0BCQUxDxcNMjMwMjA2MDExOTI0
# WjAvBgkqhkiG9w0BCQQxIgQgLweTPLKPtanJVxxrIuCqGzru3xtAintj/2W8Y+R8
# nXwwNwYLKoZIhvcNAQkQAi8xKDAmMCQwIgQgxHTOdgB9AjlODaXk3nwUxoD54oIB
# PP72U+9dtx/fYfgwCwYJKoZIhvcNAQEBBIIBAE4XHtLfg6sAuof9wFzniSPNmYks
# BPkufnx3wPWvzQECIQ1cmfDDHh8TjPENpMpmosJz6WVtAOjlVlrgFfT/A/5J8fh5
# vj7vdDHhkW+PozQyKJI2UROJrFyo1ZbD8fHIgBGalHT9PD+/BoN3yps6vLvgVUWX
# +mMdH7g1gwcHvmLl2ocmPANNR7gfdw/8BUtLlnK5Jgta3DANEh/A7Wedo1Gt4ctN
# NVC2g3Vs1BhyF8EJj274wtQuSC/9Q9SoBQhrnBYD/pElwOkFCQB+VFAP0TOnyqvS
# YO9QM5G3Xd31TRkW9i83G1SNMhKf0du/voqtplcIEMqXfYGdagtzY+qSf1c=
# SIG # End signature block
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ The options are:
architecture as the one from the current system.
- `GetUrl`: By default, the script attempts to automatically launch the download. But when using the `-GetUrl` switch,
the script only displays the download URL, which can then be piped into another command or into a file.
- `DisableProgress`: Disable progress report. This may speed up downloads when using the command line.

Examples of a commandline download:

Expand Down

0 comments on commit 10acbf9

Please sign in to comment.