From e41a9eff458beffb50b8158a6205a0a8e4055555 Mon Sep 17 00:00:00 2001
From: Stone_Red <56473591+Stone-Red-Code@users.noreply.github.com>
Date: Mon, 3 Mar 2025 17:14:44 +0100
Subject: [PATCH] Update/Replace NuGet libraries
---
.../HyperbolicDownloader.csproj | 3 +--
HyperbolicDownloader/InputHandler.cs | 12 +++++-----
HyperbolicDownloader/LogCommands.cs | 4 ++--
HyperbolicDownloader/Program.cs | 6 ++---
.../Commands/DownloadCommands.cs | 7 +++---
.../Commands/StreamingCommands.cs | 10 ++++----
.../HyperbolicDownloaderApi.csproj | 4 ++--
.../Managment/ApiManager.cs | 24 +++++++++----------
8 files changed, 33 insertions(+), 37 deletions(-)
diff --git a/HyperbolicDownloader/HyperbolicDownloader.csproj b/HyperbolicDownloader/HyperbolicDownloader.csproj
index 08aa8d4..0483673 100644
--- a/HyperbolicDownloader/HyperbolicDownloader.csproj
+++ b/HyperbolicDownloader/HyperbolicDownloader.csproj
@@ -12,8 +12,7 @@
-
-
+
diff --git a/HyperbolicDownloader/InputHandler.cs b/HyperbolicDownloader/InputHandler.cs
index 0a3aab2..d916262 100644
--- a/HyperbolicDownloader/InputHandler.cs
+++ b/HyperbolicDownloader/InputHandler.cs
@@ -1,16 +1,16 @@
-using Commander_Net;
+using Commander;
+
+using CuteUtils.Misc;
using HyperbolicDownloaderApi.Commands;
using HyperbolicDownloaderApi.FileProcessing;
using HyperbolicDownloaderApi.Networking;
-using Stone_Red_Utilities.ConsoleExtentions;
-
namespace HyperbolicDownloader;
internal class InputHandler
{
- private readonly Commander commander = new Commander();
+ private readonly Commander.Commander commander = new Commander.Commander();
private bool exit = false;
public InputHandler(HostsManager hostsManager, FilesManager filesManager, DirectoryWatcher directoryWatcher)
@@ -37,8 +37,8 @@ internal class InputHandler
Command getCommand = commander.Register(downloadCommands.GetFile, (HelpText)"Attempts to retrieve a file from another host using a hash.", "get");
_ = getCommand.Register(downloadCommands.GetFileFrom, (HelpText)"Attempts to retrieve a file from another host using a .hyper file.", "from");
- Command streamCommand = commander.Register(streamingCommands.StreamWav, (HelpText)"Attempts to stream a .wav file from another host using a hash.", "stream");
- _ = streamCommand.Register(streamingCommands.GetWavStreamFrom, (HelpText)"Attempts to stream a .wav file from another host using a .hyper file.", "from");
+ Command streamCommand = commander.Register(streamingCommands.StreamWav, (HelpText)"(EXPERIMENTAL) Attempts to stream a .wav file from another host using a hash.", "stream");
+ _ = streamCommand.Register(streamingCommands.GetWavStreamFrom, (HelpText)"(EXPERIMENTAL) Attempts to stream a .wav file from another host using a .hyper file.", "from");
Command generateCommad = commander.Register(fileCommands.GenerateFileFull, (HelpText)"Generates a .hyper file from a file hash.", "generate", "gen");
_ = generateCommad.Register(fileCommands.GenerateFileSingle, (HelpText)"Generates a .hyper file from a file hash without checking the known hosts. This adds only the local host to the file.", "noscan");
diff --git a/HyperbolicDownloader/LogCommands.cs b/HyperbolicDownloader/LogCommands.cs
index 5ca027f..8e86964 100644
--- a/HyperbolicDownloader/LogCommands.cs
+++ b/HyperbolicDownloader/LogCommands.cs
@@ -1,6 +1,6 @@
-using HyperbolicDownloaderApi.Managment;
+using CuteUtils.Misc;
-using Stone_Red_Utilities.ConsoleExtentions;
+using HyperbolicDownloaderApi.Managment;
using System.Net;
diff --git a/HyperbolicDownloader/Program.cs b/HyperbolicDownloader/Program.cs
index 1110a07..19188c4 100644
--- a/HyperbolicDownloader/Program.cs
+++ b/HyperbolicDownloader/Program.cs
@@ -1,9 +1,9 @@
-using HyperbolicDownloaderApi.FileProcessing;
+using CuteUtils.Misc;
+
+using HyperbolicDownloaderApi.FileProcessing;
using HyperbolicDownloaderApi.Managment;
using HyperbolicDownloaderApi.Networking;
-using Stone_Red_Utilities.ConsoleExtentions;
-
using System.Reflection;
using System.Text.Json;
diff --git a/HyperbolicDownloaderApi/Commands/DownloadCommands.cs b/HyperbolicDownloaderApi/Commands/DownloadCommands.cs
index 48d778f..58f6c56 100644
--- a/HyperbolicDownloaderApi/Commands/DownloadCommands.cs
+++ b/HyperbolicDownloaderApi/Commands/DownloadCommands.cs
@@ -1,10 +1,10 @@
-using HyperbolicDownloaderApi.FileProcessing;
+using CuteUtils;
+
+using HyperbolicDownloaderApi.FileProcessing;
using HyperbolicDownloaderApi.Managment;
using HyperbolicDownloaderApi.Networking;
using HyperbolicDownloaderApi.Utilities;
-using Stone_Red_Utilities.StringExtentions;
-
using System.Diagnostics;
using System.Net;
using System.Net.Sockets;
@@ -141,7 +141,6 @@ public class DownloadCommands(HostsManager hostsManager, FilesManager filesManag
ApiManager.SendNotificationMessageNewLine($"File name: {fileName}");
ApiManager.SendNotificationMessageNewLine($"Starting download...");
-
if (!Directory.Exists(directoryPath))
{
_ = Directory.CreateDirectory(directoryPath);
diff --git a/HyperbolicDownloaderApi/Commands/StreamingCommands.cs b/HyperbolicDownloaderApi/Commands/StreamingCommands.cs
index 0326c02..c140acd 100644
--- a/HyperbolicDownloaderApi/Commands/StreamingCommands.cs
+++ b/HyperbolicDownloaderApi/Commands/StreamingCommands.cs
@@ -1,12 +1,12 @@
-using HyperbolicDownloaderApi.FileProcessing;
+using CuteUtils;
+
+using HyperbolicDownloaderApi.FileProcessing;
using HyperbolicDownloaderApi.Managment;
using HyperbolicDownloaderApi.Networking;
using NAudio.Utils;
using NAudio.Wave;
-using Stone_Red_Utilities.StringExtentions;
-
using System.Diagnostics;
using System.Net;
using System.Net.Sockets;
@@ -238,9 +238,9 @@ public class StreamingCommands(HostsManager hostsManager)
hostsManager.SaveHosts();
}
- private bool IsBufferNearlyFull(BufferedWaveProvider bufferedWaveProvider)
+ private static bool IsBufferNearlyFull(BufferedWaveProvider bufferedWaveProvider)
{
- return bufferedWaveProvider != null &&
+ return bufferedWaveProvider is not null &&
bufferedWaveProvider.BufferLength - bufferedWaveProvider.BufferedBytes
< bufferedWaveProvider.WaveFormat.AverageBytesPerSecond / 4;
}
diff --git a/HyperbolicDownloaderApi/HyperbolicDownloaderApi.csproj b/HyperbolicDownloaderApi/HyperbolicDownloaderApi.csproj
index ac847e9..34f766f 100644
--- a/HyperbolicDownloaderApi/HyperbolicDownloaderApi.csproj
+++ b/HyperbolicDownloaderApi/HyperbolicDownloaderApi.csproj
@@ -7,9 +7,9 @@
+
-
-
+
diff --git a/HyperbolicDownloaderApi/Managment/ApiManager.cs b/HyperbolicDownloaderApi/Managment/ApiManager.cs
index 448c90a..54ec4b4 100644
--- a/HyperbolicDownloaderApi/Managment/ApiManager.cs
+++ b/HyperbolicDownloaderApi/Managment/ApiManager.cs
@@ -1,7 +1,7 @@
using HyperbolicDownloaderApi.FileProcessing;
using HyperbolicDownloaderApi.Networking;
-using Open.Nat;
+using SharpOpenNat;
using System.Diagnostics;
using System.Net;
@@ -14,7 +14,7 @@ public class ApiManager
public static event EventHandler? OnNotificationMessageRecived;
private static readonly Random random = new();
- private static NatDevice? device;
+ private static INatDevice? device;
private static Mapping? portMapping;
private readonly BroadcastClient broadcastClient = new BroadcastClient();
private readonly NetworkClient networkClient;
@@ -59,8 +59,7 @@ public class ApiManager
{
ApiConfiguration.PublicPort = random.Next(1000, 6000);
- NatDiscoverer? discoverer = new NatDiscoverer();
- device = await discoverer.DiscoverDeviceAsync();
+ device = await OpenNat.Discoverer.DiscoverDeviceAsync();
IPAddress? ip = await device.GetExternalIPAsync();
SendNotificationMessageNewLine($"The public IP address is: {ip} ", NotificationMessageType.Success);
@@ -92,7 +91,7 @@ public class ApiManager
public static void ClosePorts()
{
SendNotificationMessageNewLine("Closing ports...", NotificationMessageType.Info);
- if (device is not null)
+ if (device is not null && portMapping is not null)
{
try
{
@@ -153,6 +152,11 @@ public class ApiManager
OnNotificationMessageRecived?.Invoke(null, new NotificationMessageEventArgs(messageType, message + Environment.NewLine));
}
+ private static void ReciveMessage(object? sender, MessageRecivedEventArgs recivedEventArgs)
+ {
+ SendNotificationMessageNewLine($"Received \"{recivedEventArgs.Data}\" from {recivedEventArgs.IpAddress}.", NotificationMessageType.Info);
+ }
+
private async void BroadcastClient_OnBroadcastRecived(object? sender, BroadcastRecivedEventArgs recivedEventArgs)
{
IPAddress remoteIpAddress = recivedEventArgs.IPEndPoint.Address;
@@ -229,17 +233,11 @@ public class ApiManager
{
SendNotificationMessageNewLine($"{recivedEventArgs.IpAddress} > Requesting file list", NotificationMessageType.Log);
- List files = FilesManager
+ List files = [.. FilesManager
.ToList()
.Select(f => new HyperFileDto(f))
- .Where(f => f.Name.Contains(recivedEventArgs.Data))
- .ToList();
+ .Where(f => f.Name.Contains(recivedEventArgs.Data))];
await recivedEventArgs.SendResponseAsync(files);
}
-
- private void ReciveMessage(object? sender, MessageRecivedEventArgs recivedEventArgs)
- {
- SendNotificationMessageNewLine($"Received \"{recivedEventArgs.Data}\" from {recivedEventArgs.IpAddress}.", NotificationMessageType.Info);
- }
}
\ No newline at end of file