From 7552671ba2c1af3dd8bd5472fad6533edf6bf284 Mon Sep 17 00:00:00 2001 From: Bitl Date: Mon, 22 Mar 2021 15:03:05 -0700 Subject: [PATCH] implement close/launch code into shared --- .../Extended/LauncherFormExtended.cs | 80 +----------------- .../Forms/LauncherFormShared.cs | 84 ++++++++++++++++++- 2 files changed, 86 insertions(+), 78 deletions(-) diff --git a/Novetus/NovetusLauncher/Forms/LauncherForm/Extended/LauncherFormExtended.cs b/Novetus/NovetusLauncher/Forms/LauncherForm/Extended/LauncherFormExtended.cs index 0395576..ddc71a1 100644 --- a/Novetus/NovetusLauncher/Forms/LauncherForm/Extended/LauncherFormExtended.cs +++ b/Novetus/NovetusLauncher/Forms/LauncherForm/Extended/LauncherFormExtended.cs @@ -53,7 +53,7 @@ namespace NovetusLauncher #region Form Events async void tabControl1_SelectedIndexChanged(object sender, EventArgs e) { - launcherForm.ChangeTabs(); + await launcherForm.ChangeTabs(); } void Button1Click(object sender, EventArgs e) @@ -88,88 +88,14 @@ namespace NovetusLauncher void MainFormLoad(object sender, EventArgs e) { - Text = "Novetus " + GlobalVars.ProgramInformation.Version; - GlobalFuncs.ConsolePrint("Novetus version " + GlobalVars.ProgramInformation.Version + " loaded. Initializing config.", 4, richTextBox1); - GlobalFuncs.ConsolePrint("Novetus path: " + GlobalPaths.BasePath, 4, richTextBox1); - - if (File.Exists(GlobalPaths.RootPath + "\\changelog.txt")) - { - richTextBox2.Text = File.ReadAllText(GlobalPaths.RootPath + "\\changelog.txt"); - } - else - { - GlobalFuncs.ConsolePrint("ERROR - " + GlobalPaths.RootPath + "\\changelog.txt not found.", 2, richTextBox1); - } - - if (File.Exists(GlobalPaths.RootPath + "\\README-AND-CREDITS.TXT")) - { - richTextBox3.Text = File.ReadAllText(GlobalPaths.RootPath + "\\README-AND-CREDITS.TXT"); - } - else - { - GlobalFuncs.ConsolePrint("ERROR - " + GlobalPaths.RootPath + "\\README-AND-CREDITS.TXT not found.", 2, richTextBox1); - } - - if (!File.Exists(GlobalPaths.ConfigDir + "\\" + GlobalPaths.ConfigName)) - { - GlobalFuncs.ConsolePrint("WARNING - " + GlobalPaths.ConfigDir + "\\" + GlobalPaths.ConfigName + " not found. Creating one with default values.", 5, richTextBox1); - WriteConfigValues(); - } - if (!File.Exists(GlobalPaths.ConfigDir + "\\" + GlobalPaths.ConfigNameCustomization)) - { - GlobalFuncs.ConsolePrint("WARNING - " + GlobalPaths.ConfigDir + "\\" + GlobalPaths.ConfigNameCustomization + " not found. Creating one with default values.", 5, richTextBox1); - WriteCustomizationValues(); - } - if (!File.Exists(GlobalPaths.ConfigDir + "\\servers.txt")) - { - GlobalFuncs.ConsolePrint("WARNING - " + GlobalPaths.ConfigDir + "\\servers.txt not found. Creating empty file.", 5, richTextBox1); - File.Create(GlobalPaths.ConfigDir + "\\servers.txt").Dispose(); - } - if (!File.Exists(GlobalPaths.ConfigDir + "\\ports.txt")) - { - GlobalFuncs.ConsolePrint("WARNING - " + GlobalPaths.ConfigDir + "\\ports.txt not found. Creating empty file.", 5, richTextBox1); - File.Create(GlobalPaths.ConfigDir + "\\ports.txt").Dispose(); - } - - GlobalFuncs.CreateAssetCacheDirectories(); - - label8.Text = Application.ProductVersion; - LocalVars.important = SecurityFuncs.GenerateMD5(Assembly.GetExecutingAssembly().Location); - label11.Text = GlobalVars.ProgramInformation.Version; - - label12.Text = SplashReader.GetSplash(); - LocalVars.prevsplash = label12.Text; - - ReadConfigValues(true); - InitUPnP(); - StartDiscord(); - if (GlobalVars.UserConfiguration.WebServer) - { - StartWebServer(); - } + launcherForm.InitForm(); } void MainFormClose(object sender, CancelEventArgs e) { - CloseEvent(); + launcherForm.CloseEvent(); } - void CloseEvent() - { - if (!GlobalVars.LocalPlayMode) - { - WriteConfigValues(); - } - if (GlobalVars.UserConfiguration.DiscordPresence) - { - DiscordRPC.Shutdown(); - } - if (GlobalVars.IsWebServerOn) - { - StopWebServer(); - } - } - void ReadConfigValues(bool initial = false) { GlobalFuncs.Config(GlobalPaths.ConfigDir + "\\" + GlobalPaths.ConfigName, false); diff --git a/Novetus/NovetusLauncher/Forms/LauncherFormShared.cs b/Novetus/NovetusLauncher/Forms/LauncherFormShared.cs index 70e8666..e0a7870 100644 --- a/Novetus/NovetusLauncher/Forms/LauncherFormShared.cs +++ b/Novetus/NovetusLauncher/Forms/LauncherFormShared.cs @@ -5,7 +5,9 @@ using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; +using System.Reflection; using System.Text; +using System.Threading.Tasks; using System.Windows.Forms; #endregion @@ -215,7 +217,87 @@ namespace NovetusLauncher #endregion #region Form Event Functions - public async void ChangeTabs() + + public void InitForm() + { + Parent.Text = "Novetus " + GlobalVars.ProgramInformation.Version; + GlobalFuncs.ConsolePrint("Novetus version " + GlobalVars.ProgramInformation.Version + " loaded. Initializing config.", 4, ConsoleBox); + GlobalFuncs.ConsolePrint("Novetus path: " + GlobalPaths.BasePath, 4, ConsoleBox); + + if (File.Exists(GlobalPaths.RootPath + "\\changelog.txt")) + { + richTextBox2.Text = File.ReadAllText(GlobalPaths.RootPath + "\\changelog.txt"); + } + else + { + GlobalFuncs.ConsolePrint("ERROR - " + GlobalPaths.RootPath + "\\changelog.txt not found.", 2, ConsoleBox); + } + + if (File.Exists(GlobalPaths.RootPath + "\\README-AND-CREDITS.TXT")) + { + richTextBox3.Text = File.ReadAllText(GlobalPaths.RootPath + "\\README-AND-CREDITS.TXT"); + } + else + { + GlobalFuncs.ConsolePrint("ERROR - " + GlobalPaths.RootPath + "\\README-AND-CREDITS.TXT not found.", 2, ConsoleBox); + } + + if (!File.Exists(GlobalPaths.ConfigDir + "\\" + GlobalPaths.ConfigName)) + { + GlobalFuncs.ConsolePrint("WARNING - " + GlobalPaths.ConfigDir + "\\" + GlobalPaths.ConfigName + " not found. Creating one with default values.", 5, ConsoleBox); + WriteConfigValues(); + } + if (!File.Exists(GlobalPaths.ConfigDir + "\\" + GlobalPaths.ConfigNameCustomization)) + { + GlobalFuncs.ConsolePrint("WARNING - " + GlobalPaths.ConfigDir + "\\" + GlobalPaths.ConfigNameCustomization + " not found. Creating one with default values.", 5, ConsoleBox); + WriteCustomizationValues(); + } + if (!File.Exists(GlobalPaths.ConfigDir + "\\servers.txt")) + { + GlobalFuncs.ConsolePrint("WARNING - " + GlobalPaths.ConfigDir + "\\servers.txt not found. Creating empty file.", 5, ConsoleBox); + File.Create(GlobalPaths.ConfigDir + "\\servers.txt").Dispose(); + } + if (!File.Exists(GlobalPaths.ConfigDir + "\\ports.txt")) + { + GlobalFuncs.ConsolePrint("WARNING - " + GlobalPaths.ConfigDir + "\\ports.txt not found. Creating empty file.", 5, ConsoleBox); + File.Create(GlobalPaths.ConfigDir + "\\ports.txt").Dispose(); + } + + GlobalFuncs.CreateAssetCacheDirectories(); + + label8.Text = Application.ProductVersion; + LocalVars.important = SecurityFuncs.GenerateMD5(Assembly.GetExecutingAssembly().Location); + label11.Text = GlobalVars.ProgramInformation.Version; + + SplashLabel.Text = SplashReader.GetSplash(); + LocalVars.prevsplash = SplashLabel.Text; + + ReadConfigValues(true); + InitUPnP(); + StartDiscord(); + if (GlobalVars.UserConfiguration.WebServer) + { + StartWebServer(); + } + } + + public void CloseEvent() + { + if (!GlobalVars.LocalPlayMode) + { + WriteConfigValues(); + } + if (GlobalVars.UserConfiguration.DiscordPresence) + { + DiscordRPC.Shutdown(); + } + if (GlobalVars.IsWebServerOn) + { + StopWebServer(); + } + } + + public async Task ChangeTabs() { switch (Tabs.SelectedTab) {