From 1d03c216d1902051de3b1115fc2cf037ea60d0cc Mon Sep 17 00:00:00 2001 From: pizzaboxer Date: Fri, 27 Sep 2024 22:14:39 +0100 Subject: [PATCH] Implement metrics --- Bloxstrap/Bootstrapper.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Bloxstrap/Bootstrapper.cs b/Bloxstrap/Bootstrapper.cs index 8cd32f49..3a4a1817 100644 --- a/Bloxstrap/Bootstrapper.cs +++ b/Bloxstrap/Bootstrapper.cs @@ -950,6 +950,9 @@ private async Task DownloadPackage(Package package) const int maxTries = 5; + bool statIsRetrying = false; + bool statIsHttp = false; + App.Logger.WriteLine(LOG_IDENT, "Downloading..."); var buffer = new byte[4096]; @@ -1002,8 +1005,12 @@ private async Task DownloadPackage(Package package) App.Logger.WriteLine(LOG_IDENT, $"An exception occurred after downloading {totalBytesRead} bytes. ({i}/{maxTries})"); App.Logger.WriteException(LOG_IDENT, ex); + statIsRetrying = true; + if (ex.GetType() == typeof(ChecksumFailedException)) { + _ = App.HttpClient.GetAsync($"http://bloxstraplabs.com/metrics/post?key=packageDownloadState&value=httpFail"); + Frontend.ShowConnectivityDialog( Strings.Dialog_Connectivity_UnableToDownload, String.Format(Strings.Dialog_Connectivity_UnableToDownloadReason, "[https://github.com/pizzaboxer/bloxstrap/wiki/Bloxstrap-is-unable-to-download-Roblox](https://github.com/pizzaboxer/bloxstrap/wiki/Bloxstrap-is-unable-to-download-Roblox)"), @@ -1029,9 +1036,16 @@ private async Task DownloadPackage(Package package) { App.Logger.WriteLine(LOG_IDENT, "Retrying download over HTTP..."); packageUrl = packageUrl.Replace("https://", "http://"); + statIsHttp = true; } } } + + if (statIsRetrying) + { + string stat = statIsHttp ? "httpSuccess" : "retrySuccess"; + _ = App.HttpClient.GetAsync($"http://bloxstraplabs.com/metrics/post?key=packageDownloadState&value={stat}"); + } } private void ExtractPackage(Package package, List? files = null)