diff --git a/nanoFirmwareFlasher.Library/CC13x26x2Firmware.cs b/nanoFirmwareFlasher.Library/CC13x26x2Firmware.cs index 6d2dd3a5..6ebb4039 100644 --- a/nanoFirmwareFlasher.Library/CC13x26x2Firmware.cs +++ b/nanoFirmwareFlasher.Library/CC13x26x2Firmware.cs @@ -3,9 +3,6 @@ // See LICENSE file in the project root for full license information. // -using System.IO; -using System.Linq; - namespace nanoFramework.Tools.FirmwareFlasher { /// diff --git a/nanoFirmwareFlasher.Library/CC13x26x2Operations.cs b/nanoFirmwareFlasher.Library/CC13x26x2Operations.cs index af200876..25166d09 100644 --- a/nanoFirmwareFlasher.Library/CC13x26x2Operations.cs +++ b/nanoFirmwareFlasher.Library/CC13x26x2Operations.cs @@ -7,7 +7,6 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; -using System.Linq; namespace nanoFramework.Tools.FirmwareFlasher { @@ -119,7 +118,7 @@ public static async System.Threading.Tasks.Task UpdateFirmwareAsync( ExitCodes programResult = ExitCodes.OK; // write HEX files to flash - if (filesToFlash.Any(f => f.EndsWith(".hex"))) + if (filesToFlash.Exists(f => f.EndsWith(".hex"))) { programResult = ccDevice.FlashHexFiles(filesToFlash); } @@ -127,7 +126,7 @@ public static async System.Threading.Tasks.Task UpdateFirmwareAsync( if (programResult == ExitCodes.OK && isApplicationBinFile) { // now program the application file - programResult = ccDevice.FlashBinFiles(new[] { applicationPath }, new[] { deploymentAddress }); + programResult = ccDevice.FlashBinFiles([applicationPath], [deploymentAddress]); } if (updateFw) diff --git a/nanoFirmwareFlasher.Library/Esp32Firmware.cs b/nanoFirmwareFlasher.Library/Esp32Firmware.cs index 92526290..f64aa933 100644 --- a/nanoFirmwareFlasher.Library/Esp32Firmware.cs +++ b/nanoFirmwareFlasher.Library/Esp32Firmware.cs @@ -24,7 +24,7 @@ internal class Esp32Firmware : FirmwarePackage /// /// ESP32 nanoCLR is available for 2MB, 4MB, 8MB and 16MB flash sizes /// - private List SupportedFlashSizes => new() { 0x200000, 0x400000, 0x800000, 0x1000000 }; + private List SupportedFlashSizes => [0x200000, 0x400000, 0x800000, 0x1000000]; internal string BootloaderPath; diff --git a/nanoFirmwareFlasher.Library/Esp32Operations.cs b/nanoFirmwareFlasher.Library/Esp32Operations.cs index 3a6bdf51..2aeb693e 100644 --- a/nanoFirmwareFlasher.Library/Esp32Operations.cs +++ b/nanoFirmwareFlasher.Library/Esp32Operations.cs @@ -504,7 +504,7 @@ public static async System.Threading.Tasks.Task UpdateFirmwareAsync( int configPartitionAddress = 0; int configPartitionSize = 0; - string configPartitionBackup = Path.GetTempFileName(); + string configPartitionBackup = Path.GetRandomFileName(); // if mass erase wasn't requested, backup config partitition if (!massErase) @@ -613,7 +613,6 @@ public static async System.Threading.Tasks.Task DeployApplicationAsyn VerbosityLevel verbosity, PartitionTableSize? partitionTableSize) { - var operationResult = ExitCodes.OK; uint address = 0; // perform sanity checks for the specified target against the connected device details @@ -688,7 +687,7 @@ public static async System.Threading.Tasks.Task DeployApplicationAsyn } // write to flash - operationResult = espTool.WriteFlash(firmware.FlashPartitions); + ExitCodes operationResult = espTool.WriteFlash(firmware.FlashPartitions); if (operationResult == ExitCodes.OK) { diff --git a/nanoFirmwareFlasher.Library/FileDeployment/FileDeploymentManager.cs b/nanoFirmwareFlasher.Library/FileDeployment/FileDeploymentManager.cs index d16b6424..2936db3e 100644 --- a/nanoFirmwareFlasher.Library/FileDeployment/FileDeploymentManager.cs +++ b/nanoFirmwareFlasher.Library/FileDeployment/FileDeploymentManager.cs @@ -1,12 +1,13 @@ -using nanoFramework.Tools.Debugger; +// +// Copyright (c) .NET Foundation and Contributors +// See LICENSE file in the project root for full license information. +// + +using nanoFramework.Tools.Debugger; using nanoFramework.Tools.Debugger.Extensions; using Newtonsoft.Json; using System; -using System.Collections.Generic; using System.IO; -using System.Linq; -using System.Runtime; -using System.Text; using System.Threading.Tasks; namespace nanoFramework.Tools.FirmwareFlasher.FileDeployment @@ -16,9 +17,9 @@ namespace nanoFramework.Tools.FirmwareFlasher.FileDeployment /// public class FileDeploymentManager { - private FileDeploymentConfiguration _configuration; - private VerbosityLevel _verbosity; - private string _serialPort; + private readonly FileDeploymentConfiguration _configuration; + private readonly VerbosityLevel _verbosity; + private readonly string _serialPort; /// /// Creates an instance of FileDeploymentManager. diff --git a/nanoFirmwareFlasher.Library/FirmwarePackage.cs b/nanoFirmwareFlasher.Library/FirmwarePackage.cs index 02713097..8f1bf341 100644 --- a/nanoFirmwareFlasher.Library/FirmwarePackage.cs +++ b/nanoFirmwareFlasher.Library/FirmwarePackage.cs @@ -158,7 +158,7 @@ public static List GetTargetList( // Because new stable releases are published on a regular basis and preview very rarely, we query for stable versions published in past month and preview versions published during the past 6 months. string requestUri = $"{repoName}/?page_size=500&q=uploaded:'>{(preview ? "6" : "1")} month ago' {(platform.HasValue ? "AND tag:" + platform.Value : "")}"; - List targetPackages = new(); + List targetPackages = []; if (verbosity > VerbosityLevel.Normal) { @@ -246,7 +246,7 @@ internal async Task DownloadAndExtractAsync() return ExitCodes.E9006; } - List fwFiles = new(); + List fwFiles = []; if (_preview) { diff --git a/nanoFirmwareFlasher.Library/JLinkDevice.cs b/nanoFirmwareFlasher.Library/JLinkDevice.cs index 5cf4dfee..35d26f25 100644 --- a/nanoFirmwareFlasher.Library/JLinkDevice.cs +++ b/nanoFirmwareFlasher.Library/JLinkDevice.cs @@ -151,7 +151,7 @@ public static List ListDevices() if (jlinkMatches.Count == 0) { // no J-Link probe found - return new List(); + return []; } return jlinkMatches.Cast().Select(i => i.Value).ToList(); diff --git a/nanoFirmwareFlasher.Library/JLinkOperations.cs b/nanoFirmwareFlasher.Library/JLinkOperations.cs index 5f1cdb02..eba76718 100644 --- a/nanoFirmwareFlasher.Library/JLinkOperations.cs +++ b/nanoFirmwareFlasher.Library/JLinkOperations.cs @@ -69,7 +69,7 @@ public static async System.Threading.Tasks.Task UpdateFirmwareAsync( } // setup files to flash - var filesToFlash = new List(); + List filesToFlash = []; if (updateFw) { @@ -153,7 +153,7 @@ public static async System.Threading.Tasks.Task UpdateFirmwareAsync( jlinkDevice.Verbosity = verbosity; // write HEX files to flash - if (filesToFlash.Any(f => f.EndsWith(".hex"))) + if (filesToFlash.Exists(f => f.EndsWith(".hex"))) { operationResult = jlinkDevice.FlashHexFiles(filesToFlash); } @@ -161,7 +161,7 @@ public static async System.Threading.Tasks.Task UpdateFirmwareAsync( if (operationResult == ExitCodes.OK && isApplicationBinFile) { // now program the application file - operationResult = jlinkDevice.FlashBinFiles(new[] { applicationPath }, new[] { deploymentAddress }); + operationResult = jlinkDevice.FlashBinFiles([applicationPath], [deploymentAddress]); } return operationResult; @@ -178,7 +178,7 @@ public static ExitCodes MassErase( VerbosityLevel verbosity) { // J-Link device - JLinkDevice jlinkDevice = new JLinkDevice(probeId); + JLinkDevice jlinkDevice = new(probeId); if (!jlinkDevice.DevicePresent) { diff --git a/nanoFirmwareFlasher.Library/NanoDeviceOperations.cs b/nanoFirmwareFlasher.Library/NanoDeviceOperations.cs index 7cc6338f..b94a009f 100644 --- a/nanoFirmwareFlasher.Library/NanoDeviceOperations.cs +++ b/nanoFirmwareFlasher.Library/NanoDeviceOperations.cs @@ -163,13 +163,6 @@ public ExitCodes GetDeviceDetails( // report issue throw new CantConnectToNanoDeviceException("Couldn't connect to specified nano device."); } - - if (nanoDevice is null) - { - throw new ArgumentNullException(nameof(nanoDevice)); - } - - return ExitCodes.E2000; } /// diff --git a/nanoFirmwareFlasher.Library/Stm32Operations.cs b/nanoFirmwareFlasher.Library/Stm32Operations.cs index a1647152..32583aee 100644 --- a/nanoFirmwareFlasher.Library/Stm32Operations.cs +++ b/nanoFirmwareFlasher.Library/Stm32Operations.cs @@ -215,7 +215,7 @@ public static async System.Threading.Tasks.Task UpdateFirmwareAsync( if (operationResult == ExitCodes.OK && isApplicationBinFile) { // now program the application file - operationResult = dfuDevice.FlashBinFiles(new[] { applicationPath }, new[] { deploymentAddress }); + operationResult = dfuDevice.FlashBinFiles([applicationPath], [deploymentAddress]); } if ( @@ -282,7 +282,7 @@ public static async System.Threading.Tasks.Task UpdateFirmwareAsync( if (operationResult == ExitCodes.OK && isApplicationBinFile) { // now program the application file - operationResult = jtagDevice.FlashBinFiles(new[] { applicationPath }, new[] { deploymentAddress }); + operationResult = jtagDevice.FlashBinFiles([applicationPath], [deploymentAddress]); } if ( diff --git a/nanoFirmwareFlasher.Library/StmDfuDevice.cs b/nanoFirmwareFlasher.Library/StmDfuDevice.cs index 9e5bb887..c1a803cb 100644 --- a/nanoFirmwareFlasher.Library/StmDfuDevice.cs +++ b/nanoFirmwareFlasher.Library/StmDfuDevice.cs @@ -222,7 +222,7 @@ public ExitCodes StartExecution(string startAddress) if (dfuMatches.Count == 0) { // no DFU device found - return new List<(string serial, string device)>(); + return []; } return dfuMatches.Cast().Select(i => (serial: i.Groups["serial"].Value, device: i.Groups["device"].Value)).ToList(); diff --git a/nanoFirmwareFlasher.Library/StmJtagDevice.cs b/nanoFirmwareFlasher.Library/StmJtagDevice.cs index 913ab2c9..e43bba35 100644 --- a/nanoFirmwareFlasher.Library/StmJtagDevice.cs +++ b/nanoFirmwareFlasher.Library/StmJtagDevice.cs @@ -208,7 +208,7 @@ public static List ListDevices() if (jtagMatches.Count == 0) { // no JTAG found - return new List(); + return []; } return jtagMatches.Cast().Select(i => i.Value).ToList(); diff --git a/nanoFirmwareFlasher.Library/nanoFirmwareFlasher.Library.csproj b/nanoFirmwareFlasher.Library/nanoFirmwareFlasher.Library.csproj index 7453fd98..c507732f 100644 --- a/nanoFirmwareFlasher.Library/nanoFirmwareFlasher.Library.csproj +++ b/nanoFirmwareFlasher.Library/nanoFirmwareFlasher.Library.csproj @@ -2,7 +2,7 @@ library - net6.0;net472 + net8.0;net472 AnyCPU latest nanoFramework.Tools.FirmwareFlasher diff --git a/nanoFirmwareFlasher.Library/packages.lock.json b/nanoFirmwareFlasher.Library/packages.lock.json index 0886c509..2ce9575e 100644 --- a/nanoFirmwareFlasher.Library/packages.lock.json +++ b/nanoFirmwareFlasher.Library/packages.lock.json @@ -263,7 +263,7 @@ "contentHash": "okurQJO6NRE/apDIP23ajJ0hpiNmJ+f0BwOlB/cSqTLQlw5upkf+5+96+iG2Jw40G1fCVCyPz/FhIABUjMR+RQ==" } }, - "net6.0": { + "net8.0": { "Microsoft.ApplicationInsights": { "type": "Direct", "requested": "[2.22.0, )", @@ -413,10 +413,7 @@ "Microsoft.Extensions.Primitives": { "type": "Transitive", "resolved": "8.0.0", - "contentHash": "bXJEZrW9ny8vjMF1JV253WeLhpEVzFo1lyaZu1vQ4ZxWUlVvknZ/+ftFgVheLubb4eZPSwwxBeqS1JkCOjxd8g==", - "dependencies": { - "System.Runtime.CompilerServices.Unsafe": "6.0.0" - } + "contentHash": "bXJEZrW9ny8vjMF1JV253WeLhpEVzFo1lyaZu1vQ4ZxWUlVvknZ/+ftFgVheLubb4eZPSwwxBeqS1JkCOjxd8g==" }, "Microsoft.NETCore.Platforms": { "type": "Transitive", @@ -1016,11 +1013,6 @@ "Microsoft.NETCore.Targets": "1.1.0" } }, - "System.Runtime.CompilerServices.Unsafe": { - "type": "Transitive", - "resolved": "6.0.0", - "contentHash": "/iUeP3tq1S0XdNNoMz5C9twLSrM/TH+qElHkXWaPvuNOt+99G75NrV0OS2EqHx5wMN7popYjpc8oTjC1y16DLg==" - }, "System.Runtime.Extensions": { "type": "Transitive", "resolved": "4.3.0", @@ -1247,17 +1239,13 @@ "System.Text.Encodings.Web": { "type": "Transitive", "resolved": "8.0.0", - "contentHash": "yev/k9GHAEGx2Rg3/tU6MQh4HGBXJs70y7j1LaM1i/ER9po+6nnQ6RRqTJn1E7Xu0fbIFK80Nh5EoODxrbxwBQ==", - "dependencies": { - "System.Runtime.CompilerServices.Unsafe": "6.0.0" - } + "contentHash": "yev/k9GHAEGx2Rg3/tU6MQh4HGBXJs70y7j1LaM1i/ER9po+6nnQ6RRqTJn1E7Xu0fbIFK80Nh5EoODxrbxwBQ==" }, "System.Text.Json": { "type": "Transitive", "resolved": "8.0.0", "contentHash": "OdrZO2WjkiEG6ajEFRABTRCi/wuXQPxeV6g8xvUJqdxMvvuCCEk86zPla8UiIQJz3durtUEbNyY/3lIhS0yZvQ==", "dependencies": { - "System.Runtime.CompilerServices.Unsafe": "6.0.0", "System.Text.Encodings.Web": "8.0.0" } }, diff --git a/nanoFirmwareFlasher.Tool/Options.cs b/nanoFirmwareFlasher.Tool/Options.cs index 7a577ccf..02bdb0c2 100644 --- a/nanoFirmwareFlasher.Tool/Options.cs +++ b/nanoFirmwareFlasher.Tool/Options.cs @@ -353,8 +353,7 @@ public class Options [Usage(ApplicationAlias = "nanoff")] public static IEnumerable Examples => - new List - { + [ new("- Update ESP32 WROVER Kit device with latest available firmware", new Options { TargetName = "ESP_WROVER_KIT", Update = true }), new("- Update specific STM32 device (ST_STM32F769I_DISCOVERY) with latest available firmware, using JTAG interface", new Options { TargetName = "ST_STM32F769I_DISCOVERY" , Update = true, JtagUpdate = true}), new("- Update ESP32 device with latest available firmware (stable version), device is connected to COM31", new Options { Platform = SupportedPlatform.esp32, Update = true, SerialPort = "COM31" }), @@ -364,6 +363,6 @@ public class Options new("- Install STM32 JTAG drivers", new Options { InstallJtagDrivers = true}), new("- List all available STM32 targets", new Options { ListTargets = true, Platform = SupportedPlatform.stm32 }), new("- List all available COM ports", new Options { ListComPorts = true }), - }; + ]; } } diff --git a/nanoFirmwareFlasher.Tool/Program.cs b/nanoFirmwareFlasher.Tool/Program.cs index ca7a961a..ed131e37 100644 --- a/nanoFirmwareFlasher.Tool/Program.cs +++ b/nanoFirmwareFlasher.Tool/Program.cs @@ -32,8 +32,6 @@ internal class Program private static CopyrightInfo _copyrightInfo; private static NanoDeviceOperations _nanoDeviceOperations; - internal static string ExecutingPath; - public static async Task Main(string[] args) { // take care of static fields @@ -49,7 +47,7 @@ public static async Task Main(string[] args) // need this to be able to use ProcessStart at the location where the .NET Core CLI tool is running from string codeBase = Assembly.GetExecutingAssembly().Location; var fullPath = Path.GetFullPath(codeBase); - ExecutingPath = Path.GetDirectoryName(fullPath); + var ExecutingPath = Path.GetDirectoryName(fullPath); // grab AppInsights connection string to setup telemetry client IConfigurationRoot appConfigurationRoot = new ConfigurationBuilder() @@ -67,7 +65,7 @@ public static async Task Main(string[] args) // because of short-comings in CommandLine parsing // need to customize the output to provide a consistent output var parser = new Parser(config => config.HelpWriter = null); - var result = parser.ParseArguments(new[] { "", "" }); + var result = parser.ParseArguments(new string[] { "", "" }); var helpText = new HelpText( new HeadingInfo(_headerInfo), @@ -309,7 +307,7 @@ static async Task RunOptionsAndReturnExitCodeAsync(Options o) { var connectedDevices = _nanoDeviceOperations.ListDevices(_verbosityLevel > VerbosityLevel.Normal); - if (connectedDevices.Count() == 0) + if (!connectedDevices.Any()) { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("No devices found"); @@ -692,7 +690,7 @@ private static void DisplayNoOperationMessage() // because of short-comings in CommandLine parsing // need to customize the output to provide a consistent output var parser = new Parser(config => config.HelpWriter = null); - var result = parser.ParseArguments(new[] { "", "" }); + var result = parser.ParseArguments(new string[] { "", "" }); var helpText = new HelpText( new HeadingInfo(_headerInfo), diff --git a/nanoFirmwareFlasher.Tool/SilabsManager.cs b/nanoFirmwareFlasher.Tool/SilabsManager.cs index ca9a6edb..260fd2d3 100644 --- a/nanoFirmwareFlasher.Tool/SilabsManager.cs +++ b/nanoFirmwareFlasher.Tool/SilabsManager.cs @@ -126,7 +126,7 @@ public async Task ProcessAsync() else if (!string.IsNullOrEmpty(_options.DeploymentImage) && _options.Deploy) { var exitCode = jlinkDevice.FlashBinFiles( - new List() { _options.DeploymentImage }, + [_options.DeploymentImage], _options.FlashAddress); if (exitCode != ExitCodes.OK) diff --git a/nanoFirmwareFlasher.Tool/nanoFirmwareFlasher.Tool.csproj b/nanoFirmwareFlasher.Tool/nanoFirmwareFlasher.Tool.csproj index e0235472..3a9d0417 100644 --- a/nanoFirmwareFlasher.Tool/nanoFirmwareFlasher.Tool.csproj +++ b/nanoFirmwareFlasher.Tool/nanoFirmwareFlasher.Tool.csproj @@ -18,7 +18,6 @@ .NET nanoFirmwareFlasher tool to flash firmware images to target devices. - latest true AnyCPU AnyCPU;x64 @@ -29,7 +28,7 @@ - net6.0 + net8.0 net472 @@ -87,8 +86,8 @@ - - net6.0\ + + net8.0\ diff --git a/nanoFirmwareFlasher.Tool/packages.lock.json b/nanoFirmwareFlasher.Tool/packages.lock.json index 086fbb3c..c29a0f0e 100644 --- a/nanoFirmwareFlasher.Tool/packages.lock.json +++ b/nanoFirmwareFlasher.Tool/packages.lock.json @@ -1,7 +1,7 @@ { "version": 1, "dependencies": { - "net6.0": { + "net8.0": { "CommandLineParser": { "type": "Direct", "requested": "[2.9.1, )", @@ -111,10 +111,7 @@ "Microsoft.Extensions.Primitives": { "type": "Transitive", "resolved": "8.0.0", - "contentHash": "bXJEZrW9ny8vjMF1JV253WeLhpEVzFo1lyaZu1vQ4ZxWUlVvknZ/+ftFgVheLubb4eZPSwwxBeqS1JkCOjxd8g==", - "dependencies": { - "System.Runtime.CompilerServices.Unsafe": "6.0.0" - } + "contentHash": "bXJEZrW9ny8vjMF1JV253WeLhpEVzFo1lyaZu1vQ4ZxWUlVvknZ/+ftFgVheLubb4eZPSwwxBeqS1JkCOjxd8g==" }, "Microsoft.NETCore.Platforms": { "type": "Transitive", @@ -765,11 +762,6 @@ "Microsoft.NETCore.Targets": "1.1.0" } }, - "System.Runtime.CompilerServices.Unsafe": { - "type": "Transitive", - "resolved": "6.0.0", - "contentHash": "/iUeP3tq1S0XdNNoMz5C9twLSrM/TH+qElHkXWaPvuNOt+99G75NrV0OS2EqHx5wMN7popYjpc8oTjC1y16DLg==" - }, "System.Runtime.Extensions": { "type": "Transitive", "resolved": "4.3.0", @@ -996,17 +988,13 @@ "System.Text.Encodings.Web": { "type": "Transitive", "resolved": "8.0.0", - "contentHash": "yev/k9GHAEGx2Rg3/tU6MQh4HGBXJs70y7j1LaM1i/ER9po+6nnQ6RRqTJn1E7Xu0fbIFK80Nh5EoODxrbxwBQ==", - "dependencies": { - "System.Runtime.CompilerServices.Unsafe": "6.0.0" - } + "contentHash": "yev/k9GHAEGx2Rg3/tU6MQh4HGBXJs70y7j1LaM1i/ER9po+6nnQ6RRqTJn1E7Xu0fbIFK80Nh5EoODxrbxwBQ==" }, "System.Text.Json": { "type": "Transitive", "resolved": "8.0.0", "contentHash": "OdrZO2WjkiEG6ajEFRABTRCi/wuXQPxeV6g8xvUJqdxMvvuCCEk86zPla8UiIQJz3durtUEbNyY/3lIhS0yZvQ==", "dependencies": { - "System.Runtime.CompilerServices.Unsafe": "6.0.0", "System.Text.Encodings.Web": "8.0.0" } }, @@ -1112,7 +1100,7 @@ } } }, - "net6.0/any": { + "net8.0/any": { "runtime.any.System.Collections": { "type": "Transitive", "resolved": "4.3.0", @@ -1692,10 +1680,7 @@ "System.Text.Encodings.Web": { "type": "Transitive", "resolved": "8.0.0", - "contentHash": "yev/k9GHAEGx2Rg3/tU6MQh4HGBXJs70y7j1LaM1i/ER9po+6nnQ6RRqTJn1E7Xu0fbIFK80Nh5EoODxrbxwBQ==", - "dependencies": { - "System.Runtime.CompilerServices.Unsafe": "6.0.0" - } + "contentHash": "yev/k9GHAEGx2Rg3/tU6MQh4HGBXJs70y7j1LaM1i/ER9po+6nnQ6RRqTJn1E7Xu0fbIFK80Nh5EoODxrbxwBQ==" }, "System.Threading.Tasks": { "type": "Transitive",