Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recursive folder support + cleanup #565

Merged
merged 13 commits into from
May 17, 2024
22 changes: 11 additions & 11 deletions Source/v2/Meadow.Cli/Commands/Current/App/AppDeployCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ namespace Meadow.CLI.Commands.DeviceManagement;
public class AppDeployCommand : BaseDeviceCommand<AppDeployCommand>
{
private readonly IPackageManager _packageManager;
private string? _lastFile;

private readonly string AppFileName = "App.dll";

[CommandOption('c', Description = Strings.BuildConfiguration, IsRequired = false)]
public string? Configuration { get; private set; }
Expand Down Expand Up @@ -60,11 +61,11 @@ private FileInfo GetMeadowAppFile(string path)
}

// does the directory have an App.dll in it?
file = new FileInfo(System.IO.Path.Combine(path, "App.dll"));
file = new FileInfo(System.IO.Path.Combine(path, AppFileName));
if (!file.Exists)
{
// it's a directory - we need to determine the latest build (they might have a Debug and a Release config)
var candidates = PackageManager.GetAvailableBuiltConfigurations(path, "App.dll");
var candidates = PackageManager.GetAvailableBuiltConfigurations(path, AppFileName);

if (candidates.Length == 0)
{
Expand All @@ -76,7 +77,7 @@ private FileInfo GetMeadowAppFile(string path)
}
else
{
if (System.IO.Path.GetFileName(path) != "App.dll")
if (System.IO.Path.GetFileName(path) != AppFileName)
{
throw new CommandException($"The file '{path}' is not a compiled Meadow application", CommandExitCode.FileNotFound);
}
Expand All @@ -90,7 +91,7 @@ private async Task<bool> DeployApplication(IMeadowConnection connection, string
{
connection.FileWriteProgress += OnFileWriteProgress;

var candidates = PackageManager.GetAvailableBuiltConfigurations(path, "App.dll");
var candidates = PackageManager.GetAvailableBuiltConfigurations(path, AppFileName);

if (candidates.Length == 0)
{
Expand All @@ -106,20 +107,19 @@ private async Task<bool> DeployApplication(IMeadowConnection connection, string

connection.FileWriteProgress -= OnFileWriteProgress;

Logger?.LogInformation($"{Strings.AppDeployedSuccessfully}");

return true;
}

private void OnFileWriteProgress(object? sender, (string fileName, long completed, long total) e)
{
var p = e.completed / (double)e.total * 100d;

if (e.fileName != _lastFile)
if (!double.IsNaN(p))
{
Console?.Output.Write("\n");
_lastFile = e.fileName;
// Console instead of Logger due to line breaking for progress bar
Console?.Output.Write($"Writing {e.fileName}: {p:0}% \r");
}

// Console instead of Logger due to line breaking for progress bar
Console?.Output.Write($"Writing {e.fileName}: {p:0}% \r");
}
}
11 changes: 3 additions & 8 deletions Source/v2/Meadow.Cli/Commands/Current/App/AppRunCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ namespace Meadow.CLI.Commands.DeviceManagement;
public class AppRunCommand : BaseDeviceCommand<AppRunCommand>
{
private readonly IPackageManager _packageManager;
private string? _lastFile;

[CommandOption("no-prefix", 'n', Description = "When set, the message source prefix (e.g. 'stdout>') is suppressed during 'listen'", IsRequired = false)]
public bool NoPrefix { get; init; }
Expand Down Expand Up @@ -134,14 +133,10 @@ private void OnFileWriteProgress(object? sender, (string fileName, long complete
{
var p = e.completed / (double)e.total * 100d;

if (e.fileName != _lastFile)
{
Console?.Output.Write("\n");
_lastFile = e.fileName;
if (!double.IsNaN(p))
{ // Console instead of Logger due to line breaking for progress bar
Console?.Output.Write($"Writing {e.fileName}: {p:0}% \r");
}

// Console instead of Logger due to line breaking for progress bar
Console?.Output.Write($"Writing {e.fileName}: {p:0}% \r");
}

private void OnDeviceMessageReceived(object? sender, (string message, string? source) e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ private async Task DeleteFileRecursive(IMeadowDevice device, string directorynam
return;
}

Logger?.LogInformation($"Deleting file '{meadowFile}' from device...");

Logger?.LogInformation($"Deleting file '{meadowFile}' from device...");
await device.DeleteFile(meadowFile, cancellationToken);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ protected override async ValueTask ExecuteCommand()
{
foreach (var file in files)
{
Logger?.LogInformation(file.Name + (file.IsDirectory ? FolderLabel : string.Empty));
Logger?.LogInformation(file.Name + '\t' + (file.IsDirectory ? FolderLabel : string.Empty));
}

Logger?.LogInformation($"\t{files.Length} file(s)");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ protected override async ValueTask ExecuteCommand()
}
else
{
await connection!.Device!.WriteFile(osFileWithoutBootloader, $"/meadow0/update/os/{package.OsWithoutBootloader}");
await connection!.Device!.WriteFile(osFileWithoutBootloader, $"/{AppTools.MeadowRootFolder}/update/os/{package.OsWithoutBootloader}");
}
}

Expand Down Expand Up @@ -351,7 +351,7 @@ private async Task<IMeadowConnection> FindMeadowConnection(IList<string> portsTo
}
else
{
await connection.Device!.WriteFile(runtimePath, $"/meadow0/update/os/{destinationFilename}");
await connection.Device!.WriteFile(runtimePath, $"/{AppTools.MeadowRootFolder}/update/os/{destinationFilename}");
}

return connection;
Expand Down Expand Up @@ -393,7 +393,7 @@ private async Task WriteEspFiles(IMeadowConnection? connection, DeviceInfo? devi
{
foreach (var file in fileList)
{
await connection!.Device!.WriteFile(file, $"/meadow0/update/os/{Path.GetFileName(file)}");
await connection!.Device!.WriteFile(file, $"/{AppTools.MeadowRootFolder}/update/os/{Path.GetFileName(file)}");
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Source/v2/Meadow.Cli/Meadow.CLI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<Authors>Wilderness Labs, Inc</Authors>
<Company>Wilderness Labs, Inc</Company>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageVersion>2.0.41.0</PackageVersion>
<PackageVersion>2.0.42.0-beta</PackageVersion>
<Platforms>AnyCPU</Platforms>
<PackageProjectUrl>http://developer.wildernesslabs.co/Meadow/Meadow.CLI/</PackageProjectUrl>
<RepositoryUrl>https://github.com/WildernessLabs/Meadow.CLI</RepositoryUrl>
Expand Down
2 changes: 1 addition & 1 deletion Source/v2/Meadow.Cli/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ namespace Meadow.CLI;

public static class Constants
{
public const string CLI_VERSION = "2.0.41.0";
public const string CLI_VERSION = "2.0.42.0";
}
7 changes: 4 additions & 3 deletions Source/v2/Meadow.Cli/Strings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ public static class Strings
public const string NewMeadowDeviceNotFound = "New Meadow device not found";
public const string NoFirmwarePackagesFound = "No firmware packages found, run 'meadow firmware download' to download the latest firmware";
public const string NoDefaultFirmwarePackageSet = "No default firmware package set, run 'meadow firmware default' to set the default firmware";
public const string AppDeployFailed = "Application deploy failed";
public const string AppDeployedSuccessfully = "Application deployed successfully";
public const string AppTrimFailed = "Application trimming failed";


public static class Telemetry
{
Expand All @@ -82,7 +86,4 @@ public static class Telemetry

public const string AskToParticipate = "Would you like to participate?";
}

public const string AppDeployFailed = "Application deploy failed";
public const string AppTrimFailed = "Application trimming failed";
}
7 changes: 3 additions & 4 deletions Source/v2/Meadow.Hcom/Connections/SerialConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,11 @@ private void Open()
}
catch (UnauthorizedAccessException uae)
{
throw new Exception($"{uae.Message} Another application may have access to '{_port.PortName}'. ");
throw new Exception($"{uae.Message}");
}
catch (Exception ex)
{
// We don't know what happened, best to bail and let the user know.
throw new Exception($"Unable to open port '{_port.PortName}'. {ex.Message}");
throw new Exception($"Unable to open port '{_port.PortName}' - {ex.Message}");
}

State = ConnectionState.Connected;
Expand Down Expand Up @@ -855,7 +854,7 @@ public override async Task ResetDevice(CancellationToken? cancellationToken = nu

foreach (var candidate in _textList)
{
var fi = MeadowFileInfo.Parse(candidate);
var fi = MeadowFileInfo.Parse(candidate, folder);
if (fi != null)
{
list.Add(fi);
Expand Down
18 changes: 12 additions & 6 deletions Source/v2/Meadow.Hcom/MeadowFileInfo.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
public class MeadowFileInfo
{
public string Name { get; private set; } = default!;
public string Path { get; private set; } = string.Empty;
public string FullName => System.IO.Path.Combine(Path, Name).Replace("\\", "/");
public long? Size { get; private set; }
public string? Crc { get; private set; }
public bool IsDirectory { get; private set; }
Expand All @@ -10,22 +12,25 @@ public override string ToString()
return $"{(IsDirectory ? "/" : "")}{Name}";
}

public static MeadowFileInfo? Parse(string info)
public static MeadowFileInfo? Parse(string info, string folder)
{
folder = folder.Replace("\\", "/");

MeadowFileInfo? mfi = null;

// parse the input to a file info
if (info.StartsWith("/"))
{
mfi = new MeadowFileInfo();

mfi.Name = info.Substring(1);
mfi.IsDirectory = true;
mfi = new MeadowFileInfo
{
Name = info.Substring(1),
Path = folder,
IsDirectory = true
};
}
else
{
// v2 file lists have changed

if (info.StartsWith("Directory:"))
{
// this is the first line and contains the directory name being parsed
Expand All @@ -51,6 +56,7 @@ public override string ToString()
var end = info.IndexOf(' ', indexOfParen);
mfi.Size = int.Parse(info.Substring(indexOfParen + 1, end - indexOfParen));
}
mfi.Path = folder;
}

return mfi;
Expand Down
Loading
Loading