From 5c8f2406937a3f56220eb322495ac686e1ebfbf1 Mon Sep 17 00:00:00 2001 From: Bitl Date: Fri, 4 Sep 2020 10:41:28 -0700 Subject: [PATCH] updated to code in new snapshot. --- Novetus/NovetusCMD/NovetusCMD.cs | 15 ++++++++----- .../NovetusCore/StorageAndFunctions/NETExt.cs | 15 ++++++++++++- .../NovetusCore/WinForms/TreeNodeHelper.cs | 6 ++--- .../Compact/LauncherFormCompact.cs | 22 +++++++++++-------- .../Extended/LauncherFormExtended.cs | 22 +++++++++++-------- 5 files changed, 53 insertions(+), 27 deletions(-) diff --git a/Novetus/NovetusCMD/NovetusCMD.cs b/Novetus/NovetusCMD/NovetusCMD.cs index e02a18b..c63837f 100644 --- a/Novetus/NovetusCMD/NovetusCMD.cs +++ b/Novetus/NovetusCMD/NovetusCMD.cs @@ -36,7 +36,8 @@ namespace NovetusCMD try { NetFuncs.StartUPnP(device,protocol,port); - GlobalFuncs.ConsolePrint("UPnP: Port " + port + " opened on '" + device.GetExternalIP() + "' (" + protocol.ToString() + ")", 3); + string IP = (!string.IsNullOrWhiteSpace(GlobalVars.UserConfiguration.AlternateServerIP) ? GlobalVars.UserConfiguration.AlternateServerIP : device.GetExternalIP().ToString()); + GlobalFuncs.ConsolePrint("UPnP: Port " + port + " opened on '" + IP + "' (" + protocol.ToString() + ")", 3); } catch (Exception ex) { @@ -52,7 +53,8 @@ namespace NovetusCMD try { NetFuncs.StopUPnP(device,protocol,port); - GlobalFuncs.ConsolePrint("UPnP: Port " + port + " closed on '" + device.GetExternalIP() + "' (" + protocol.ToString() + ")", 3); + string IP = (!string.IsNullOrWhiteSpace(GlobalVars.UserConfiguration.AlternateServerIP) ? GlobalVars.UserConfiguration.AlternateServerIP : device.GetExternalIP().ToString()); + GlobalFuncs.ConsolePrint("UPnP: Port " + port + " closed on '" + IP + "' (" + protocol.ToString() + ")", 3); } catch (Exception ex) { @@ -66,7 +68,8 @@ namespace NovetusCMD try { INatDevice device = args.Device; - GlobalFuncs.ConsolePrint("UPnP: Device '" + device.GetExternalIP() + "' registered.", 3); + string IP = (!string.IsNullOrWhiteSpace(GlobalVars.UserConfiguration.AlternateServerIP) ? GlobalVars.UserConfiguration.AlternateServerIP : device.GetExternalIP().ToString()); + GlobalFuncs.ConsolePrint("UPnP: Device '" + IP + "' registered.", 3); StartUPnP(device, Protocol.Udp, GlobalVars.UserConfiguration.RobloxPort); StartUPnP(device, Protocol.Tcp, GlobalVars.UserConfiguration.RobloxPort); StartUPnP(device, Protocol.Udp, GlobalVars.UserConfiguration.WebServerPort); @@ -83,7 +86,8 @@ namespace NovetusCMD try { INatDevice device = args.Device; - GlobalFuncs.ConsolePrint("UPnP: Device '" + device.GetExternalIP() + "' disconnected.", 3); + string IP = (!string.IsNullOrWhiteSpace(GlobalVars.UserConfiguration.AlternateServerIP) ? GlobalVars.UserConfiguration.AlternateServerIP : device.GetExternalIP().ToString()); + GlobalFuncs.ConsolePrint("UPnP: Device '" + IP + "' disconnected.", 3); StopUPnP(device, Protocol.Udp, GlobalVars.UserConfiguration.RobloxPort); StopUPnP(device, Protocol.Tcp, GlobalVars.UserConfiguration.RobloxPort); StopUPnP(device, Protocol.Udp, GlobalVars.UserConfiguration.WebServerPort); @@ -196,7 +200,7 @@ namespace NovetusCMD LoadOverrideINIArgs(args); InitUPnP(); - if (!GlobalVars.UserConfiguration.WebServer) + if (GlobalVars.UserConfiguration.WebServer) { StartWebServer(); } @@ -317,6 +321,7 @@ namespace NovetusCMD if (CommandLine["map"] != null) { LocalVars.OverrideINI = true; + GlobalVars.UserConfiguration.Map = CommandLine["map"]; GlobalVars.UserConfiguration.MapPath = CommandLine["map"]; GlobalFuncs.ConsolePrint("NovetusCMD will now launch the server with the map " + GlobalVars.UserConfiguration.MapPath, 4); } diff --git a/Novetus/NovetusCore/StorageAndFunctions/NETExt.cs b/Novetus/NovetusCore/StorageAndFunctions/NETExt.cs index 59f0702..9e6439f 100644 --- a/Novetus/NovetusCore/StorageAndFunctions/NETExt.cs +++ b/Novetus/NovetusCore/StorageAndFunctions/NETExt.cs @@ -5,6 +5,9 @@ using System.Windows.Forms; using System.Diagnostics; using System.Security.Cryptography; using System.Text; +using System.IO; +using System.Collections.Generic; +using System.Linq; #endregion #region .NET Extentions @@ -162,7 +165,7 @@ public static class NETExt } #endregion - #region Exeption Helpers + #region Exception Helpers //https://github.com/AlexMelw/EasySharp/blob/master/NHelpers/ExceptionsDealing/Extensions/ExceptionExtensions.cs /// /// Gets the entire stack trace consisting of exception's footprints (File, Method, LineNumber) @@ -209,5 +212,15 @@ public static class NETExt return stackTraceFootprints; } #endregion + + #region DirectoryInfo Extensions + public static IEnumerable GetFilesByExtensions(this DirectoryInfo dir, params string[] extensions) + { + if (extensions == null) + throw new ArgumentNullException("extensions"); + IEnumerable files = dir.EnumerateFiles(); + return files.Where(f => extensions.Contains(f.Extension)); + } + #endregion } #endregion \ No newline at end of file diff --git a/Novetus/NovetusCore/WinForms/TreeNodeHelper.cs b/Novetus/NovetusCore/WinForms/TreeNodeHelper.cs index 1e8da8b..2232705 100644 --- a/Novetus/NovetusCore/WinForms/TreeNodeHelper.cs +++ b/Novetus/NovetusCore/WinForms/TreeNodeHelper.cs @@ -9,19 +9,19 @@ using System.Windows.Forms; #region Tree Node Helper public static class TreeNodeHelper { - public static void ListDirectory(TreeView treeView, string path, string filter = ".*") + public static void ListDirectory(TreeView treeView, string path, string[] filter) { treeView.Nodes.Clear(); var rootDirectoryInfo = new DirectoryInfo(path); treeView.Nodes.Add(CreateDirectoryNode(rootDirectoryInfo, filter)); } - public static TreeNode CreateDirectoryNode(DirectoryInfo directoryInfo, string filter = ".*") + public static TreeNode CreateDirectoryNode(DirectoryInfo directoryInfo, string[] filter) { var directoryNode = new TreeNode(directoryInfo.Name); foreach (var directory in directoryInfo.GetDirectories()) directoryNode.Nodes.Add(CreateDirectoryNode(directory, filter)); - foreach (var file in directoryInfo.GetFiles("*" + filter)) + foreach (var file in directoryInfo.GetFilesByExtensions(filter)) directoryNode.Nodes.Add(new TreeNode(file.Name)); return directoryNode; } diff --git a/Novetus/NovetusLauncher/Forms/LauncherForm/Compact/LauncherFormCompact.cs b/Novetus/NovetusLauncher/Forms/LauncherForm/Compact/LauncherFormCompact.cs index d677d76..bc6539d 100644 --- a/Novetus/NovetusLauncher/Forms/LauncherForm/Compact/LauncherFormCompact.cs +++ b/Novetus/NovetusLauncher/Forms/LauncherForm/Compact/LauncherFormCompact.cs @@ -54,7 +54,8 @@ namespace NovetusLauncher try { NetFuncs.StartUPnP(device, protocol, port); - GlobalFuncs.ConsolePrint("UPnP: Port " + port + " opened on '" + device.GetExternalIP() + "' (" + protocol.ToString() + ")", 3, richTextBox1); + string IP = (!string.IsNullOrWhiteSpace(GlobalVars.UserConfiguration.AlternateServerIP) ? GlobalVars.UserConfiguration.AlternateServerIP : device.GetExternalIP().ToString()); + GlobalFuncs.ConsolePrint("UPnP: Port " + port + " opened on '" + IP + "' (" + protocol.ToString() + ")", 3, richTextBox1); } catch (Exception ex) { @@ -70,7 +71,8 @@ namespace NovetusLauncher try { NetFuncs.StopUPnP(device, protocol, port); - GlobalFuncs.ConsolePrint("UPnP: Port " + port + " closed on '" + device.GetExternalIP() + "' (" + protocol.ToString() + ")", 3, richTextBox1); + string IP = (!string.IsNullOrWhiteSpace(GlobalVars.UserConfiguration.AlternateServerIP) ? GlobalVars.UserConfiguration.AlternateServerIP : device.GetExternalIP().ToString()); + GlobalFuncs.ConsolePrint("UPnP: Port " + port + " closed on '" + IP + "' (" + protocol.ToString() + ")", 3, richTextBox1); } catch (Exception ex) { @@ -84,7 +86,8 @@ namespace NovetusLauncher try { INatDevice device = args.Device; - GlobalFuncs.ConsolePrint("UPnP: Device '" + device.GetExternalIP() + "' registered.", 3, richTextBox1); + string IP = (!string.IsNullOrWhiteSpace(GlobalVars.UserConfiguration.AlternateServerIP) ? GlobalVars.UserConfiguration.AlternateServerIP : device.GetExternalIP().ToString()); + GlobalFuncs.ConsolePrint("UPnP: Device '" + IP + "' registered.", 3, richTextBox1); StartUPnP(device, Protocol.Udp, GlobalVars.UserConfiguration.RobloxPort); StartUPnP(device, Protocol.Tcp, GlobalVars.UserConfiguration.RobloxPort); StartUPnP(device, Protocol.Udp, GlobalVars.UserConfiguration.WebServerPort); @@ -101,7 +104,8 @@ namespace NovetusLauncher try { INatDevice device = args.Device; - GlobalFuncs.ConsolePrint("UPnP: Device '" + device.GetExternalIP() + "' disconnected.", 3, richTextBox1); + string IP = (!string.IsNullOrWhiteSpace(GlobalVars.UserConfiguration.AlternateServerIP) ? GlobalVars.UserConfiguration.AlternateServerIP : device.GetExternalIP().ToString()); + GlobalFuncs.ConsolePrint("UPnP: Device '" + IP + "' disconnected.", 3, richTextBox1); StopUPnP(device, Protocol.Udp, GlobalVars.UserConfiguration.RobloxPort); StopUPnP(device, Protocol.Tcp, GlobalVars.UserConfiguration.RobloxPort); StopUPnP(device, Protocol.Udp, GlobalVars.UserConfiguration.WebServerPort); @@ -260,8 +264,8 @@ namespace NovetusLauncher break; case TabPage pg4 when pg4 == tabControl1.TabPages["tabPage4"]: string mapdir = GlobalPaths.MapsDir; - TreeNodeHelper.ListDirectory(treeView1, mapdir, ".rbxl"); - TreeNodeHelper.ListDirectory(treeView1, mapdir, ".rbxlx"); + string[] fileexts = new string[] { ".rbxl", ".rbxlx"}; + TreeNodeHelper.ListDirectory(treeView1, mapdir, fileexts); TreeNodeHelper.CopyNodes(treeView1.Nodes, _fieldsTreeCache.Nodes); treeView1.SelectedNode = TreeNodeHelper.SearchTreeView(GlobalVars.UserConfiguration.Map, treeView1.Nodes); treeView1.Focus(); @@ -419,7 +423,7 @@ namespace NovetusLauncher ReadConfigValues(true); InitUPnP(); StartDiscord(); - if (!GlobalVars.UserConfiguration.WebServer) + if (GlobalVars.UserConfiguration.WebServer) { StartWebServer(); } @@ -1070,8 +1074,8 @@ namespace NovetusLauncher treeView1.Nodes.Clear(); _fieldsTreeCache.Nodes.Clear(); string mapdir = GlobalPaths.MapsDir; - TreeNodeHelper.ListDirectory(treeView1, mapdir, ".rbxl"); - TreeNodeHelper.ListDirectory(treeView1, mapdir, ".rbxlx"); + string[] fileexts = new string[] { ".rbxl", ".rbxlx" }; + TreeNodeHelper.ListDirectory(treeView1, mapdir, fileexts); TreeNodeHelper.CopyNodes(treeView1.Nodes, _fieldsTreeCache.Nodes); treeView1.SelectedNode = TreeNodeHelper.SearchTreeView(GlobalVars.UserConfiguration.Map, treeView1.Nodes); treeView1.Focus(); diff --git a/Novetus/NovetusLauncher/Forms/LauncherForm/Extended/LauncherFormExtended.cs b/Novetus/NovetusLauncher/Forms/LauncherForm/Extended/LauncherFormExtended.cs index efb46cc..26d11db 100644 --- a/Novetus/NovetusLauncher/Forms/LauncherForm/Extended/LauncherFormExtended.cs +++ b/Novetus/NovetusLauncher/Forms/LauncherForm/Extended/LauncherFormExtended.cs @@ -58,7 +58,8 @@ namespace NovetusLauncher try { NetFuncs.StartUPnP(device, protocol, port); - GlobalFuncs.ConsolePrint("UPnP: Port " + port + " opened on '" + device.GetExternalIP() + "' (" + protocol.ToString() + ")", 3, richTextBox1); + string IP = (!string.IsNullOrWhiteSpace(GlobalVars.UserConfiguration.AlternateServerIP) ? GlobalVars.UserConfiguration.AlternateServerIP : device.GetExternalIP().ToString()); + GlobalFuncs.ConsolePrint("UPnP: Port " + port + " opened on '" + IP + "' (" + protocol.ToString() + ")", 3, richTextBox1); } catch (Exception ex) { @@ -74,7 +75,8 @@ namespace NovetusLauncher try { NetFuncs.StopUPnP(device, protocol, port); - GlobalFuncs.ConsolePrint("UPnP: Port " + port + " closed on '" + device.GetExternalIP() + "' (" + protocol.ToString() + ")", 3, richTextBox1); + string IP = (!string.IsNullOrWhiteSpace(GlobalVars.UserConfiguration.AlternateServerIP) ? GlobalVars.UserConfiguration.AlternateServerIP : device.GetExternalIP().ToString()); + GlobalFuncs.ConsolePrint("UPnP: Port " + port + " closed on '" + IP + "' (" + protocol.ToString() + ")", 3, richTextBox1); } catch (Exception ex) { @@ -88,7 +90,8 @@ namespace NovetusLauncher try { INatDevice device = args.Device; - GlobalFuncs.ConsolePrint("UPnP: Device '" + device.GetExternalIP() + "' registered.", 3, richTextBox1); + string IP = (!string.IsNullOrWhiteSpace(GlobalVars.UserConfiguration.AlternateServerIP) ? GlobalVars.UserConfiguration.AlternateServerIP : device.GetExternalIP().ToString()); + GlobalFuncs.ConsolePrint("UPnP: Device '" + IP + "' registered.", 3, richTextBox1); StartUPnP(device, Protocol.Udp, GlobalVars.UserConfiguration.RobloxPort); StartUPnP(device, Protocol.Tcp, GlobalVars.UserConfiguration.RobloxPort); StartUPnP(device, Protocol.Udp, GlobalVars.UserConfiguration.WebServerPort); @@ -105,7 +108,8 @@ namespace NovetusLauncher try { INatDevice device = args.Device; - GlobalFuncs.ConsolePrint("UPnP: Device '" + device.GetExternalIP() + "' disconnected.", 3, richTextBox1); + string IP = (!string.IsNullOrWhiteSpace(GlobalVars.UserConfiguration.AlternateServerIP) ? GlobalVars.UserConfiguration.AlternateServerIP : device.GetExternalIP().ToString()); + GlobalFuncs.ConsolePrint("UPnP: Device '" + IP + "' disconnected.", 3, richTextBox1); StopUPnP(device, Protocol.Udp, GlobalVars.UserConfiguration.RobloxPort); StopUPnP(device, Protocol.Tcp, GlobalVars.UserConfiguration.RobloxPort); StopUPnP(device, Protocol.Udp, GlobalVars.UserConfiguration.WebServerPort); @@ -264,8 +268,8 @@ namespace NovetusLauncher break; case TabPage pg4 when pg4 == tabControl1.TabPages["tabPage4"]: string mapdir = GlobalPaths.MapsDir; - TreeNodeHelper.ListDirectory(treeView1, mapdir, ".rbxl"); - TreeNodeHelper.ListDirectory(treeView1, mapdir, ".rbxlx"); + string[] fileexts = new string[] { ".rbxl", ".rbxlx" }; + TreeNodeHelper.ListDirectory(treeView1, mapdir, fileexts); TreeNodeHelper.CopyNodes(treeView1.Nodes, _fieldsTreeCache.Nodes); treeView1.SelectedNode = TreeNodeHelper.SearchTreeView(GlobalVars.UserConfiguration.Map, treeView1.Nodes); treeView1.Focus(); @@ -451,7 +455,7 @@ namespace NovetusLauncher ReadConfigValues(true); InitUPnP(); StartDiscord(); - if (!GlobalVars.UserConfiguration.WebServer) + if (GlobalVars.UserConfiguration.WebServer) { StartWebServer(); } @@ -1143,8 +1147,8 @@ namespace NovetusLauncher treeView1.Nodes.Clear(); _fieldsTreeCache.Nodes.Clear(); string mapdir = GlobalPaths.MapsDir; - TreeNodeHelper.ListDirectory(treeView1, mapdir, ".rbxl"); - TreeNodeHelper.ListDirectory(treeView1, mapdir, ".rbxlx"); + string[] fileexts = new string[] { ".rbxl", ".rbxlx" }; + TreeNodeHelper.ListDirectory(treeView1, mapdir, fileexts); TreeNodeHelper.CopyNodes(treeView1.Nodes,_fieldsTreeCache.Nodes); treeView1.SelectedNode = TreeNodeHelper.SearchTreeView(GlobalVars.UserConfiguration.Map, treeView1.Nodes); treeView1.Focus();