From 79ecfafeb5f3e68b86884a68617f74a26fd71f65 Mon Sep 17 00:00:00 2001 From: Bitl Date: Fri, 6 Jan 2023 12:03:47 -0700 Subject: [PATCH] improved console/extension reliability --- Novetus/NovetusCore/Classes/WebProxy.cs | 11 +++-- .../StorageAndFunctions/GlobalPaths.cs | 1 + .../StorageAndFunctions/NetFuncs.cs | 11 +++++ .../NovetusCore/StorageAndFunctions/Util.cs | 43 ++++++++----------- .../NovetusLauncher/Forms/NovetusConsole.cs | 11 +++-- 5 files changed, 43 insertions(+), 34 deletions(-) diff --git a/Novetus/NovetusCore/Classes/WebProxy.cs b/Novetus/NovetusCore/Classes/WebProxy.cs index cd7f0eb..cbb8f05 100644 --- a/Novetus/NovetusCore/Classes/WebProxy.cs +++ b/Novetus/NovetusCore/Classes/WebProxy.cs @@ -22,10 +22,9 @@ namespace Novetus.Core public virtual bool IsValidURL(string absolutePath, string host) { return false; } public virtual Task OnBeforeTunnelConnectRequest(object sender, TunnelConnectSessionEventArgs e) { return Task.CompletedTask; } - public virtual Task OnRequest(object sender, SessionEventArgs e) + public virtual async Task OnRequest(object sender, SessionEventArgs e) { e.Ok("Test successful. \nRunning Novetus " + GlobalVars.ProgramInformation.Version + " on " + GlobalVars.ProgramInformation.NetVersion); - return Task.CompletedTask; } } @@ -227,7 +226,7 @@ namespace Novetus.Core } else { - e.DecryptSsl = false; + continue; } } } @@ -255,9 +254,13 @@ namespace Novetus.Core catch (Exception) { e.GenericResponse("", HttpStatusCode.InternalServerError); - return; + continue; } } + else + { + continue; + } } e.GenericResponse("", HttpStatusCode.NotFound); diff --git a/Novetus/NovetusCore/StorageAndFunctions/GlobalPaths.cs b/Novetus/NovetusCore/StorageAndFunctions/GlobalPaths.cs index 6373c1f..c34341d 100644 --- a/Novetus/NovetusCore/StorageAndFunctions/GlobalPaths.cs +++ b/Novetus/NovetusCore/StorageAndFunctions/GlobalPaths.cs @@ -15,6 +15,7 @@ namespace Novetus.Core public static readonly string RootPath = Directory.GetParent(RootPathLauncher).ToString(); public static readonly string BasePath = RootPath.Replace(@"\", @"\\"); public static readonly string DataPath = BasePath + @"\\shareddata"; + public static readonly string AssetsPath = BasePath + @"\\assets"; public static readonly string BinDir = BasePath + @"\\bin"; public static readonly string ConfigDir = BasePath + @"\\config"; public static readonly string LogDir = BasePath + @"\\logs"; diff --git a/Novetus/NovetusCore/StorageAndFunctions/NetFuncs.cs b/Novetus/NovetusCore/StorageAndFunctions/NetFuncs.cs index 7695849..292ca75 100644 --- a/Novetus/NovetusCore/StorageAndFunctions/NetFuncs.cs +++ b/Novetus/NovetusCore/StorageAndFunctions/NetFuncs.cs @@ -2,6 +2,7 @@ #region Usings using Mono.Nat; using System; +using System.Web; #endregion namespace Novetus.Core @@ -50,6 +51,16 @@ namespace Novetus.Core } } } + + public static string FindQueryString(Uri uri, string searchQuery) + { + return FindQueryString(uri.Query, searchQuery); + } + + public static string FindQueryString(string query, string searchQuery) + { + return HttpUtility.ParseQueryString(query)[searchQuery]; + } } #endregion } diff --git a/Novetus/NovetusCore/StorageAndFunctions/Util.cs b/Novetus/NovetusCore/StorageAndFunctions/Util.cs index e0237d7..3ba1ef1 100644 --- a/Novetus/NovetusCore/StorageAndFunctions/Util.cs +++ b/Novetus/NovetusCore/StorageAndFunctions/Util.cs @@ -44,7 +44,7 @@ namespace Novetus.Core box.SelectionColor = color; box.AppendText(text); - box.SelectionColor = box.ForeColor; + //box.SelectionColor = box.ForeColor; } #endregion @@ -592,7 +592,7 @@ namespace Novetus.Core { string message = (ex.Message != null ? ex.Message.ToString() : "N/A"); - ConsolePrint(ex.Source + " Exception: " + message, 2, false, true); + ConsolePrint(ex.Source + " Exception: " + message, 2, true); LogPrint("EXCEPTION|MESSAGE: " + message, 2); LogPrint("EXCEPTION|STACK TRACE: " + (!string.IsNullOrWhiteSpace(ex.StackTrace) ? ex.StackTrace : "N/A"), 2); @@ -680,13 +680,8 @@ namespace Novetus.Core return (p <= 0); } - public static void ConsolePrint(string text, int type = 1, bool notime = false, bool noLog = false) + public static void ConsolePrint(string text, int type = 1, bool noLog = false) { - if (!notime) - { - ConsoleText("[" + DateTime.Now.ToShortTimeString() + "] - ", ConsoleColor.White); - } - switch (type) { case 0: @@ -721,20 +716,20 @@ namespace Novetus.Core } #if LAUNCHER - if (GlobalVars.consoleForm != null) - { - FormPrint(text, type, GlobalVars.consoleForm.ConsoleBox, notime); - } + if (GlobalVars.consoleForm != null) + { + FormPrint(text, type, GlobalVars.consoleForm.ConsoleBox); + } #endif } - public static void ConsolePrintMultiLine(string text, int type = 1, bool notime = false, bool noLog = false) + public static void ConsolePrintMultiLine(string text, int type = 1, bool noLog = false) { try { string[] NewlineChars = { Environment.NewLine, "\n" }; string[] lines = text.Split(NewlineChars, StringSplitOptions.None); - ConsolePrintMultiLine(lines, type, notime, noLog); + ConsolePrintMultiLine(lines, type, noLog); } catch (Exception e) { @@ -744,33 +739,35 @@ namespace Novetus.Core } } - public static void ConsolePrintMultiLine(ICollection textColection, int type = 1, bool notime = false, bool noLog = false) + public static void ConsolePrintMultiLine(ICollection textColection, int type = 1, bool noLog = false) { if (!textColection.Any()) return; if (textColection.Count == 1) { - ConsolePrint(textColection.First(), type, notime, noLog); + ConsolePrint(textColection.First(), type, noLog); return; } foreach (string text in textColection) { - ConsolePrint(text, type, notime, noLog); + ConsolePrint(text, type, noLog); } } - private static void FormPrint(string text, int type, RichTextBox box, bool noTime = false) + private static void FormPrint(string text, int type, RichTextBox box) { if (box == null) return; - if (!noTime) + foreach (string line in box.Lines) { - box.AppendText("[" + DateTime.Now.ToShortTimeString() + "] - ", Color.White); + Regex.Replace(line, @"^\s+$[\r\n]*", "", RegexOptions.Multiline); } + box.AppendText("\r\n", Color.White); + switch (type) { case 1: @@ -793,8 +790,6 @@ namespace Novetus.Core box.AppendText(text, Color.Black); break; } - - box.AppendText(Environment.NewLine, Color.White); } private static void ConsoleText(string text, ConsoleColor color, bool newLine = false) @@ -818,11 +813,11 @@ namespace Novetus.Core try { string[] vals = line.Split('|'); - ConsolePrint(vals[0], Convert.ToInt32(vals[1]), true, true); + ConsolePrint(vals[0], Convert.ToInt32(vals[1]), true); } catch (Exception) { - ConsolePrint(line, 1, true, true); + ConsolePrint(line, 1, true); } } } diff --git a/Novetus/NovetusLauncher/Forms/NovetusConsole.cs b/Novetus/NovetusLauncher/Forms/NovetusConsole.cs index 3d11775..1021212 100644 --- a/Novetus/NovetusLauncher/Forms/NovetusConsole.cs +++ b/Novetus/NovetusLauncher/Forms/NovetusConsole.cs @@ -441,16 +441,16 @@ namespace NovetusLauncher public void ConsoleHelp() { ClearConsole(); - Util.ConsolePrint("Help:", 3, true, true); + Util.ConsolePrint("Help:", 3, true); Util.ReadTextFileWithColor(GlobalPaths.BasePath + "\\" + GlobalPaths.ConsoleHelpFileName); - Util.ConsolePrint(GlobalVars.Important2, 0, true, true); + Util.ConsolePrint(GlobalVars.Important2, 0, true); ScrollToTop(); } public void ClientScriptDoc() { ClearConsole(); - Util.ConsolePrint("ClientScript Documentation:", 3, true, true); + Util.ConsolePrint("ClientScript Documentation:", 3, true); Util.ReadTextFileWithColor(GlobalPaths.BasePath + "\\" + GlobalPaths.ClientScriptDocumentationFileName); ScrollToTop(); } @@ -476,7 +476,6 @@ namespace NovetusLauncher if (e.KeyCode == Keys.Enter) { - ConsoleBox.AppendText(Environment.NewLine, Color.White); ConsoleProcessCommands(lastLine); e.Handled = true; } @@ -499,8 +498,8 @@ namespace NovetusLauncher private void ClearConsole() { ConsoleBox.Text = ""; - ConsoleBox.SelectionStart = 0; - ConsoleBox.ScrollToCaret(); + ScrollToTop(); + Console.Clear(); } private void ScrollToTop()