diff --git a/BUILDS/net6.0/Music Commands.dll b/BUILDS/net6.0/Music Commands.dll index 2341731..cb4a5fc 100644 Binary files a/BUILDS/net6.0/Music Commands.dll and b/BUILDS/net6.0/Music Commands.dll differ diff --git a/BUILDS/net6.0/PluginManager.dll b/BUILDS/net6.0/PluginManager.dll index 2ab2537..7c99f4f 100644 Binary files a/BUILDS/net6.0/PluginManager.dll and b/BUILDS/net6.0/PluginManager.dll differ diff --git a/DiscordBot/Program.cs b/DiscordBot/Program.cs index 98faa69..8dd1586 100644 --- a/DiscordBot/Program.cs +++ b/DiscordBot/Program.cs @@ -6,6 +6,8 @@ using System.Reflection; using System.Threading; using System.Threading.Tasks; +using Discord; + using DiscordBot.Discord.Core; using PluginManager; @@ -210,10 +212,8 @@ public class Program /// The arguments private static async Task HandleInput(string[] args) { - var b = await StartNoGUI(); - consoleCommandsHandler = new ConsoleCommandsHandler(b.client); - var len = args.Length; + var len = args.Length; if (len == 3 && args[0] == "/download") { @@ -225,17 +225,23 @@ public class Program return; } - if (len > 0 && args[0] == "/remplug") + if (len > 0 && args[0] == "/test") { + int p = 1; + bool allowed = true; + Console.CancelKeyPress += (sender, e) => allowed = false; + Console_Utilities.ProgressBar bar = new Console_Utilities.ProgressBar(); + Console.WriteLine("Press Ctrl + C to stop."); + while (p <= int.MaxValue - 1 && allowed) + { + bar.Update(ProgressBarType.NO_END, 100 / p); + await Task.Delay(100); + p++; + } - string plugName = Functions.MergeStrings(args, 1); - Console.WriteLine("Starting to remove " + plugName); - await ConsoleCommandsHandler.ExecuteCommad("remplug " + plugName); - loadPluginsOnStartup = true; - len = 0; + return; } - if (len > 0 && (args.Contains("--cmd") || args.Contains("--args") || args.Contains("--nomessage"))) { if (args.Contains("lp") || args.Contains("loadplugins")) @@ -248,6 +254,19 @@ public class Program + var b = await StartNoGUI(); + consoleCommandsHandler = new ConsoleCommandsHandler(b.client); + + if (len > 0 && args[0] == "/remplug") + { + + string plugName = Functions.MergeStrings(args, 1); + Console.WriteLine("Starting to remove " + plugName); + await ConsoleCommandsHandler.ExecuteCommad("remplug " + plugName); + loadPluginsOnStartup = true; + len = 0; + } + if (len == 0 || (args[0] != "--exec" && args[0] != "--execute")) { diff --git a/MusicCommands/AudioFile.cs b/MusicCommands/AudioFile.cs index 76daa24..bd7b576 100644 --- a/MusicCommands/AudioFile.cs +++ b/MusicCommands/AudioFile.cs @@ -1,4 +1,5 @@ using AngleSharp.Dom; + using System; using System.Collections.Generic; using System.Diagnostics; @@ -11,20 +12,20 @@ namespace MusicCommands internal class AudioFile { internal string Name { get; set; } - internal string Url { get; set; } + internal string Url { get; set; } internal AudioFile(string name, string url) { Name = name; - Url = url; + Url = url; } internal async Task DownloadAudioFile() { Process proc = new Process(); - proc.StartInfo.FileName = "MusicDownloader.exe"; - proc.StartInfo.Arguments = $"{Url},{Name}"; - proc.StartInfo.UseShellExecute = false; + proc.StartInfo.FileName = "MusicDownloader"; + proc.StartInfo.Arguments = $"{Url},{Name}"; + proc.StartInfo.UseShellExecute = false; proc.StartInfo.RedirectStandardOutput = true; proc.Start(); diff --git a/PluginManager/Items/ConsoleCommandsHandler.cs b/PluginManager/Items/ConsoleCommandsHandler.cs index 2532636..bc95438 100644 --- a/PluginManager/Items/ConsoleCommandsHandler.cs +++ b/PluginManager/Items/ConsoleCommandsHandler.cs @@ -185,7 +185,7 @@ public class ConsoleCommandsHandler { while (isExtracting) { - bar.Update(proc); + bar.Update(ProgressBarType.NORMAL, proc); if (proc >= 99.9f) isExtracting = false; Thread.Sleep(500); @@ -194,10 +194,10 @@ public class ConsoleCommandsHandler ).Start ).Start(); await Functions.ExtractArchive("./" + split[1], "./", extractProgress, UnzipProgressType.PercentageFromTotalSize); - bar.Update(100f); + bar.Update(ProgressBarType.NORMAL, 100f); isExtracting = false; await Task.Delay(1000); - bar.Update(100); + bar.Update(ProgressBarType.NORMAL, 100); Console.WriteLine("\n"); File.Delete("./" + split[1]); } diff --git a/PluginManager/Online/PluginsManager.cs b/PluginManager/Online/PluginsManager.cs index ddbe61c..2ad44b4 100644 --- a/PluginManager/Online/PluginsManager.cs +++ b/PluginManager/Online/PluginsManager.cs @@ -1,7 +1,9 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; + using PluginManager.Others; + using OperatingSystem = PluginManager.Others.OperatingSystem; namespace PluginManager.Online; @@ -30,13 +32,13 @@ public class PluginsManager { try { - var list = await ServerCom.ReadTextFromURL(PluginsLink); + var list = await ServerCom.ReadTextFromURL(PluginsLink); var lines = list.ToArray(); var data = new List(); - var op = Functions.GetOperatingSystem(); + var op = Functions.GetOperatingSystem(); - var len = lines.Length; + var len = lines.Length; string[] titles = { "Name", "Description", "Plugin Type", "Libraries", "Installed" }; data.Add(new[] { "-", "-", "-", "-", "-" }); data.Add(titles); @@ -86,7 +88,7 @@ public class PluginsManager data.Add(new[] { "-", "-", "-", "-", "-" }); - Console_Utilities.FormatAndAlignTable(data); + Console_Utilities.FormatAndAlignTable(data, TableFormat.CENTER_EACH_COLUMN_BASED); } catch (Exception exception) { @@ -104,9 +106,9 @@ public class PluginsManager { try { - var list = await ServerCom.ReadTextFromURL(PluginsLink); + var list = await ServerCom.ReadTextFromURL(PluginsLink); var lines = list.ToArray(); - var len = lines.Length; + var len = lines.Length; for (var i = 0; i < len; i++) { var contents = lines[i].Split(','); diff --git a/PluginManager/Online/ServerCom.cs b/PluginManager/Online/ServerCom.cs index 7ae5834..267042e 100644 --- a/PluginManager/Online/ServerCom.cs +++ b/PluginManager/Online/ServerCom.cs @@ -51,8 +51,8 @@ namespace PluginManager.Online /// public static async Task DownloadFileAsync(string URL, string location) { - bool isDownloading = true; - float c_progress = 0; + bool isDownloading = true; + float c_progress = 0; Console_Utilities.ProgressBar pbar = new Console_Utilities.ProgressBar { Max = 100f, NoColor = true }; @@ -63,7 +63,7 @@ namespace PluginManager.Online { while (isDownloading) { - pbar.Update(c_progress); + pbar.Update(ProgressBarType.NORMAL, c_progress); if (c_progress == 100f) break; Thread.Sleep(500); @@ -76,7 +76,7 @@ namespace PluginManager.Online c_progress = pbar.Max; - pbar.Update(100f); + pbar.Update(ProgressBarType.NORMAL, 100f); isDownloading = false; } } diff --git a/PluginManager/Others/Console Utilities.cs b/PluginManager/Others/Console Utilities.cs index 44a8a42..fc40d3a 100644 --- a/PluginManager/Others/Console Utilities.cs +++ b/PluginManager/Others/Console Utilities.cs @@ -1,4 +1,5 @@ using Discord; + using System; using System.Collections.Generic; using System.Linq; @@ -32,47 +33,74 @@ namespace PluginManager.Others /// public class ProgressBar { - public float Max { get; init; } - public ConsoleColor Color { get; init; } - public bool NoColor { get; init; } + public float Max { get; init; } + public ConsoleColor Color { get; init; } + public bool NoColor { get; init; } + private int BarLength = 32; + private int position = 1; + private bool positive = true; - public void Update(float progress, double speed = -1, string? unit = null) + public void Update(ProgressBarType type, float progress) + { + switch (type) + { + case ProgressBarType.NORMAL: + UpdateNormal(progress); + return; + case ProgressBarType.NO_END: + if (progress <= 99.9f) + UpdateNoEnd(); + return; + } + } + + private void UpdateNoEnd() { Console.CursorLeft = 0; Console.Write("["); - Console.CursorLeft = 32; + for (int i = 1; i <= position; i++) + Console.Write(" "); + Console.Write("<==()==>"); + position += positive ? 1 : -1; + for (int i = position; i <= BarLength - 1 - (positive ? 0 : 2); i++) + Console.Write(" "); + Console.Write("]"); + + + if (position == BarLength - 1 || position == 1) + positive = !positive; + } + + private void UpdateNormal(float progress) + { + Console.CursorLeft = 0; + Console.Write("["); + Console.CursorLeft = BarLength; Console.Write("]"); Console.CursorLeft = 1; float onechunk = 30.0f / Max; - int position = 1; - for (int i = 0; i < onechunk * progress; i++) { Console.BackgroundColor = NoColor ? ConsoleColor.Black : this.Color; - Console.CursorLeft = position++; + Console.CursorLeft = position++; Console.Write("#"); } - for (int i = position; i <= 31; i++) + for (int i = position; i <= BarLength - 1; i++) { Console.BackgroundColor = NoColor ? ConsoleColor.Black : ConsoleColor.DarkGray; - Console.CursorLeft = position++; + Console.CursorLeft = position++; Console.Write(" "); } Console.CursorLeft = 35; Console.BackgroundColor = ConsoleColor.Black; - if (speed is -1 || unit == null) - { - if (progress.CanAproximateTo(Max)) - Console.Write(progress + " % ✓"); - else - Console.Write(MathF.Round(progress, 2) + " % "); - } + if (progress.CanAproximateTo(Max)) + Console.Write(progress + " % ✓"); else - Console.Write(progress + $"{speed} {unit}/s "); + Console.Write(MathF.Round(progress, 2) + " % "); } } @@ -84,13 +112,13 @@ namespace PluginManager.Others /// A way to create a table based on input data /// /// The List of arrays of strings that represent the rows. - public static void FormatAndAlignTable(List data, TableFormat format = TableFormat.CENTER_EACH_COLUMN_BASED) + public static void FormatAndAlignTable(List data, TableFormat format) { if (format == TableFormat.CENTER_EACH_COLUMN_BASED) { - char tableLine = '-'; + char tableLine = '-'; char tableCross = '+'; - char tableWall = '|'; + char tableWall = '|'; int[] len = new int[data[0].Length]; foreach (var line in data) @@ -196,8 +224,8 @@ namespace PluginManager.Others if (format == TableFormat.DEFAULT) { - int[] widths = new int[data[0].Length]; - int space_between_columns = int.Parse(Config.GetValue>("TableVariables")?["DefaultSpace"]!); + int[] widths = new int[data[0].Length]; + int space_between_columns = int.Parse(Config.GetValue>("TableVariables")?["DefaultSpace"]!); for (int i = 0; i < data.Count; i++) { for (int j = 0; j < data[i].Length; j++) @@ -230,7 +258,7 @@ namespace PluginManager.Others public static void WriteColorText(string text, bool appendNewLineAtEnd = true) { ConsoleColor initialForeGround = Console.ForegroundColor; - char[] input = text.ToCharArray(); + char[] input = text.ToCharArray(); for (int i = 0; i < input.Length; i++) { if (input[i] == Config.GetValue("ColorPrefix")) diff --git a/PluginManager/Others/Enums.cs b/PluginManager/Others/Enums.cs index e1e3f77..fb63614 100644 --- a/PluginManager/Others/Enums.cs +++ b/PluginManager/Others/Enums.cs @@ -32,4 +32,5 @@ public enum UnzipProgressType { PercentageFromNumberOfFiles, PercentageFromTotal public enum TableFormat { CENTER_EACH_COLUMN_BASED, CENTER_OVERALL_LENGTH, DEFAULT } -public enum SaveType { NORMAL, BACKUP } \ No newline at end of file +public enum SaveType { NORMAL, BACKUP } +public enum ProgressBarType { NORMAL, NO_END } \ No newline at end of file diff --git a/PluginManager/Others/Functions.cs b/PluginManager/Others/Functions.cs index 8b17397..2f26f9e 100644 --- a/PluginManager/Others/Functions.cs +++ b/PluginManager/Others/Functions.cs @@ -36,7 +36,7 @@ namespace PluginManager.Others /// /// Archives folder /// - public static readonly string pakFolder = @"./Data/Resources/PAK/"; + public static readonly string pakFolder = @"./Data/PAKS/"; /// /// Beta testing folder @@ -50,7 +50,7 @@ namespace PluginManager.Others /// The file name that is inside the archive or its full path /// The archive location from the PAKs folder /// A string that represents the content of the file or null if the file does not exists or it has no content - public static Stream? ReadFromPakAsync(string FileName, string archFile) + public static async Task ReadFromPakAsync(string FileName, string archFile) { archFile = pakFolder + archFile; Directory.CreateDirectory(pakFolder); @@ -58,7 +58,11 @@ namespace PluginManager.Others using ZipArchive archive = ZipFile.OpenRead(archFile); ZipArchiveEntry? entry = archive.GetEntry(FileName); - return entry?.Open(); + if (entry is null) return Stream.Null; + MemoryStream stream = new MemoryStream(); + await (entry?.Open()!).CopyToAsync(stream); + + return stream; } ///