Skip to content

Commit

Permalink
fix unhandled crash while checking for FW update at boot without inte…
Browse files Browse the repository at this point in the history
…rnet available
  • Loading branch information
magicrub authored and meee1 committed Apr 25, 2023
1 parent 4e845cd commit 9d3b663
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions ExtLibs/ArduPilot/APFirmware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ManifestRoot>(manifest);
Manifest = JsonConvert.DeserializeObject<ManifestRoot>(manifest);

log.Info(Manifest.Firmware?.Length);
log.Info(Manifest.Firmware?.Length);
}
catch (Exception ex)
{
log.Error(ex);
}
}
}

Expand Down

0 comments on commit 9d3b663

Please sign in to comment.