From f635b0d85501395856ba6e7d7bd7dc2d05bd49ee Mon Sep 17 00:00:00 2001 From: Stone_Red <56473591+Stone-Red-Code@users.noreply.github.com> Date: Thu, 14 Dec 2023 11:21:31 +0100 Subject: [PATCH] Improve file list commands --- .../Commands/FileCommands.cs | 31 +++++++++++++++++-- .../Managment/ApiManager.cs | 8 ++++- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/HyperbolicDownloaderApi/Commands/FileCommands.cs b/HyperbolicDownloaderApi/Commands/FileCommands.cs index 0416a91..aa0a4d2 100644 --- a/HyperbolicDownloaderApi/Commands/FileCommands.cs +++ b/HyperbolicDownloaderApi/Commands/FileCommands.cs @@ -64,6 +64,7 @@ public class FileCommands public void ListFiles(string searchString) { int index = 0; + int fileCount = 0; List fileInfos = filesManager.ToList(); if (fileInfos.Count == 0) @@ -81,15 +82,35 @@ public class FileCommands continue; } + fileCount++; + ApiManager.SendNotificationMessageNewLine($"{index}) {fileInfo.FilePath}"); ApiManager.SendNotificationMessageNewLine($"Hash: {fileInfo.Hash}"); ApiManager.SendNotificationMessageNewLine(string.Empty); } - Console.CursorTop--; + + if (fileCount == 0) + { + ApiManager.SendNotificationMessage($"No files found containing \"{searchString}\".", NotificationMessageType.Warning); + } + else + { + Console.CursorTop--; + } } public void ListFilesRemote(string args) { + args = args.Trim(); + + string searchString = string.Empty; + + if (args.Contains(' ')) + { + searchString = args.Substring(args.IndexOf(' ') + 1, args.Length - args.IndexOf(' ') - 1); + args = args[..args.IndexOf(' ')]; + } + if (int.TryParse(args, out int index)) { List hosts = hostsManager.ToList(); @@ -140,7 +161,7 @@ public class FileCommands return; } - Task?> sendTask = NetworkClient.SendAsync>(ipAddress, port, "GetFilesList", string.Empty); + Task?> sendTask = NetworkClient.SendAsync>(ipAddress, port, "GetFilesList", searchString); _ = sendTask.Wait(1000); @@ -152,7 +173,11 @@ public class FileCommands List? fileInfos = sendTask.Result; - if (fileInfos is null || fileInfos.Count == 0) + if (fileInfos?.Count == 0 && !string.IsNullOrEmpty(searchString)) + { + ApiManager.SendNotificationMessageNewLine($"No files found containing \"{searchString}\".", NotificationMessageType.Warning); + } + else if (fileInfos is null || fileInfos.Count == 0) { ApiManager.SendNotificationMessageNewLine("No tracked files!", NotificationMessageType.Warning); return; diff --git a/HyperbolicDownloaderApi/Managment/ApiManager.cs b/HyperbolicDownloaderApi/Managment/ApiManager.cs index fa65ed7..71e704a 100644 --- a/HyperbolicDownloaderApi/Managment/ApiManager.cs +++ b/HyperbolicDownloaderApi/Managment/ApiManager.cs @@ -227,7 +227,13 @@ public class ApiManager { SendNotificationMessageNewLine($"{recivedEventArgs.IpAddress} > Requesting file list", NotificationMessageType.Log); - await recivedEventArgs.SendResponseAsync(FilesManager.ToList().Select(f => new HyperFileDto(f)).ToList()); + List files = FilesManager + .ToList() + .Select(f => new HyperFileDto(f)) + .Where(f => f.Name.Contains(recivedEventArgs.Data)) + .ToList(); + + await recivedEventArgs.SendResponseAsync(files); } private void ReciveMessage(object? sender, MessageRecivedEventArgs recivedEventArgs)