From 41f42bbf2a425d06194c077439abe3c6fd7f07e9 Mon Sep 17 00:00:00 2001 From: Adrian Stevens Date: Thu, 9 Jan 2025 16:23:27 -0800 Subject: [PATCH 1/4] Clean up delete-all command --- .../Current/File/FileDeleteAllCommand.cs | 75 +++++++++++++++++++ .../Current/File/FileDeleteCommand.cs | 39 +++------- .../Meadow.Cli/Properties/launchSettings.json | 2 +- 3 files changed, 87 insertions(+), 29 deletions(-) create mode 100644 Source/v2/Meadow.CLI/Commands/Current/File/FileDeleteAllCommand.cs diff --git a/Source/v2/Meadow.CLI/Commands/Current/File/FileDeleteAllCommand.cs b/Source/v2/Meadow.CLI/Commands/Current/File/FileDeleteAllCommand.cs new file mode 100644 index 00000000..e1dee353 --- /dev/null +++ b/Source/v2/Meadow.CLI/Commands/Current/File/FileDeleteAllCommand.cs @@ -0,0 +1,75 @@ +using CliFx.Attributes; +using Meadow.Hcom; +using Microsoft.Extensions.Logging; + +namespace Meadow.CLI.Commands.DeviceManagement; + +[Command("file delete-all", Description = "Deletes all files from the device")] +public class FileDeleteAllCommand : BaseDeviceCommand +{ + public FileDeleteAllCommand(MeadowConnectionManager connectionManager, ILoggerFactory loggerFactory) + : base(connectionManager, loggerFactory) + { } + + protected override async ValueTask ExecuteCommand() + { + var connection = await GetCurrentConnection(); + var device = await GetCurrentDevice(); + + var state = await device.IsRuntimeEnabled(CancellationToken); + + if (state == true) + { + Logger?.LogInformation($"{Strings.DisablingRuntime}..."); + await device.RuntimeDisable(CancellationToken); + } + + Logger?.LogInformation($"Looking for files..."); + + var folder = AppTools.SanitizeMeadowFolderName("\\"); + + var fileList = await connection.GetFileList($"{folder}", false, CancellationToken); + + if (fileList == null || fileList.Length == 0) + { + Logger?.LogError($"File delete failed, no files found"); + return; + } + + foreach (var file in fileList) + { + await DeleteFileRecursive(device, folder, file, CancellationToken); + } + } + + private async Task DeleteFileRecursive(IMeadowDevice device, string directoryname, MeadowFileInfo fileInfo, CancellationToken cancellationToken) + { + var meadowFile = AppTools.SanitizeMeadowFilename(Path.Combine(directoryname, fileInfo.Name)); + + foreach (var folder in AppManager.PersistantFolders) + { + if (meadowFile.StartsWith($"/{AppManager.MeadowRootFolder}/{folder}")) + { + return; + } + } + + if (fileInfo.IsDirectory) + { + // Add a backslash as we're a directory and not a file + meadowFile += "/"; + var subfolderFiles = await device.GetFileList(meadowFile, false, cancellationToken); + + foreach (var subfolderFile in subfolderFiles!) + { + await DeleteFileRecursive(device, meadowFile, subfolderFile, cancellationToken); + } + return; + } + + Logger?.LogInformation($"Deleting file '{meadowFile}' from device..."); + + await device.DeleteFile(meadowFile, cancellationToken); + await Task.Delay(100); + } +} \ No newline at end of file diff --git a/Source/v2/Meadow.Cli/Commands/Current/File/FileDeleteCommand.cs b/Source/v2/Meadow.Cli/Commands/Current/File/FileDeleteCommand.cs index bf3da405..1da2c383 100644 --- a/Source/v2/Meadow.Cli/Commands/Current/File/FileDeleteCommand.cs +++ b/Source/v2/Meadow.Cli/Commands/Current/File/FileDeleteCommand.cs @@ -27,14 +27,7 @@ protected override async ValueTask ExecuteCommand() await device.RuntimeDisable(CancellationToken); } - if (MeadowFile == "all") - { - Logger?.LogInformation($"Looking for files..."); - } - else - { - Logger?.LogInformation($"Looking for file {MeadowFile}..."); - } + Logger?.LogInformation($"Looking for file {MeadowFile}..."); var folder = AppTools.SanitizeMeadowFolderName(Path.GetDirectoryName(MeadowFile)!); @@ -46,30 +39,20 @@ protected override async ValueTask ExecuteCommand() return; } - if (MeadowFile == "all") + var requested = Path.GetFileName(MeadowFile); + + var exists = fileList?.Any(f => Path.GetFileName(f.Name) == requested) ?? false; + + var file = AppTools.SanitizeMeadowFilename(MeadowFile); + + if (!exists) { - foreach (var file in fileList) - { - await DeleteFileRecursive(device, folder, file, CancellationToken); - } + Logger?.LogError($"File '{file}' not found on device"); } else { - var requested = Path.GetFileName(MeadowFile); - - var exists = fileList?.Any(f => Path.GetFileName(f.Name) == requested) ?? false; - - var file = AppTools.SanitizeMeadowFilename(MeadowFile); - - if (!exists) - { - Logger?.LogError($"File '{file}' not found on device"); - } - else - { - Logger?.LogInformation($"Deleting '{file}'"); - await device.DeleteFile(file, CancellationToken); - } + Logger?.LogInformation($"Deleting '{file}'"); + await device.DeleteFile(file, CancellationToken); } } diff --git a/Source/v2/Meadow.Cli/Properties/launchSettings.json b/Source/v2/Meadow.Cli/Properties/launchSettings.json index 66f46684..c6ff980d 100644 --- a/Source/v2/Meadow.Cli/Properties/launchSettings.json +++ b/Source/v2/Meadow.Cli/Properties/launchSettings.json @@ -101,7 +101,7 @@ }, "File Delete All": { "commandName": "Project", - "commandLineArgs": "file delete all" + "commandLineArgs": "file delete-all" }, "File initial": { "commandName": "Project", From 461d8e020d0cd9f1b24743cdc27883fafeefcff1 Mon Sep 17 00:00:00 2001 From: Adrian Stevens Date: Thu, 9 Jan 2025 16:23:41 -0800 Subject: [PATCH 2/4] Check for missing ESP bins when writing firmware --- .../Commands/Current/Firmware/FirmwareWriteCommand.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Source/v2/Meadow.Cli/Commands/Current/Firmware/FirmwareWriteCommand.cs b/Source/v2/Meadow.Cli/Commands/Current/Firmware/FirmwareWriteCommand.cs index a298c6dc..a1490a2a 100644 --- a/Source/v2/Meadow.Cli/Commands/Current/Firmware/FirmwareWriteCommand.cs +++ b/Source/v2/Meadow.Cli/Commands/Current/Firmware/FirmwareWriteCommand.cs @@ -393,6 +393,14 @@ private async Task WriteEspFiles(IMeadowConnection? connection, DeviceInfo? devi }; } + foreach (var file in fileList) + { + if (!File.Exists(file)) + { + throw new CommandException(string.Format(Strings.InvalidFirmwareForSpecifiedPath, file), CommandExitCode.FileNotFound); + } + } + deviceInfo ??= await connection.GetDeviceInfo(CancellationToken); if (deviceInfo == null) { throw new CommandException(Strings.UnableToGetDeviceInfo); } From 746462ae8a98dca8ee2ff0b86bf35a210a43e0cd Mon Sep 17 00:00:00 2001 From: Adrian Stevens Date: Thu, 9 Jan 2025 16:23:54 -0800 Subject: [PATCH 3/4] Bump version to 2.0.65 --- Source/v2/Meadow.Cli/Meadow.CLI.csproj | 2 +- Source/v2/Meadow.Cli/Properties/AssemblyInfo.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/v2/Meadow.Cli/Meadow.CLI.csproj b/Source/v2/Meadow.Cli/Meadow.CLI.csproj index 28711131..e6c07de1 100644 --- a/Source/v2/Meadow.Cli/Meadow.CLI.csproj +++ b/Source/v2/Meadow.Cli/Meadow.CLI.csproj @@ -10,7 +10,7 @@ Wilderness Labs, Inc Wilderness Labs, Inc true - 2.0.64.0 + 2.0.65.0 AnyCPU http://developer.wildernesslabs.co/Meadow/Meadow.CLI/ https://github.com/WildernessLabs/Meadow.CLI diff --git a/Source/v2/Meadow.Cli/Properties/AssemblyInfo.cs b/Source/v2/Meadow.Cli/Properties/AssemblyInfo.cs index 699528fa..b69bee20 100644 --- a/Source/v2/Meadow.Cli/Properties/AssemblyInfo.cs +++ b/Source/v2/Meadow.Cli/Properties/AssemblyInfo.cs @@ -6,5 +6,5 @@ namespace Meadow.CLI; public static class Constants { - public const string CLI_VERSION = "2.0.64.0"; + public const string CLI_VERSION = "2.0.65.0"; } \ No newline at end of file From e23d26403609b2710a66a7412240633132a9a3c9 Mon Sep 17 00:00:00 2001 From: Adrian Stevens Date: Thu, 9 Jan 2025 16:26:06 -0800 Subject: [PATCH 4/4] Device info formatting --- Source/v2/Meadow.HCom/DeviceInfo.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/v2/Meadow.HCom/DeviceInfo.cs b/Source/v2/Meadow.HCom/DeviceInfo.cs index 7c0ceed1..41a62bdb 100644 --- a/Source/v2/Meadow.HCom/DeviceInfo.cs +++ b/Source/v2/Meadow.HCom/DeviceInfo.cs @@ -30,7 +30,7 @@ public string? this[string propname] public string? SerialNumber => this["SerialNo"]; public string? MacAddress => this["WiFiMAC"]; public string? SoftAPMacAddress => this["SoftAPMac"]; - public string?BluetoothMacAddress => this["BtMac"]; + public string? BluetoothMacAddress => this["BtMac"]; /// /// String representation of an unknown MAC address. @@ -82,11 +82,11 @@ public override string ToString() { if (macCount > 1) { - deviceInfo.AppendLine(" MAC Addresses - "); + deviceInfo.AppendLine(" MAC Addresses"); } else { - deviceInfo.AppendLine(" MAC Address - "); + deviceInfo.AppendLine(" MAC Address"); } deviceInfo.Append($"{macAddresses}"); }