From 33353f5fad4a67458f88c414070a3c4fe4fd42a9 Mon Sep 17 00:00:00 2001 From: CartBlanche Date: Thu, 27 Jun 2024 23:00:26 +0100 Subject: [PATCH] Refactor for Windows installation. --- Source/v2/Meadow.Dfu/DfuUtils.cs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/Source/v2/Meadow.Dfu/DfuUtils.cs b/Source/v2/Meadow.Dfu/DfuUtils.cs index ac32a66d..c4fd80ba 100644 --- a/Source/v2/Meadow.Dfu/DfuUtils.cs +++ b/Source/v2/Meadow.Dfu/DfuUtils.cs @@ -19,8 +19,9 @@ public static class DfuUtils { private static readonly int _osAddress = 0x08000000; - private const string DFU_UTIL_AMD64_URL = "http://ftp.de.debian.org/debian/pool/main/d/dfu-util/dfu-util_0.11-1_amd64.deb"; - private const string DFU_UTIL_ARM64_URL = "http://ftp.de.debian.org/debian/pool/main/d/dfu-util/dfu-util_0.11-1_arm64.deb"; + private const string DFU_UTIL_UBUNTU_AMD64_URL = "http://ftp.de.debian.org/debian/pool/main/d/dfu-util/dfu-util_0.11-1_amd64.deb"; + private const string DFU_UTIL_UBUNTU_ARM64_URL = "http://ftp.de.debian.org/debian/pool/main/d/dfu-util/dfu-util_0.11-1_arm64.deb"; + private const string DFU_UTIL_WINDOWS_URL = $"https://s3-us-west-2.amazonaws.com/downloads.wildernesslabs.co/public/dfu-util-{DEFAULT_DFU_VERSION}-binaries.zip"; private const string DFU_UTIL = "dfu-util"; public const string DEFAULT_DFU_VERSION = "0.11"; @@ -240,14 +241,12 @@ private static async Task InstallDfuUtilOnWindows(string tempFolder, strin Directory.CreateDirectory(tempFolder); - var downloadUrl = $"https://s3-us-west-2.amazonaws.com/downloads.wildernesslabs.co/public/dfu-util-{dfuUtilVersion}-binaries.zip"; - - var downloadedFileName = downloadUrl.Substring(downloadUrl.LastIndexOf("/", StringComparison.Ordinal) + 1); - - await DownloadFile(downloadUrl, downloadedFileName, cancellationToken); + var downloadedFileName = Path.GetFileName(new Uri(DFU_UTIL_WINDOWS_URL).LocalPath); + var downloadedFilePath = Path.Combine(tempFolder, downloadedFileName); + await DownloadFile(DFU_UTIL_WINDOWS_URL, downloadedFilePath, cancellationToken); ZipFile.ExtractToDirectory( - Path.Combine(tempFolder, downloadedFileName), + downloadedFilePath, tempFolder); var is64Bit = Environment.Is64BitOperatingSystem; @@ -452,8 +451,8 @@ private static async Task InstallPackageOnLinux(string package) { var dfuPackageUrl = RuntimeInformation.OSArchitecture switch { - Architecture.Arm64 => DFU_UTIL_ARM64_URL, - Architecture.X64 => DFU_UTIL_AMD64_URL, + Architecture.Arm64 => DFU_UTIL_UBUNTU_ARM64_URL, + Architecture.X64 => DFU_UTIL_UBUNTU_AMD64_URL, _ => throw new PlatformNotSupportedException("Unsupported architecture") }; var fileName = Path.GetFileName(new Uri(dfuPackageUrl).LocalPath);