The library can now be used for Windows exclusive bots (Made with WinForm or Wpf)
This commit is contained in:
@@ -3,6 +3,7 @@ using System.IO;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using PluginManager.Others;
|
||||
|
||||
namespace PluginManager.Online.Helpers;
|
||||
@@ -18,10 +19,10 @@ internal static class OnlineFunctions
|
||||
/// <param name="progress">The <see cref="IProgress{T}" /> that is used to track the download progress</param>
|
||||
/// <param name="cancellation">The cancellation token</param>
|
||||
/// <returns></returns>
|
||||
internal static async Task DownloadFileAsync(this HttpClient client, string url, Stream destination,
|
||||
IProgress<float>? progress = null,
|
||||
IProgress<long>? downloadedBytes = null, int bufferSize = 81920,
|
||||
CancellationToken cancellation = default)
|
||||
internal static async Task DownloadFileAsync(this HttpClient client, string url, Stream destination,
|
||||
IProgress<float>? progress = null,
|
||||
IProgress<long>? downloadedBytes = null, int bufferSize = 81920,
|
||||
CancellationToken cancellation = default)
|
||||
{
|
||||
using (var response = await client.GetAsync(url, HttpCompletionOption.ResponseHeadersRead, cancellation))
|
||||
{
|
||||
@@ -40,14 +41,14 @@ internal static class OnlineFunctions
|
||||
// Convert absolute progress (bytes downloaded) into relative progress (0% - 100%)
|
||||
var relativeProgress = new Progress<long>(totalBytes =>
|
||||
{
|
||||
progress.Report((float)totalBytes / contentLength.Value * 100);
|
||||
progress?.Report((float)totalBytes / contentLength.Value * 100);
|
||||
downloadedBytes?.Report(totalBytes);
|
||||
}
|
||||
);
|
||||
|
||||
// Use extension method to report progress while downloading
|
||||
await download.CopyToOtherStreamAsync(destination, bufferSize, relativeProgress, cancellation);
|
||||
progress.Report(1);
|
||||
progress.Report(100);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ public class PluginsManager
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Settings.Variables.outputStream.WriteLine("Failed to execute command: listplugs\nReason: " + exception.Message);
|
||||
Logger.WriteLine("Failed to execute command: listplugs\nReason: " + exception.Message);
|
||||
Functions.WriteErrFile(exception.ToString());
|
||||
}
|
||||
}
|
||||
@@ -116,7 +116,7 @@ public class PluginsManager
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Settings.Variables.outputStream.WriteLine("Failed to execute command: listplugs\nReason: " + exception.Message);
|
||||
Logger.WriteLine("Failed to execute command: listplugs\nReason: " + exception.Message);
|
||||
Functions.WriteErrFile(exception.ToString());
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ public class PluginUpdater
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
Logger.LogError(ex);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user