mirror of
https://github.com/Stone-Red-Code/HyperbolicDownloader.git
synced 2026-09-07 23:40:52 +02:00
Improve file list commands
This commit is contained in:
@@ -64,6 +64,7 @@ public class FileCommands
|
|||||||
public void ListFiles(string searchString)
|
public void ListFiles(string searchString)
|
||||||
{
|
{
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
int fileCount = 0;
|
||||||
List<PrivateHyperFileInfo> fileInfos = filesManager.ToList();
|
List<PrivateHyperFileInfo> fileInfos = filesManager.ToList();
|
||||||
|
|
||||||
if (fileInfos.Count == 0)
|
if (fileInfos.Count == 0)
|
||||||
@@ -81,15 +82,35 @@ public class FileCommands
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fileCount++;
|
||||||
|
|
||||||
ApiManager.SendNotificationMessageNewLine($"{index}) {fileInfo.FilePath}");
|
ApiManager.SendNotificationMessageNewLine($"{index}) {fileInfo.FilePath}");
|
||||||
ApiManager.SendNotificationMessageNewLine($"Hash: {fileInfo.Hash}");
|
ApiManager.SendNotificationMessageNewLine($"Hash: {fileInfo.Hash}");
|
||||||
ApiManager.SendNotificationMessageNewLine(string.Empty);
|
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)
|
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))
|
if (int.TryParse(args, out int index))
|
||||||
{
|
{
|
||||||
List<NetworkSocket> hosts = hostsManager.ToList();
|
List<NetworkSocket> hosts = hostsManager.ToList();
|
||||||
@@ -140,7 +161,7 @@ public class FileCommands
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Task<List<HyperFileDto>?> sendTask = NetworkClient.SendAsync<List<HyperFileDto>>(ipAddress, port, "GetFilesList", string.Empty);
|
Task<List<HyperFileDto>?> sendTask = NetworkClient.SendAsync<List<HyperFileDto>>(ipAddress, port, "GetFilesList", searchString);
|
||||||
|
|
||||||
_ = sendTask.Wait(1000);
|
_ = sendTask.Wait(1000);
|
||||||
|
|
||||||
@@ -152,7 +173,11 @@ public class FileCommands
|
|||||||
|
|
||||||
List<HyperFileDto>? fileInfos = sendTask.Result;
|
List<HyperFileDto>? 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);
|
ApiManager.SendNotificationMessageNewLine("No tracked files!", NotificationMessageType.Warning);
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -227,7 +227,13 @@ public class ApiManager
|
|||||||
{
|
{
|
||||||
SendNotificationMessageNewLine($"{recivedEventArgs.IpAddress} > Requesting file list", NotificationMessageType.Log);
|
SendNotificationMessageNewLine($"{recivedEventArgs.IpAddress} > Requesting file list", NotificationMessageType.Log);
|
||||||
|
|
||||||
await recivedEventArgs.SendResponseAsync(FilesManager.ToList().Select(f => new HyperFileDto(f)).ToList());
|
List<HyperFileDto> 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<string> recivedEventArgs)
|
private void ReciveMessage(object? sender, MessageRecivedEventArgs<string> recivedEventArgs)
|
||||||
|
|||||||
Reference in New Issue
Block a user