From b1014a7c9a6c2c2152cec9be02ca985ea1ce9e34 Mon Sep 17 00:00:00 2001 From: Stone_Red <56473591+Stone-Red-Code@users.noreply.github.com> Date: Thu, 27 Jan 2022 22:57:25 +0100 Subject: [PATCH] - Automatically track downloaded files --- .../UserInterface/InputHandler.cs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/HyperbolicDownloader/UserInterface/InputHandler.cs b/HyperbolicDownloader/UserInterface/InputHandler.cs index b7b4a8f..6715f5a 100644 --- a/HyperbolicDownloader/UserInterface/InputHandler.cs +++ b/HyperbolicDownloader/UserInterface/InputHandler.cs @@ -38,6 +38,8 @@ internal class InputHandler listCommand.Register(ListFiles, "files"); listCommand.Register(ListHosts, "hosts"); + commander.Register((_) => hostsManager.CheckHostsActivity(), "status", "check"); + this.filesManager = filesManager; } @@ -180,7 +182,8 @@ internal class InputHandler { if (string.IsNullOrEmpty(hash)) { - Console.WriteLine("No hash value specified!"); + ConsoleExt.WriteLine("No hash value specified!", ConsoleColor.Red); + return; } hash = hash.Trim(); @@ -250,6 +253,7 @@ internal class InputHandler } string fileName = parts[1].ToFileName(); + string filepath = $"./Downloads/{fileName}"; Console.WriteLine($"File name: {fileName}"); Console.WriteLine($"Starting download..."); @@ -261,7 +265,7 @@ internal class InputHandler Directory.CreateDirectory("./Downloads"); } - using FileStream? fileStream = new FileStream($"./Downloads/{fileName}", FileMode.Create); + using FileStream? fileStream = new FileStream(filepath, FileMode.Create); int bytesInOneSecond = 0; int unitsPerSecond = 0; @@ -321,12 +325,16 @@ internal class InputHandler Console.WriteLine(); Console.WriteLine("Validating file..."); - if (!FileValidator.ValidateHash($"./Downloads/{fileName}", hash)) + if (FileValidator.ValidateHash(filepath, hash)) + { + _ = filesManager.TryAdd(filepath, out _, out _); + } + else { ConsoleExt.WriteLine("Warning: File hash does not match! File might me corrupted or manipulated!", ConsoleColor.DarkYellow); } - Console.WriteLine($"File saved at: {Path.GetFullPath($"./Downloads/{fileName}")}"); + Console.WriteLine($"File saved at: {Path.GetFullPath(filepath)}"); ConsoleExt.WriteLine("Done", ConsoleColor.Green); stopWatch.Stop(); hostsManager.SaveHosts();