From 63b91efe39a34c6428560cbf7bc069ac9e09e28a Mon Sep 17 00:00:00 2001 From: pizzaboxer Date: Thu, 31 Aug 2023 10:26:05 +0100 Subject: [PATCH] debug packages not downloading properly over http --- Bloxstrap/Bootstrapper.cs | 14 ++++++++------ Bloxstrap/Exceptions/ChecksumFailedException.cs | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 6 deletions(-) create mode 100644 Bloxstrap/Exceptions/ChecksumFailedException.cs diff --git a/Bloxstrap/Bootstrapper.cs b/Bloxstrap/Bootstrapper.cs index c0174b1..5628454 100644 --- a/Bloxstrap/Bootstrapper.cs +++ b/Bloxstrap/Bootstrapper.cs @@ -1365,9 +1365,11 @@ namespace Bloxstrap _totalDownloadedBytes += bytesRead; UpdateProgressBar(); } - - if (MD5Hash.FromStream(fileStream) != package.Signature) - throw new Exception("Signature does not match!"); + + string hash = MD5Hash.FromStream(fileStream); + + if (hash != package.Signature) + throw new ChecksumFailedException($"Failed to verify download of {packageUrl}\n\nGot signature: {hash}\n\nPackage has been downloaded to {packageLocation}\n\nPlease send the file shown above in a bug report."); App.Logger.WriteLine(LOG_IDENT, $"Finished downloading! ({totalBytesRead} bytes total)"); break; @@ -1377,12 +1379,12 @@ namespace Bloxstrap App.Logger.WriteLine(LOG_IDENT, $"An exception occurred after downloading {totalBytesRead} bytes. ({i}/{maxTries})"); App.Logger.WriteException(LOG_IDENT, ex); + if (i >= maxTries || ex.GetType() == typeof(ChecksumFailedException)) + throw; + if (File.Exists(packageLocation)) File.Delete(packageLocation); - if (i >= maxTries) - throw; - _totalDownloadedBytes -= totalBytesRead; UpdateProgressBar(); diff --git a/Bloxstrap/Exceptions/ChecksumFailedException.cs b/Bloxstrap/Exceptions/ChecksumFailedException.cs new file mode 100644 index 0000000..95d8af2 --- /dev/null +++ b/Bloxstrap/Exceptions/ChecksumFailedException.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Bloxstrap.Exceptions +{ + internal class ChecksumFailedException : Exception + { + public ChecksumFailedException(string message) : base(message) + { + } + } +}