From abc4da1ef8c0227d3cf18c752c8ab68f245dc54c Mon Sep 17 00:00:00 2001 From: That_One_Nerd Date: Thu, 16 Mar 2023 13:25:20 -0400 Subject: [PATCH 1/2] Fixed Issue #2 and did some more stuff. --- SrcMod/Shell/GlobalUsings.cs | 1 + SrcMod/Shell/Modules/BaseModule.cs | 5 +---- .../Shell/Modules/ObjectModels/TypeParsers.cs | 4 ++-- SrcMod/Shell/Shell.cs | 18 ++++++++++++++++-- SrcMod/Shell/Tools.cs | 15 ++++++++++----- 5 files changed, 30 insertions(+), 13 deletions(-) diff --git a/SrcMod/Shell/GlobalUsings.cs b/SrcMod/Shell/GlobalUsings.cs index a019627..42ed4d2 100644 --- a/SrcMod/Shell/GlobalUsings.cs +++ b/SrcMod/Shell/GlobalUsings.cs @@ -5,6 +5,7 @@ global using System; global using System.Collections.Generic; global using System.Diagnostics; global using System.IO; +global using System.IO.Compression; global using System.Linq; global using System.Reflection; global using static SrcMod.Shell.Tools; diff --git a/SrcMod/Shell/Modules/BaseModule.cs b/SrcMod/Shell/Modules/BaseModule.cs index 1edb05d..232745f 100644 --- a/SrcMod/Shell/Modules/BaseModule.cs +++ b/SrcMod/Shell/Modules/BaseModule.cs @@ -1,7 +1,4 @@ -using System.IO; -using System.IO.Compression; - -namespace SrcMod.Shell.Modules; +namespace SrcMod.Shell.Modules; [Module("base", false)] public static class BaseModule diff --git a/SrcMod/Shell/Modules/ObjectModels/TypeParsers.cs b/SrcMod/Shell/Modules/ObjectModels/TypeParsers.cs index cce44b9..954f9be 100644 --- a/SrcMod/Shell/Modules/ObjectModels/TypeParsers.cs +++ b/SrcMod/Shell/Modules/ObjectModels/TypeParsers.cs @@ -23,10 +23,10 @@ public static class TypeParsers if (TryParse(msg, out char resChar)) return resChar; if (TryParse(msg, out DateOnly dateOnly)) return dateOnly; if (TryParse(msg, out DateTime dateTime)) return dateTime; - if (TryParse(msg, out DateTime dateTimeOffset)) return dateTimeOffset; + if (TryParse(msg, out DateTimeOffset dateTimeOffset)) return dateTimeOffset; if (TryParse(msg, out Guid guid)) return guid; if (TryParse(msg, out TimeOnly timeOnly)) return timeOnly; - if (TryParse(msg, out TimeOnly timeSpan)) return timeSpan; + if (TryParse(msg, out TimeSpan timeSpan)) return timeSpan; return msg; } diff --git a/SrcMod/Shell/Shell.cs b/SrcMod/Shell/Shell.cs index 661f7c7..b9add8b 100644 --- a/SrcMod/Shell/Shell.cs +++ b/SrcMod/Shell/Shell.cs @@ -4,7 +4,7 @@ public class Shell { public const string Author = "That_One_Nerd"; public const string Name = "SrcMod"; - public const string Version = "Alpha 0.1.0"; + public const string Version = "Alpha 0.1.1"; public readonly string? ShellDirectory; @@ -44,10 +44,22 @@ public class Shell WorkingDirectory = Directory.GetCurrentDirectory(); // Load modules and commands. + List possibleAsms = new() + { + assembly, + Assembly.GetEntryAssembly(), + Assembly.GetCallingAssembly() + }; + LoadedModules = new(); LoadedCommands = new(); - Type[] possibleModules = assembly.GetTypes(); + List possibleModules = new(); + foreach (Assembly? a in possibleAsms) + { + if (a is null) continue; + possibleModules.AddRange(a.GetTypes().Where(x => !possibleModules.Contains(x))); + } foreach (Type t in possibleModules) { ModuleInfo? module = ModuleInfo.FromModule(t); @@ -166,10 +178,12 @@ public class Shell catch (TargetInvocationException ex) { Write($"[ERROR] {ex.InnerException!.Message}", ConsoleColor.Red); + if (LoadingBarEnabled) LoadingBarEnd(); } catch (Exception ex) { Write($"[ERROR] {ex.Message}", ConsoleColor.Red); + if (LoadingBarEnabled) LoadingBarEnd(); } return; } diff --git a/SrcMod/Shell/Tools.cs b/SrcMod/Shell/Tools.cs index efdd61d..321126e 100644 --- a/SrcMod/Shell/Tools.cs +++ b/SrcMod/Shell/Tools.cs @@ -5,8 +5,10 @@ namespace SrcMod.Shell; public static class Tools { private static int loadingPosition = -1; - private static int lastBufferSize = 0; - private static int lastValue = -1; + private static int lastLoadingBufferSize = 0; + private static int lastLoadingValue = -1; + + public static bool LoadingBarEnabled { get; private set; } public static void DisplayWithPages(IEnumerable lines, ConsoleColor? color = null) { @@ -77,6 +79,7 @@ public static class Tools Console.SetCursorPosition(oldPos.x, oldPos.y); } loadingPosition = -1; + LoadingBarEnabled = false; } public static void LoadingBarSet(float value, ConsoleColor? color = null) { @@ -85,17 +88,18 @@ public static class Tools int barSize = Console.BufferWidth - left.Length - right.Length, filled = (int)(barSize * value); - if (filled == lastValue) return; + if (filled == lastLoadingValue) return; + lastLoadingValue = filled; Int2 oldPos = (Console.CursorLeft, Console.CursorTop); // Erase last bar. Console.SetCursorPosition(0, loadingPosition); - Console.Write(new string(' ', lastBufferSize)); + Console.Write(new string(' ', lastLoadingBufferSize)); Console.CursorLeft = 0; // Add new bar. - lastBufferSize = Console.BufferWidth; + lastLoadingBufferSize = Console.BufferWidth; Write(left, newLine: false); ConsoleColor oldFore = Console.ForegroundColor; @@ -114,6 +118,7 @@ public static class Tools if (loadingPosition != -1) throw new("The loading bar has already been enabled."); loadingPosition = position ?? Console.CursorTop; LoadingBarSet(value, color); + LoadingBarEnabled = true; } public static void Write(object? message, ConsoleColor? col = null, bool newLine = true) From c103a5242a6b267e97c9601e093ac2e951b07214 Mon Sep 17 00:00:00 2001 From: That_One_Nerd Date: Thu, 16 Mar 2023 13:28:21 -0400 Subject: [PATCH 2/2] I'll do the version thing last --- SrcMod/Shell/Shell.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SrcMod/Shell/Shell.cs b/SrcMod/Shell/Shell.cs index b9add8b..1d9464d 100644 --- a/SrcMod/Shell/Shell.cs +++ b/SrcMod/Shell/Shell.cs @@ -4,7 +4,7 @@ public class Shell { public const string Author = "That_One_Nerd"; public const string Name = "SrcMod"; - public const string Version = "Alpha 0.1.1"; + public const string Version = "Alpha 0.1.0"; public readonly string? ShellDirectory;