Code refactoring

This commit is contained in:
Stone_Red
2022-04-22 16:09:21 +02:00
parent 495a09ec60
commit c2b84dd475
5 changed files with 11 additions and 26 deletions
+2 -8
View File
@@ -3,11 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17 # Visual Studio Version 17
VisualStudioVersion = 17.0.32112.339 VisualStudioVersion = 17.0.32112.339
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HyperbolicDownloaderCli", "HyperbolicDownloader\HyperbolicDownloaderCli.csproj", "{7BA90CAF-36A1-4D55-9CE2-E498ECC1B62D}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HyperbolicDownloader", "HyperbolicDownloader\HyperbolicDownloader.csproj", "{7BA90CAF-36A1-4D55-9CE2-E498ECC1B62D}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HyperbolicDownloaderGUI", "HyperbolicDownloaderGUI\HyperbolicDownloaderGUI.csproj", "{E1CE6E07-F8A6-447F-837D-9D1943A42E96}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HyperbolicDownloaderApi", "HyperbolicDownloaderApi\HyperbolicDownloaderApi.csproj", "{45ACEEC6-9AE4-4DA5-9A08-E22F1EBA7E22}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HyperbolicDownloaderApi", "HyperbolicDownloaderApi\HyperbolicDownloaderApi.csproj", "{45ACEEC6-9AE4-4DA5-9A08-E22F1EBA7E22}"
EndProject EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{CA4F21C6-5B63-46C1-8576-91BB3FAE4FA7}" Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{CA4F21C6-5B63-46C1-8576-91BB3FAE4FA7}"
ProjectSection(SolutionItems) = preProject ProjectSection(SolutionItems) = preProject
@@ -24,10 +22,6 @@ Global
{7BA90CAF-36A1-4D55-9CE2-E498ECC1B62D}.Debug|Any CPU.Build.0 = Debug|Any CPU {7BA90CAF-36A1-4D55-9CE2-E498ECC1B62D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7BA90CAF-36A1-4D55-9CE2-E498ECC1B62D}.Release|Any CPU.ActiveCfg = Release|Any CPU {7BA90CAF-36A1-4D55-9CE2-E498ECC1B62D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7BA90CAF-36A1-4D55-9CE2-E498ECC1B62D}.Release|Any CPU.Build.0 = Release|Any CPU {7BA90CAF-36A1-4D55-9CE2-E498ECC1B62D}.Release|Any CPU.Build.0 = Release|Any CPU
{E1CE6E07-F8A6-447F-837D-9D1943A42E96}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E1CE6E07-F8A6-447F-837D-9D1943A42E96}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E1CE6E07-F8A6-447F-837D-9D1943A42E96}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E1CE6E07-F8A6-447F-837D-9D1943A42E96}.Release|Any CPU.Build.0 = Release|Any CPU
{45ACEEC6-9AE4-4DA5-9A08-E22F1EBA7E22}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {45ACEEC6-9AE4-4DA5-9A08-E22F1EBA7E22}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{45ACEEC6-9AE4-4DA5-9A08-E22F1EBA7E22}.Debug|Any CPU.Build.0 = Debug|Any CPU {45ACEEC6-9AE4-4DA5-9A08-E22F1EBA7E22}.Debug|Any CPU.Build.0 = Debug|Any CPU
{45ACEEC6-9AE4-4DA5-9A08-E22F1EBA7E22}.Release|Any CPU.ActiveCfg = Release|Any CPU {45ACEEC6-9AE4-4DA5-9A08-E22F1EBA7E22}.Release|Any CPU.ActiveCfg = Release|Any CPU
+3 -11
View File
@@ -2,14 +2,14 @@
using HyperbolicDownloaderApi.Commands; using HyperbolicDownloaderApi.Commands;
using HyperbolicDownloaderApi.FileProcessing; using HyperbolicDownloaderApi.FileProcessing;
using HyperbolicDownloaderApi.Networking;
using Stone_Red_Utilities.ConsoleExtentions; using Stone_Red_Utilities.ConsoleExtentions;
namespace HyperbolicDownloaderApi; namespace HyperbolicDownloader;
internal class InputHandler internal class InputHandler
{ {
private readonly HostsManager hostsManager;
private readonly Commander commander = new Commander(); private readonly Commander commander = new Commander();
private bool exit = false; private bool exit = false;
@@ -20,10 +20,8 @@ internal class InputHandler
DownloadCommands downloadCommands = new DownloadCommands(hostsManager, filesManager); DownloadCommands downloadCommands = new DownloadCommands(hostsManager, filesManager);
ClientCommands clientCommands = new ClientCommands(); ClientCommands clientCommands = new ClientCommands();
this.hostsManager = hostsManager;
commander.Register((_) => Console.Clear(), "clear", "cls"); commander.Register((_) => Console.Clear(), "clear", "cls");
commander.Register(Exit, "exit", "quit"); commander.Register((_) => exit = true, "exit", "quit");
commander.Register(clientCommands.ShowInfo, "info", "inf"); commander.Register(clientCommands.ShowInfo, "info", "inf");
commander.Register(hostCommands.Discover, "discover", "disc"); commander.Register(hostCommands.Discover, "discover", "disc");
@@ -72,10 +70,4 @@ internal class InputHandler
} }
} }
} }
private void Exit(string _)
{
hostsManager.SaveHosts();
exit = true;
}
} }
+5 -5
View File
@@ -6,7 +6,7 @@ using Stone_Red_Utilities.ConsoleExtentions;
using System.Text.Json; using System.Text.Json;
namespace HyperbolicDownloaderApi; namespace HyperbolicDownloader;
internal static class Program internal static class Program
{ {
@@ -14,7 +14,7 @@ internal static class Program
private static async Task Main(string[] args) private static async Task Main(string[] args)
{ {
Console.CancelKeyPress += Console_CancelKeyPress; Console.CancelKeyPress += (_, _) => Close();
Console.CursorVisible = false; Console.CursorVisible = false;
ApiManager.OnNotificationMessageRecived += ApiManager_OnNotificationMessageRecived; ApiManager.OnNotificationMessageRecived += ApiManager_OnNotificationMessageRecived;
@@ -35,7 +35,7 @@ internal static class Program
if (args.Length > 0 && File.Exists(args[0])) if (args.Length > 0 && File.Exists(args[0]))
{ {
Commands.DownloadCommands downloadCommands = new Commands.DownloadCommands(apiManager.HostsManager, apiManager.FilesManager); HyperbolicDownloaderApi.Commands.DownloadCommands downloadCommands = new HyperbolicDownloaderApi.Commands.DownloadCommands(apiManager.HostsManager, apiManager.FilesManager);
downloadCommands.GetFileFrom(args[0]); downloadCommands.GetFileFrom(args[0]);
Console.WriteLine("Do you want to continue using this instance? [y/N]"); Console.WriteLine("Do you want to continue using this instance? [y/N]");
if (char.ToLower(Console.ReadKey().KeyChar) != 'y') if (char.ToLower(Console.ReadKey().KeyChar) != 'y')
@@ -76,7 +76,7 @@ internal static class Program
ConsoleExt.WriteLine("Ready", ConsoleColor.Green); ConsoleExt.WriteLine("Ready", ConsoleColor.Green);
inputHandler.ReadInput(); inputHandler.ReadInput();
ApiManager.ClosePorts(); Close();
} }
private static void ApiManager_OnNotificationMessageRecived(object? sender, NotificationMessageEventArgs e) private static void ApiManager_OnNotificationMessageRecived(object? sender, NotificationMessageEventArgs e)
@@ -90,7 +90,7 @@ internal static class Program
} }
} }
private static void Console_CancelKeyPress(object? sender, ConsoleCancelEventArgs e) private static void Close()
{ {
ApiManager.ClosePorts(); ApiManager.ClosePorts();
apiManager.HostsManager.SaveHosts(); apiManager.HostsManager.SaveHosts();
@@ -1,10 +1,9 @@
using HyperbolicDownloaderApi.Managment; using HyperbolicDownloaderApi.Managment;
using HyperbolicDownloaderApi.Networking;
using System.Net.Sockets; using System.Net.Sockets;
using System.Text.Json; using System.Text.Json;
namespace HyperbolicDownloaderApi; namespace HyperbolicDownloaderApi.Networking;
public class HostsManager public class HostsManager
{ {