From 9d3b663c9455a9270c846cb20217ff08469a42b4 Mon Sep 17 00:00:00 2001 From: Tom Pittenger Date: Tue, 25 Apr 2023 08:16:14 -0700 Subject: [PATCH] fix unhandled crash while checking for FW update at boot without internet available --- ExtLibs/ArduPilot/APFirmware.cs | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/ExtLibs/ArduPilot/APFirmware.cs b/ExtLibs/ArduPilot/APFirmware.cs index 27d42c07e4..54f132f5da 100644 --- a/ExtLibs/ArduPilot/APFirmware.cs +++ b/ExtLibs/ArduPilot/APFirmware.cs @@ -104,24 +104,31 @@ public static void GetList(string url = "https://firmware.ardupilot.org/manifest if (force == false && Manifest != null) return; - log.Info(url); + try + { + log.Info(url); - var client = new HttpClient(); + var client = new HttpClient(); - if (!String.IsNullOrEmpty(Settings.Instance.UserAgent)) - client.DefaultRequestHeaders.Add("User-Agent", Settings.Instance.UserAgent); + if (!String.IsNullOrEmpty(Settings.Instance.UserAgent)) + client.DefaultRequestHeaders.Add("User-Agent", Settings.Instance.UserAgent); - var manifestgz = client.GetByteArrayAsync(url).GetAwaiter().GetResult(); - var mssrc = new MemoryStream(manifestgz); - var msdest = new MemoryStream(); - GZipStream gz = new GZipStream(mssrc, CompressionMode.Decompress); - gz.CopyTo(msdest); - msdest.Position = 0; - var manifest = new StreamReader(msdest).ReadToEnd(); + var manifestgz = client.GetByteArrayAsync(url).GetAwaiter().GetResult(); + var mssrc = new MemoryStream(manifestgz); + var msdest = new MemoryStream(); + GZipStream gz = new GZipStream(mssrc, CompressionMode.Decompress); + gz.CopyTo(msdest); + msdest.Position = 0; + var manifest = new StreamReader(msdest).ReadToEnd(); - Manifest = JsonConvert.DeserializeObject(manifest); + Manifest = JsonConvert.DeserializeObject(manifest); - log.Info(Manifest.Firmware?.Length); + log.Info(Manifest.Firmware?.Length); + } + catch (Exception ex) + { + log.Error(ex); + } } }