From 85768546c227adc602e7288257da8eb87511dbf6 Mon Sep 17 00:00:00 2001 From: Adrian Stevens Date: Sat, 17 Feb 2024 19:18:18 -0800 Subject: [PATCH 1/3] Fix delete all and file list --- .../Current/File/FileDeleteCommand.cs | 31 +++++++++++++++---- .../Commands/Current/File/FileListCommand.cs | 4 +-- Source/v2/Meadow.Cli/Meadow.CLI.csproj | 2 +- .../v2/Meadow.Cli/Properties/AssemblyInfo.cs | 2 +- .../Meadow.Cli/Properties/launchSettings.json | 4 +++ 5 files changed, 33 insertions(+), 10 deletions(-) diff --git a/Source/v2/Meadow.Cli/Commands/Current/File/FileDeleteCommand.cs b/Source/v2/Meadow.Cli/Commands/Current/File/FileDeleteCommand.cs index 4b5ba86b..9824a559 100644 --- a/Source/v2/Meadow.Cli/Commands/Current/File/FileDeleteCommand.cs +++ b/Source/v2/Meadow.Cli/Commands/Current/File/FileDeleteCommand.cs @@ -1,4 +1,5 @@ using CliFx.Attributes; +using Meadow.Hcom; using Microsoft.Extensions.Logging; namespace Meadow.CLI.Commands.DeviceManagement; @@ -9,6 +10,8 @@ public class FileDeleteCommand : BaseDeviceCommand [CommandParameter(0, Name = "MeadowFile", IsRequired = true)] public string MeadowFile { get; init; } = default!; + private const string MeadowRootFolder = "meadow0"; + public FileDeleteCommand(MeadowConnectionManager connectionManager, ILoggerFactory loggerFactory) : base(connectionManager, loggerFactory) { } @@ -26,10 +29,10 @@ protected override async ValueTask ExecuteCommand() var folder = Path.GetDirectoryName(MeadowFile)!.Replace(Path.DirectorySeparatorChar, '/'); if (string.IsNullOrWhiteSpace(folder)) { - folder = "/meadow0"; + folder = MeadowRootFolder; } - var fileList = await connection.GetFileList($"{folder}/", false); + var fileList = await connection.GetFileList($"/{folder}/", false); if (fileList == null || fileList.Length == 0) { @@ -39,11 +42,9 @@ protected override async ValueTask ExecuteCommand() if (MeadowFile == "all") { - foreach (var f in fileList) + foreach (var file in fileList) { - var p = Path.GetFileName(f.Name); - Logger?.LogInformation($"Deleting file '{p}' from device..."); - await connection.Device.DeleteFile(p, CancellationToken); + await DeleteFileRecursive(connection.Device, file, CancellationToken); } } else @@ -71,4 +72,22 @@ protected override async ValueTask ExecuteCommand() } } } + + private async Task DeleteFileRecursive(IMeadowDevice device, MeadowFileInfo fileInfo, CancellationToken cancellationToken) + { + if (fileInfo.IsDirectory) + { + var subfolderFiles = await device.GetFileList(fileInfo.Name, false, cancellationToken); + + foreach (var subfolderFile in subfolderFiles) + { + await DeleteFileRecursive(device, subfolderFile, cancellationToken); + } + return; + } + + var fileName = Path.GetFileName(fileInfo.Name); + Logger?.LogInformation($"Deleting file '{fileName}' from device..."); + await device.DeleteFile(fileName, cancellationToken); + } } \ No newline at end of file diff --git a/Source/v2/Meadow.Cli/Commands/Current/File/FileListCommand.cs b/Source/v2/Meadow.Cli/Commands/Current/File/FileListCommand.cs index 4e32513a..95fbc369 100644 --- a/Source/v2/Meadow.Cli/Commands/Current/File/FileListCommand.cs +++ b/Source/v2/Meadow.Cli/Commands/Current/File/FileListCommand.cs @@ -38,11 +38,11 @@ protected override async ValueTask ExecuteCommand() } if (Folder.StartsWith('/') == false) { - Folder += "/"; + Folder = $"/{Folder}"; } if (Folder.Contains(MeadowRootFolder) == false) { - Folder += $"/{MeadowRootFolder}"; + Folder = $"/{MeadowRootFolder}{Folder}"; } Logger?.LogInformation($"Getting file list from '{Folder}'..."); diff --git a/Source/v2/Meadow.Cli/Meadow.CLI.csproj b/Source/v2/Meadow.Cli/Meadow.CLI.csproj index 5859f556..04efc9ce 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.7 + 2.0.7.1 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 cb918ad9..a7ab2d30 100644 --- a/Source/v2/Meadow.Cli/Properties/AssemblyInfo.cs +++ b/Source/v2/Meadow.Cli/Properties/AssemblyInfo.cs @@ -6,6 +6,6 @@ namespace Meadow.CLI { public static class Constants { - public const string CLI_VERSION = "2.0.7.0"; + public const string CLI_VERSION = "2.0.7.1"; } } \ No newline at end of file diff --git a/Source/v2/Meadow.Cli/Properties/launchSettings.json b/Source/v2/Meadow.Cli/Properties/launchSettings.json index 5b7f6445..fcce861e 100644 --- a/Source/v2/Meadow.Cli/Properties/launchSettings.json +++ b/Source/v2/Meadow.Cli/Properties/launchSettings.json @@ -83,6 +83,10 @@ "commandName": "Project", "commandLineArgs": "file delete Juego.pdb" }, + "File Delete All": { + "commandName": "Project", + "commandLineArgs": "file delete all" + }, "File Read": { "commandName": "Project", "commandLineArgs": "file read test.txt \"f:\\temp\\test2.txt\"" From 71b701232b009a04d3b2cab90bfe7775217febc7 Mon Sep 17 00:00:00 2001 From: Adrian Stevens Date: Sat, 17 Feb 2024 19:31:14 -0800 Subject: [PATCH 2/3] Fix firmware write esp --- .../Commands/Current/Firmware/FirmwareWriteCommand.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Source/v2/Meadow.Cli/Commands/Current/Firmware/FirmwareWriteCommand.cs b/Source/v2/Meadow.Cli/Commands/Current/Firmware/FirmwareWriteCommand.cs index 8219755a..be7e9a0c 100644 --- a/Source/v2/Meadow.Cli/Commands/Current/Firmware/FirmwareWriteCommand.cs +++ b/Source/v2/Meadow.Cli/Commands/Current/Firmware/FirmwareWriteCommand.cs @@ -248,7 +248,14 @@ protected override async ValueTask ExecuteCommand() || Path.GetFileName(IndividualFile) == F7FirmwarePackageCollection.F7FirmwareFiles.CoprocApplicationFile || Path.GetFileName(IndividualFile) == F7FirmwarePackageCollection.F7FirmwareFiles.CoprocBootloaderFile) { - await connection.RuntimeDisable(); + if(connection == null) + { + connection = await GetConnectionAndDisableRuntime(); + } + else + { + await connection.RuntimeDisable(); + } await WriteEspFiles(connection, deviceInfo, package); } From 4d8f1d84f7399631d5ac58852a1302e918dfec54 Mon Sep 17 00:00:00 2001 From: Adrian Stevens Date: Sat, 17 Feb 2024 19:48:24 -0800 Subject: [PATCH 3/3] cleanup verbose output --- .../Commands/Current/File/FileListCommand.cs | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/Source/v2/Meadow.Cli/Commands/Current/File/FileListCommand.cs b/Source/v2/Meadow.Cli/Commands/Current/File/FileListCommand.cs index 95fbc369..de9ae6b6 100644 --- a/Source/v2/Meadow.Cli/Commands/Current/File/FileListCommand.cs +++ b/Source/v2/Meadow.Cli/Commands/Current/File/FileListCommand.cs @@ -1,6 +1,5 @@ using CliFx.Attributes; using Microsoft.Extensions.Logging; -using System.Linq; namespace Meadow.CLI.Commands.DeviceManagement; @@ -10,6 +9,7 @@ public class FileListCommand : BaseDeviceCommand public const int FileSystemBlockSize = 4096; private const string MeadowRootFolder = "meadow0"; + private const string FolderLabel = "[folder]"; [CommandOption("verbose", 'v', IsRequired = false)] public bool Verbose { get; init; } @@ -81,19 +81,27 @@ protected override async ValueTask ExecuteCommand() totalBlocksUsed += ((file.Size ?? 0) / FileSystemBlockSize) + 1; var line = $"{file.Name.PadRight(longestFileName)}"; - line = $"{line}\t{file.Crc:x8}"; - if (file.Size > 1000000) + if(file.IsDirectory) { - line = $"{line}\t{file.Size / 1000000d,7:0.0} MB "; - } - else if (file.Size > 1000) - { - line = $"{line}\t{file.Size / 1000,7:0} kB "; + line = $"{line}\t{FolderLabel}"; } else { - line = $"{line}\t{file.Size,7} bytes"; + line = $"{line}\t{file.Crc:x8}"; + + if (file.Size > 1000000) + { + line = $"{line}\t{file.Size / 1000000d,7:0.0} MB "; + } + else if (file.Size > 1000) + { + line = $"{line}\t{file.Size / 1000,7:0} kB "; + } + else + { + line = $"{line}\t{file.Size,7} bytes"; + } } Logger?.LogInformation(line); @@ -110,7 +118,7 @@ protected override async ValueTask ExecuteCommand() { foreach (var file in files) { - Logger?.LogInformation(file.Name + (file.IsDirectory?" [folder]":string.Empty)); + Logger?.LogInformation(file.Name + (file.IsDirectory?FolderLabel:string.Empty)); } Logger?.LogInformation($"\t{files.Length} file(s)");