From 1cf0758ef01783e64892997f9aba25ff45685ab5 Mon Sep 17 00:00:00 2001 From: Bitl Date: Mon, 22 Mar 2021 15:28:22 -0700 Subject: [PATCH] revert compact to stuff that doesn't break for now. implement style detection --- .../Compact/LauncherFormCompact.cs | 203 +++++++++++++++++ .../Extended/LauncherFormExtended.cs | 211 ++---------------- .../Forms/LauncherFormShared.cs | 211 +++++++++++++++++- 3 files changed, 425 insertions(+), 200 deletions(-) diff --git a/Novetus/NovetusLauncher/Forms/LauncherForm/Compact/LauncherFormCompact.cs b/Novetus/NovetusLauncher/Forms/LauncherForm/Compact/LauncherFormCompact.cs index 779f662..e41a3f3 100644 --- a/Novetus/NovetusLauncher/Forms/LauncherForm/Compact/LauncherFormCompact.cs +++ b/Novetus/NovetusLauncher/Forms/LauncherForm/Compact/LauncherFormCompact.cs @@ -15,6 +15,13 @@ namespace NovetusLauncher #region LauncherForm - Compact public partial class LauncherFormCompact : Form { + #region Private Variables + private DiscordRPC.EventHandlers handlers; + private List CurrentNodeMatches = new List(); + private int LastNodeIndex = 0; + private string LastSearchText; + #endregion + #region Constructor public LauncherFormCompact() { @@ -23,6 +30,183 @@ namespace NovetusLauncher } #endregion + #region UPnP + public void InitUPnP() + { + if (GlobalVars.UserConfiguration.UPnP) + { + try + { + NetFuncs.InitUPnP(DeviceFound, DeviceLost); + GlobalFuncs.ConsolePrint("UPnP: Service initialized", 3, richTextBox1); + } + catch (Exception ex) + { + GlobalFuncs.ConsolePrint("UPnP: Unable to initialize UPnP. Reason - " + ex.Message, 2, richTextBox1); + } + } + } + + public void StartUPnP(INatDevice device, Protocol protocol, int port) + { + if (GlobalVars.UserConfiguration.UPnP) + { + try + { + NetFuncs.StartUPnP(device, protocol, port); + 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) + { + GlobalFuncs.ConsolePrint("UPnP: Unable to open port mapping. Reason - " + ex.Message, 2, richTextBox1); + } + } + } + + public void StopUPnP(INatDevice device, Protocol protocol, int port) + { + if (GlobalVars.UserConfiguration.UPnP) + { + try + { + NetFuncs.StopUPnP(device, protocol, port); + 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) + { + GlobalFuncs.ConsolePrint("UPnP: Unable to close port mapping. Reason - " + ex.Message, 2, richTextBox1); + } + } + } + + private void DeviceFound(object sender, DeviceEventArgs args) + { + try + { + INatDevice device = args.Device; + 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); + StartUPnP(device, Protocol.Tcp, GlobalVars.UserConfiguration.WebServerPort); + } + catch (Exception ex) + { + GlobalFuncs.ConsolePrint("UPnP: Unable to register device. Reason - " + ex.Message, 2, richTextBox1); + } + } + + private void DeviceLost(object sender, DeviceEventArgs args) + { + try + { + INatDevice device = args.Device; + 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); + StopUPnP(device, Protocol.Tcp, GlobalVars.UserConfiguration.WebServerPort); + } + catch (Exception ex) + { + GlobalFuncs.ConsolePrint("UPnP: Unable to disconnect device. Reason - " + ex.Message, 2, richTextBox1); + } + } + #endregion + + #region Discord + public void ReadyCallback() + { + GlobalFuncs.ConsolePrint("Discord RPC: Ready", 3, richTextBox1); + } + + public void DisconnectedCallback(int errorCode, string message) + { + GlobalFuncs.ConsolePrint("Discord RPC: Disconnected. Reason - " + errorCode + ": " + message, 2, richTextBox1); + } + + public void ErrorCallback(int errorCode, string message) + { + GlobalFuncs.ConsolePrint("Discord RPC: Error. Reason - " + errorCode + ": " + message, 2, richTextBox1); + } + + public void JoinCallback(string secret) + { + } + + public void SpectateCallback(string secret) + { + } + + public void RequestCallback(DiscordRPC.JoinRequest request) + { + } + + void StartDiscord() + { + if (GlobalVars.UserConfiguration.DiscordPresence) + { + handlers = new DiscordRPC.EventHandlers(); + handlers.readyCallback = ReadyCallback; + handlers.disconnectedCallback += DisconnectedCallback; + handlers.errorCallback += ErrorCallback; + handlers.joinCallback += JoinCallback; + handlers.spectateCallback += SpectateCallback; + handlers.requestCallback += RequestCallback; + DiscordRPC.Initialize(GlobalVars.appid, ref handlers, true, ""); + + GlobalFuncs.UpdateRichPresence(GlobalVars.LauncherState.InLauncher, "", true); + } + } + #endregion + + #region Web Server + //udp clients will connect to the web server alongside the game. + void StartWebServer() + { + if (SecurityFuncs.IsElevated) + { + try + { + GlobalVars.WebServer = new SimpleHTTPServer(GlobalPaths.DataPath, GlobalVars.UserConfiguration.WebServerPort); + GlobalFuncs.ConsolePrint("WebServer: Server is running on port: " + GlobalVars.WebServer.Port.ToString(), 3, richTextBox1); + } + catch (Exception ex) + { + GlobalFuncs.ConsolePrint("WebServer: Failed to launch WebServer. Some features may not function. (" + ex.Message + ")", 2, richTextBox1); + } + } + else + { + GlobalFuncs.ConsolePrint("WebServer: Failed to launch WebServer. Some features may not function. (Did not run as Administrator)", 2, richTextBox1); + } + } + + void StopWebServer() + { + if (SecurityFuncs.IsElevated) + { + try + { + GlobalFuncs.ConsolePrint("WebServer: Server has stopped on port: " + GlobalVars.WebServer.Port.ToString(), 2, richTextBox1); + GlobalVars.WebServer.Stop(); + } + catch (Exception ex) + { + GlobalFuncs.ConsolePrint("WebServer: Failed to stop WebServer. Some features may not function. (" + ex.Message + ")", 2, richTextBox1); + } + } + else + { + GlobalFuncs.ConsolePrint("WebServer: Failed to stop WebServer. Some features may not function. (Did not run as Administrator)", 2, richTextBox1); + } + } + #endregion + #region Form Events async void tabControl1_SelectedIndexChanged(object sender, EventArgs e) { @@ -1156,6 +1340,25 @@ namespace NovetusLauncher GlobalVars.UserConfiguration.ShowServerNotifications = checkBox9.Checked; } #endregion + + #region Functions + private void SearchNodes(string SearchText, TreeNode StartNode) + { + while (StartNode != null) + { + if (StartNode.Text.ToLower().Contains(SearchText.ToLower())) + { + CurrentNodeMatches.Add(StartNode); + }; + if (StartNode.Nodes.Count != 0) + { + SearchNodes(SearchText, StartNode.Nodes[0]);//Recursive Search + }; + StartNode = StartNode.NextNode; + }; + + } + #endregion } #endregion } diff --git a/Novetus/NovetusLauncher/Forms/LauncherForm/Extended/LauncherFormExtended.cs b/Novetus/NovetusLauncher/Forms/LauncherForm/Extended/LauncherFormExtended.cs index ddc71a1..3f2ef9e 100644 --- a/Novetus/NovetusLauncher/Forms/LauncherForm/Extended/LauncherFormExtended.cs +++ b/Novetus/NovetusLauncher/Forms/LauncherForm/Extended/LauncherFormExtended.cs @@ -28,6 +28,7 @@ namespace NovetusLauncher //*vomits* launcherForm = new LauncherFormShared(); launcherForm.Parent = this; + launcherForm.FormStyle = Settings.UIOptions.Style.Extended; launcherForm.ConsoleBox = richTextBox1; launcherForm.Tabs = tabControl1; launcherForm.MapDescBox = textBox4; @@ -43,7 +44,9 @@ namespace NovetusLauncher launcherForm.ClientBox = listBox2; launcherForm.SplashLabel = label12; launcherForm.SearchBar = SearchBar; - + launcherForm.StyleSelectorBox = comboBox3; + launcherForm.ChangelogBox = richTextBox2; + launcherForm.ReadmeBox = richTextBox3; Size = new Size(745, 377); panel2.Size = new Size(646, 272); @@ -95,164 +98,6 @@ namespace NovetusLauncher { launcherForm.CloseEvent(); } - - void ReadConfigValues(bool initial = false) - { - GlobalFuncs.Config(GlobalPaths.ConfigDir + "\\" + GlobalPaths.ConfigName, false); - - checkBox1.Checked = GlobalVars.UserConfiguration.CloseOnLaunch; - textBox5.Text = GlobalVars.UserConfiguration.UserID.ToString(); - label18.Text = GlobalVars.UserConfiguration.PlayerTripcode.ToString(); - numericUpDown3.Value = Convert.ToDecimal(GlobalVars.UserConfiguration.PlayerLimit); - textBox2.Text = GlobalVars.UserConfiguration.PlayerName; - label26.Text = GlobalVars.UserConfiguration.SelectedClient; - label28.Text = GlobalVars.UserConfiguration.Map; - treeView1.SelectedNode = TreeNodeHelper.SearchTreeView(GlobalVars.UserConfiguration.Map, treeView1.Nodes); - treeView1.Focus(); - numericUpDown1.Value = Convert.ToDecimal(GlobalVars.UserConfiguration.RobloxPort); - numericUpDown2.Value = Convert.ToDecimal(GlobalVars.UserConfiguration.RobloxPort); - label37.Text = GlobalVars.IP; - label38.Text = GlobalVars.UserConfiguration.RobloxPort.ToString(); - checkBox2.Checked = GlobalVars.UserConfiguration.DiscordPresence; - checkBox5.Checked = GlobalVars.UserConfiguration.ReShade; - checkBox6.Checked = GlobalVars.UserConfiguration.ReShadeFPSDisplay; - checkBox7.Checked = GlobalVars.UserConfiguration.ReShadePerformanceMode; - checkBox4.Checked = GlobalVars.UserConfiguration.UPnP; - checkBox9.Checked = GlobalVars.UserConfiguration.ShowServerNotifications; - - if (SecurityFuncs.IsElevated) - { - checkBox8.Enabled = true; - checkBox8.Checked = GlobalVars.UserConfiguration.WebServer; - } - else - { - checkBox8.Enabled = false; - } - - switch (GlobalVars.UserConfiguration.GraphicsMode) - { - case Settings.GraphicsOptions.Mode.OpenGL: - comboBox1.SelectedIndex = 1; - break; - case Settings.GraphicsOptions.Mode.DirectX: - comboBox1.SelectedIndex = 2; - break; - default: - comboBox1.SelectedIndex = 0; - break; - } - - switch (GlobalVars.UserConfiguration.QualityLevel) - { - case Settings.GraphicsOptions.Level.VeryLow: - comboBox2.SelectedIndex = 1; - break; - case Settings.GraphicsOptions.Level.Low: - comboBox2.SelectedIndex = 2; - break; - case Settings.GraphicsOptions.Level.Medium: - comboBox2.SelectedIndex = 3; - break; - case Settings.GraphicsOptions.Level.High: - comboBox2.SelectedIndex = 4; - break; - case Settings.GraphicsOptions.Level.Ultra: - comboBox2.SelectedIndex = 5; - break; - case Settings.GraphicsOptions.Level.Custom: - comboBox2.SelectedIndex = 6; - break; - default: - comboBox2.SelectedIndex = 0; - break; - } - - switch (GlobalVars.UserConfiguration.LauncherStyle) - { - case Settings.UIOptions.Style.Compact: - comboBox3.SelectedIndex = 1; - break; - case Settings.UIOptions.Style.Extended: - default: - comboBox3.SelectedIndex = 0; - break; - } - - GlobalFuncs.ConsolePrint("Config loaded.", 3, richTextBox1); - ReadClientValues(initial); - } - - void WriteConfigValues() - { - GlobalFuncs.Config(GlobalPaths.ConfigDir + "\\" + GlobalPaths.ConfigName, true); - GlobalFuncs.ReadClientValues(richTextBox1); - GlobalFuncs.ConsolePrint("Config Saved.", 3, richTextBox1); - } - - void WriteCustomizationValues() - { - GlobalFuncs.Customization(GlobalPaths.ConfigDir + "\\" + GlobalPaths.ConfigNameCustomization, true); - GlobalFuncs.ConsolePrint("Config Saved.", 3, richTextBox1); - } - - void ReadClientValues(bool initial = false) - { - GlobalFuncs.ReadClientValues(richTextBox1, initial); - - switch (GlobalVars.SelectedClientInfo.UsesPlayerName) - { - case true: - textBox2.Enabled = true; - break; - case false: - textBox2.Enabled = false; - break; - } - - switch (GlobalVars.SelectedClientInfo.UsesID) - { - case true: - textBox5.Enabled = true; - button4.Enabled = true; - if (GlobalVars.IP.Equals("localhost")) - { - checkBox3.Enabled = true; - } - break; - case false: - textBox5.Enabled = false; - button4.Enabled = false; - checkBox3.Enabled = false; - GlobalVars.LocalPlayMode = false; - break; - } - - if (!string.IsNullOrWhiteSpace(GlobalVars.SelectedClientInfo.Warning)) - { - label30.Text = GlobalVars.SelectedClientInfo.Warning; - label30.Visible = true; - } - else - { - label30.Visible = false; - } - - textBox6.Text = GlobalVars.SelectedClientInfo.Description; - label26.Text = GlobalVars.UserConfiguration.SelectedClient; - } - - void GeneratePlayerID() - { - GlobalFuncs.GeneratePlayerID(); - textBox5.Text = Convert.ToString(GlobalVars.UserConfiguration.UserID); - } - - void GenerateTripcode() - { - GlobalFuncs.GenerateTripcode(); - label18.Text = GlobalVars.UserConfiguration.PlayerTripcode; - } void TextBox1TextChanged(object sender, EventArgs e) { @@ -269,12 +114,12 @@ namespace NovetusLauncher void Button4Click(object sender, EventArgs e) { - GeneratePlayerID(); + launcherForm.GeneratePlayerID(); } void Button5Click(object sender, EventArgs e) { - WriteConfigValues(); + launcherForm.WriteConfigValues(); MessageBox.Show("Config Saved!"); } @@ -289,11 +134,11 @@ namespace NovetusLauncher GlobalVars.UserConfiguration.SelectedClient = listBox2.SelectedItem.ToString(); if (!ourselectedclient.Equals(GlobalVars.UserConfiguration.SelectedClient)) { - ReadClientValues(true); + launcherForm.ReadClientValues(true); } else { - ReadClientValues(); + launcherForm.ReadClientValues(); } GlobalFuncs.UpdateRichPresence(GlobalVars.LauncherState.InLauncher, ""); @@ -343,7 +188,7 @@ namespace NovetusLauncher void Button9Click(object sender, EventArgs e) { - ResetConfigValues(); + launcherForm.ResetConfigValues(); MessageBox.Show("Config Reset!"); } @@ -431,25 +276,6 @@ namespace NovetusLauncher { launcherForm.ProcessConsole(e); } - - void ResetConfigValues() - { - //https://stackoverflow.com/questions/9029351/close-all-open-forms-except-the-main-menu-in-c-sharp - List
openForms = new List(); - - foreach (Form f in Application.OpenForms) - openForms.Add(f); - - foreach (Form f in openForms) - { - if (f.Name != "LauncherFormExtended") - f.Close(); - } - - GlobalFuncs.ResetConfigValues(); - WriteConfigValues(); - ReadConfigValues(); - } void Button21Click(object sender, EventArgs e) { @@ -569,7 +395,7 @@ namespace NovetusLauncher break; } - WriteConfigValues(); + launcherForm.WriteConfigValues(); Application.Restart(); } @@ -650,7 +476,7 @@ namespace NovetusLauncher break; } - WriteConfigValues(); + launcherForm.WriteConfigValues(); Application.Restart(); } @@ -696,7 +522,7 @@ namespace NovetusLauncher private void button34_Click(object sender, EventArgs e) { - LoadLauncher(); + launcherForm.LoadLauncher(); } private void label8_Click(object sender, EventArgs e) @@ -786,16 +612,7 @@ namespace NovetusLauncher private void comboBox3_SelectedIndexChanged(object sender, EventArgs e) { - switch (comboBox3.SelectedIndex) - { - case 1: - GlobalVars.UserConfiguration.LauncherStyle = Settings.UIOptions.Style.Compact; - CloseEvent(); - Application.Restart(); - break; - default: - break; - } + launcherForm.SwitchStyles(); } private void SearchButton_Click(object sender, EventArgs e) @@ -833,7 +650,7 @@ namespace NovetusLauncher break; } - WriteConfigValues(); + launcherForm.WriteConfigValues(); Application.Restart(); } diff --git a/Novetus/NovetusLauncher/Forms/LauncherFormShared.cs b/Novetus/NovetusLauncher/Forms/LauncherFormShared.cs index e0a7870..8551ae9 100644 --- a/Novetus/NovetusLauncher/Forms/LauncherFormShared.cs +++ b/Novetus/NovetusLauncher/Forms/LauncherFormShared.cs @@ -24,12 +24,14 @@ namespace NovetusLauncher //CONTROLS public Form Parent = null; - public RichTextBox ConsoleBox = null; + public Settings.UIOptions.Style FormStyle = Settings.UIOptions.Style.None; + public RichTextBox ConsoleBox, ChangelogBox, ReadmeBox = null; public TabControl Tabs = null; public TextBox MapDescBox, ServerInfo, SearchBar = null; public TreeView Tree, _TreeCache = null; public ListBox ServerBox, PortBox, ClientBox = null; public Label SplashLabel = null; + public ComboBox StyleSelectorBox = null; public string TabPageHost, TabPageMaps, TabPageClients, TabPageSaved = ""; #endregion @@ -226,7 +228,7 @@ namespace NovetusLauncher if (File.Exists(GlobalPaths.RootPath + "\\changelog.txt")) { - richTextBox2.Text = File.ReadAllText(GlobalPaths.RootPath + "\\changelog.txt"); + ChangelogBox.Text = File.ReadAllText(GlobalPaths.RootPath + "\\changelog.txt"); } else { @@ -235,7 +237,7 @@ namespace NovetusLauncher if (File.Exists(GlobalPaths.RootPath + "\\README-AND-CREDITS.TXT")) { - richTextBox3.Text = File.ReadAllText(GlobalPaths.RootPath + "\\README-AND-CREDITS.TXT"); + ReadmeBox.Text = File.ReadAllText(GlobalPaths.RootPath + "\\README-AND-CREDITS.TXT"); } else { @@ -699,6 +701,209 @@ namespace NovetusLauncher GlobalFuncs.ConsolePrint("= dlldelete on | Turn on the deletion of opengl32.dll when ReShade is off.", 4, ConsoleBox); GlobalFuncs.ConsolePrint("---------", 1, ConsoleBox); } + + public void SwitchStyles() + { + switch (StyleSelectorBox.SelectedIndex) + { + case 1: + if (FormStyle == Settings.UIOptions.Style.Extended) + { + GlobalVars.UserConfiguration.LauncherStyle = Settings.UIOptions.Style.Compact; + CloseEvent(); + Application.Restart(); + } + break; + default: + if (FormStyle == Settings.UIOptions.Style.Compact) + { + GlobalVars.UserConfiguration.LauncherStyle = Settings.UIOptions.Style.Extended; + CloseEvent(); + Application.Restart(); + } + break; + } + } + + public void ReadConfigValues(bool initial = false) + { + GlobalFuncs.Config(GlobalPaths.ConfigDir + "\\" + GlobalPaths.ConfigName, false); + + checkBox1.Checked = GlobalVars.UserConfiguration.CloseOnLaunch; + textBox5.Text = GlobalVars.UserConfiguration.UserID.ToString(); + label18.Text = GlobalVars.UserConfiguration.PlayerTripcode.ToString(); + numericUpDown3.Value = Convert.ToDecimal(GlobalVars.UserConfiguration.PlayerLimit); + textBox2.Text = GlobalVars.UserConfiguration.PlayerName; + label26.Text = GlobalVars.UserConfiguration.SelectedClient; + label28.Text = GlobalVars.UserConfiguration.Map; + treeView1.SelectedNode = TreeNodeHelper.SearchTreeView(GlobalVars.UserConfiguration.Map, Tree.Nodes); + treeView1.Focus(); + numericUpDown1.Value = Convert.ToDecimal(GlobalVars.UserConfiguration.RobloxPort); + numericUpDown2.Value = Convert.ToDecimal(GlobalVars.UserConfiguration.RobloxPort); + label37.Text = GlobalVars.IP; + label38.Text = GlobalVars.UserConfiguration.RobloxPort.ToString(); + checkBox2.Checked = GlobalVars.UserConfiguration.DiscordPresence; + checkBox5.Checked = GlobalVars.UserConfiguration.ReShade; + checkBox6.Checked = GlobalVars.UserConfiguration.ReShadeFPSDisplay; + checkBox7.Checked = GlobalVars.UserConfiguration.ReShadePerformanceMode; + checkBox4.Checked = GlobalVars.UserConfiguration.UPnP; + checkBox9.Checked = GlobalVars.UserConfiguration.ShowServerNotifications; + + if (SecurityFuncs.IsElevated) + { + checkBox8.Enabled = true; + checkBox8.Checked = GlobalVars.UserConfiguration.WebServer; + } + else + { + checkBox8.Enabled = false; + } + + if (FormStyle == Settings.UIOptions.Style.Extended) + { + switch (GlobalVars.UserConfiguration.GraphicsMode) + { + case Settings.GraphicsOptions.Mode.OpenGL: + comboBox1.SelectedIndex = 1; + break; + case Settings.GraphicsOptions.Mode.DirectX: + comboBox1.SelectedIndex = 2; + break; + default: + comboBox1.SelectedIndex = 0; + break; + } + + switch (GlobalVars.UserConfiguration.QualityLevel) + { + case Settings.GraphicsOptions.Level.VeryLow: + comboBox2.SelectedIndex = 1; + break; + case Settings.GraphicsOptions.Level.Low: + comboBox2.SelectedIndex = 2; + break; + case Settings.GraphicsOptions.Level.Medium: + comboBox2.SelectedIndex = 3; + break; + case Settings.GraphicsOptions.Level.High: + comboBox2.SelectedIndex = 4; + break; + case Settings.GraphicsOptions.Level.Ultra: + comboBox2.SelectedIndex = 5; + break; + case Settings.GraphicsOptions.Level.Custom: + comboBox2.SelectedIndex = 6; + break; + default: + comboBox2.SelectedIndex = 0; + break; + } + } + + switch (GlobalVars.UserConfiguration.LauncherStyle) + { + case Settings.UIOptions.Style.Compact: + StyleSelectorBox.SelectedIndex = 1; + break; + case Settings.UIOptions.Style.Extended: + default: + StyleSelectorBox.SelectedIndex = 0; + break; + } + + GlobalFuncs.ConsolePrint("Config loaded.", 3, ConsoleBox); + ReadClientValues(initial); + } + + public void WriteConfigValues() + { + GlobalFuncs.Config(GlobalPaths.ConfigDir + "\\" + GlobalPaths.ConfigName, true); + GlobalFuncs.ReadClientValues(ConsoleBox); + GlobalFuncs.ConsolePrint("Config Saved.", 3, ConsoleBox); + } + + public void WriteCustomizationValues() + { + GlobalFuncs.Customization(GlobalPaths.ConfigDir + "\\" + GlobalPaths.ConfigNameCustomization, true); + GlobalFuncs.ConsolePrint("Config Saved.", 3, ConsoleBox); + } + + public void ResetConfigValues() + { + //https://stackoverflow.com/questions/9029351/close-all-open-forms-except-the-main-menu-in-c-sharp + List openForms = new List(); + + foreach (Form f in Application.OpenForms) + openForms.Add(f); + + foreach (Form f in openForms) + { + if (f.Name != Parent.Name) + f.Close(); + } + + GlobalFuncs.ResetConfigValues(); + WriteConfigValues(); + ReadConfigValues(); + } + + public void ReadClientValues(bool initial = false) + { + GlobalFuncs.ReadClientValues(ConsoleBox, initial); + + switch (GlobalVars.SelectedClientInfo.UsesPlayerName) + { + case true: + textBox2.Enabled = true; + break; + case false: + textBox2.Enabled = false; + break; + } + + switch (GlobalVars.SelectedClientInfo.UsesID) + { + case true: + textBox5.Enabled = true; + button4.Enabled = true; + if (GlobalVars.IP.Equals("localhost")) + { + checkBox3.Enabled = true; + } + break; + case false: + textBox5.Enabled = false; + button4.Enabled = false; + checkBox3.Enabled = false; + GlobalVars.LocalPlayMode = false; + break; + } + + if (!string.IsNullOrWhiteSpace(GlobalVars.SelectedClientInfo.Warning)) + { + label30.Text = GlobalVars.SelectedClientInfo.Warning; + label30.Visible = true; + } + else + { + label30.Visible = false; + } + + textBox6.Text = GlobalVars.SelectedClientInfo.Description; + label26.Text = GlobalVars.UserConfiguration.SelectedClient; + } + + public void GeneratePlayerID() + { + GlobalFuncs.GeneratePlayerID(); + textBox5.Text = Convert.ToString(GlobalVars.UserConfiguration.UserID); + } + + public void GenerateTripcode() + { + GlobalFuncs.GenerateTripcode(); + label18.Text = GlobalVars.UserConfiguration.PlayerTripcode; + } #endregion #region Functions