From 71fe7649aacd630bac1dbc87cdc260f63cf44742 Mon Sep 17 00:00:00 2001 From: Dominique Louis Date: Mon, 25 Sep 2023 09:21:06 +0100 Subject: [PATCH] Do some decent version comparisons. (#351) * Fix 350, by doing some decent version comparisons. * Only accept --verbose to change loglevel. * Bump version to 1.3.4 --- .github/workflows/dotnet.yml | 6 +++--- Meadow.CLI.Core/Constants.cs | 2 +- Meadow.CLI.Core/Internals/Dfu/DfuUtils.cs | 15 +++++++-------- Meadow.CLI.Core/Managers/DownloadManager.cs | 2 +- Meadow.CLI.Core/Meadow.CLI.Core.6.0.0.csproj | 2 +- Meadow.CLI.Core/Meadow.CLI.Core.Classic.csproj | 2 +- Meadow.CLI.Core/Meadow.CLI.Core.VS2019.csproj | 2 +- Meadow.CLI.Core/Meadow.CLI.Core.csproj | 2 +- Meadow.CLI/Meadow.CLI.Classic.csproj | 2 +- Meadow.CLI/Meadow.CLI.csproj | 2 +- Meadow.CLI/Program.cs | 9 ++------- 11 files changed, 20 insertions(+), 26 deletions(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 33b7b870..20e01a35 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -1,8 +1,8 @@ name: Meadow.CLI env: - CLI_RELEASE_VERSION: 1.3.0.0 - IDE_TOOLS_RELEASE_VERSION: 1.3.0 - MEADOW_OS_VERSION: 1.3.0.0 + CLI_RELEASE_VERSION: 1.3.4.0 + IDE_TOOLS_RELEASE_VERSION: 1.3.4 + MEADOW_OS_VERSION: 1.3.4.0 VS_MAC_2019_VERSION: 8.10 VS_MAC_2022_VERSION: 17.5 diff --git a/Meadow.CLI.Core/Constants.cs b/Meadow.CLI.Core/Constants.cs index 05ebe39c..e73b68c9 100644 --- a/Meadow.CLI.Core/Constants.cs +++ b/Meadow.CLI.Core/Constants.cs @@ -7,7 +7,7 @@ namespace Meadow.CLI.Core { public static class Constants { - public const string CLI_VERSION = "1.3.0.0"; + public const string CLI_VERSION = "1.3.4.0"; public const ushort HCOM_PROTOCOL_PREVIOUS_VERSION_NUMBER = 0x0006; public const ushort HCOM_PROTOCOL_CURRENT_VERSION_NUMBER = 0x0007; // Used for transmission public const string WILDERNESS_LABS_USB_VID = "2E6A"; diff --git a/Meadow.CLI.Core/Internals/Dfu/DfuUtils.cs b/Meadow.CLI.Core/Internals/Dfu/DfuUtils.cs index f34b60f1..a044e052 100644 --- a/Meadow.CLI.Core/Internals/Dfu/DfuUtils.cs +++ b/Meadow.CLI.Core/Internals/Dfu/DfuUtils.cs @@ -221,10 +221,10 @@ public static async Task FlashFile(string fileName, IUsbDevice? device = n LastSerialNumber = GetDeviceSerial(device); - var dfuUtilVersion = GetDfuUtilVersion(); + var dfuUtilVersion = new System.Version(GetDfuUtilVersion()); logger.LogDebug("Detected OS: {os}", RuntimeInformation.OSDescription); - if (string.IsNullOrEmpty(dfuUtilVersion)) + if (dfuUtilVersion == null) { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { @@ -236,24 +236,23 @@ public static async Task FlashFile(string fileName, IUsbDevice? device = n } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { - logger.LogError("dfu-util not found - install using package manager, for example: `apt install dfu-util`"); + logger.LogError("dfu-util not found - install using package manager, for example: `apt install dfu-util` or the equivalent for your Linux distribution"); } return false; } - else if (dfuUtilVersion != "0.10") + else if (dfuUtilVersion.CompareTo(new System.Version("0.11")) < 0) { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { - logger.LogError("dfu-util update required. To install, run in administrator mode: meadow install dfu-util"); + logger.LogError("dfu-util update required. To update, run in administrator mode: `meadow install dfu-util`"); } else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { - logger.LogError("dfu-util update required. To install, run: brew upgrade dfu-util"); + logger.LogError("dfu-util update required. To update, run: `brew upgrade dfu-util`"); } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { - if (dfuUtilVersion != "0.9") - return false; + logger.LogError("dfu-util update required. To update , run: `apt upgrade dfu-util` or the equivalent for your Linux distribution"); } else { diff --git a/Meadow.CLI.Core/Managers/DownloadManager.cs b/Meadow.CLI.Core/Managers/DownloadManager.cs index cd461436..12b87399 100644 --- a/Meadow.CLI.Core/Managers/DownloadManager.cs +++ b/Meadow.CLI.Core/Managers/DownloadManager.cs @@ -206,7 +206,7 @@ public async Task InstallDfuUtil(bool is64Bit = true, Directory.CreateDirectory(WildernessLabsTemp); - const string downloadUrl = "https://s3-us-west-2.amazonaws.com/downloads.wildernesslabs.co/public/dfu-util-0.10-binaries.zip"; + const string downloadUrl = "https://s3-us-west-2.amazonaws.com/downloads.wildernesslabs.co/public/dfu-util-0.11-binaries.zip"; var downloadFileName = downloadUrl.Substring(downloadUrl.LastIndexOf("/", StringComparison.Ordinal) + 1); var response = await Client.GetAsync(downloadUrl, HttpCompletionOption.ResponseHeadersRead, cancellationToken); diff --git a/Meadow.CLI.Core/Meadow.CLI.Core.6.0.0.csproj b/Meadow.CLI.Core/Meadow.CLI.Core.6.0.0.csproj index 127418eb..4dda5118 100644 --- a/Meadow.CLI.Core/Meadow.CLI.Core.6.0.0.csproj +++ b/Meadow.CLI.Core/Meadow.CLI.Core.6.0.0.csproj @@ -11,7 +11,7 @@ preview enable True - 1.3.0.0 + 1.3.4.0 diff --git a/Meadow.CLI.Core/Meadow.CLI.Core.Classic.csproj b/Meadow.CLI.Core/Meadow.CLI.Core.Classic.csproj index ddef270a..0153ff5b 100644 --- a/Meadow.CLI.Core/Meadow.CLI.Core.Classic.csproj +++ b/Meadow.CLI.Core/Meadow.CLI.Core.Classic.csproj @@ -11,7 +11,7 @@ preview enable True - 1.3.0.0 + 1.3.4.0 diff --git a/Meadow.CLI.Core/Meadow.CLI.Core.VS2019.csproj b/Meadow.CLI.Core/Meadow.CLI.Core.VS2019.csproj index a69b2d56..713335ee 100644 --- a/Meadow.CLI.Core/Meadow.CLI.Core.VS2019.csproj +++ b/Meadow.CLI.Core/Meadow.CLI.Core.VS2019.csproj @@ -11,7 +11,7 @@ preview enable True - 1.3.0.0 + 1.3.4.0 diff --git a/Meadow.CLI.Core/Meadow.CLI.Core.csproj b/Meadow.CLI.Core/Meadow.CLI.Core.csproj index 31d043ff..c398f76c 100644 --- a/Meadow.CLI.Core/Meadow.CLI.Core.csproj +++ b/Meadow.CLI.Core/Meadow.CLI.Core.csproj @@ -11,7 +11,7 @@ preview enable True - 1.3.0.0 + 1.3.4.0 diff --git a/Meadow.CLI/Meadow.CLI.Classic.csproj b/Meadow.CLI/Meadow.CLI.Classic.csproj index eba00955..5249513f 100644 --- a/Meadow.CLI/Meadow.CLI.Classic.csproj +++ b/Meadow.CLI/Meadow.CLI.Classic.csproj @@ -10,7 +10,7 @@ Peter Moody, Adrian Stevens, Brian Kim, Pete Garafano, Dominique Louis Wilderness Labs, Inc true - 1.3.0.0 + 1.3.4.0 AnyCPU http://developer.wildernesslabs.co/Meadow/Meadow.Foundation/ icon.png diff --git a/Meadow.CLI/Meadow.CLI.csproj b/Meadow.CLI/Meadow.CLI.csproj index be3142d6..89a10bee 100644 --- a/Meadow.CLI/Meadow.CLI.csproj +++ b/Meadow.CLI/Meadow.CLI.csproj @@ -10,7 +10,7 @@ Peter Moody, Adrian Stevens, Brian Kim, Pete Garafano, Dominique Louis Wilderness Labs, Inc true - 1.3.0.0 + 1.3.4.0 AnyCPU http://developer.wildernesslabs.co/Meadow/Meadow.Foundation/ icon.png diff --git a/Meadow.CLI/Program.cs b/Meadow.CLI/Program.cs index 47c54e58..b0250e21 100644 --- a/Meadow.CLI/Program.cs +++ b/Meadow.CLI/Program.cs @@ -26,14 +26,9 @@ public static async Task Main(string[] args) .Build(); var logLevel = LogEventLevel.Information; - var logModifier = args.FirstOrDefault(a => a.Equals("-m")) - ?.Count(x => x == 'm') ?? 0; - logLevel -= logModifier; - if (logLevel < 0) - { - logLevel = 0; - } + if (args.Contains("--verbose")) + logLevel = LogEventLevel.Verbose; var outputTemplate = logLevel == LogEventLevel.Verbose ? "[{Timestamp:HH:mm:ss.fff} {Level:u3}] {Message:lj}{NewLine}{Exception}"