// Initialize everything on the UI thread, and report+die for any problems or SwitchContext from SplashForm to EDDiscoveryForm. private void MainEngineStart(object sender, EventArgs e) { var tim = (Timer)sender; tim?.Stop(); var launchArg = ((EDDFormLaunchArgs)tim?.Tag)?.Clone() ?? new EDDFormLaunchArgs(); tim?.Dispose(); try { EDDMainForm = new EDDiscoveryForm(); SetLoadingMsg("Starting EDD"); EDDiscoveryController.Initialize(SetLoadingMsg); // this loads up the options EDDOptions.Instance.NoWindowReposition |= launchArg.PositionReset; EDDOptions.Instance.NoTheme |= launchArg.ThemeReset; EDDOptions.Instance.TabsReset |= launchArg.TabsReset; EDDOptions.Instance.ResetLanguage |= launchArg.ResetLang; EDDMainForm.Init(SetLoadingMsg); // call the init function, which will initialize the eddiscovery form SetLoadingMsg("Starting Program"); SwitchContext(EDDMainForm); // Ignition, and liftoff! } catch (Exception ex) { // There's so many ways that things could go wrong during init; let's fail for everything! EDDMainForm?.Dispose(); BaseUtils.ExceptionForm.ShowException(ex, "A fatal exception was encountered while initializing EDDiscovery.", Properties.Resources.URLProjectFeedback, isFatal: true, parent: MainForm); } }
// Initialize everything on the UI thread, and report+die for any problems or SwitchContext from SplashForm to EDDiscoveryForm. private void MainEngineStart(object sender, EventArgs e) { var tim = (Timer)sender; tim?.Stop(); var launchArg = ((EDDFormLaunchArgs)tim?.Tag)?.Clone() ?? new EDDFormLaunchArgs(); tim?.Dispose(); try { EDDMainForm = new EDDiscoveryForm(); SetLoadingMsg("Checking Ship Systems"); EDDiscoveryController.Initialize(SetLoadingMsg); // this loads up the options EDDOptions.Instance.NoWindowReposition |= launchArg.PositionReset; EDDOptions.Instance.NoTheme |= launchArg.ThemeReset; EDDMainForm.Init(SetLoadingMsg); // call the init function, which will initialize the eddiscovery form SetLoadingMsg("Establishing Telepresence"); SwitchContext(EDDMainForm); // Ignition, and liftoff! } catch (Exception ex) { // There's so many ways that things could go wrong during init; let's fail for everything! EDDMainForm?.Dispose(); FatalExceptionForm.ShowAndDie(MainForm, "Initializing", Properties.Resources.URLProjectFeedback, ex); } }
// event handlers // Initialize everything on the UI thread soon after the `Application` has been `.Run()`, and transfer context (MainForm) from the SplashForm to the EDDiscoveryForm. private void initTimer_Tick(object sender, EventArgs e) { ((Timer)sender)?.Stop(); ((Timer)sender)?.Dispose(); try { EDDMainForm = new EDDiscoveryForm(); SetLoadingMsg("Checking Ship Systems"); EDDiscoveryController.Initialize(Control.ModifierKeys.HasFlag(Keys.Shift), Control.ModifierKeys.HasFlag(Keys.Control), SetLoadingMsg); EDDMainForm.Init(SetLoadingMsg); // call the init function, which will initialize the eddiscovery form SetLoadingMsg("Establishing Telepresence"); EDDMainForm.Show(); } catch (Exception ex) { // There's so many ways that things could go wrong during init; let's fail for everything! EDDMainForm?.Dispose(); FatalExceptionForm.ShowAndDie(MainForm, "Initializing", Properties.Resources.URLProjectFeedback, ex); } var splashForm = MainForm; MainForm = EDDMainForm; // Switch context splashForm.Close(); // and cleanup }
// Initialize everything on the UI thread, and report+die for any problems or SwitchContext from SplashForm to EDDiscoveryForm. private void MainEngineStart(object sender, EventArgs e) { var tim = (Timer)sender; tim?.Stop(); var launchArg = ((EDDFormLaunchArgs)tim?.Tag)?.Clone() ?? new EDDFormLaunchArgs(); tim?.Dispose(); EDDiscoveryForm EDDMainForm = null; try { EDDMainForm = new EDDiscoveryForm(); SetLoadingMsg("Starting EDD"); EDDiscoveryController.Initialize(SetLoadingMsg); // this loads up the options EDDOptions.Instance.NoWindowReposition |= launchArg.PositionReset; EDDOptions.Instance.NoTheme |= launchArg.ThemeReset; EDDOptions.Instance.TabsReset |= launchArg.TabsReset; EDDOptions.Instance.ResetLanguage |= launchArg.ResetLang; EDDMainForm.Init(SetLoadingMsg); // call the init function, which will initialize the eddiscovery form if (Environment.OSVersion.Platform == PlatformID.Win32NT) { NativeMethods.STARTUPINFO_I si = new NativeMethods.STARTUPINFO_I(); UnsafeNativeMethods.GetStartupInfo(si); // duplicate of form.cs WmCreate check of code. if ((si.dwFlags & NativeMethods.STARTF_USESHOWWINDOW) != 0) { if (si.wShowWindow == NativeMethods.SW_MINIMIZE || si.wShowWindow == NativeMethods.SW_SHOWMINNOACTIVE) { EDDOptions.Instance.MinimiseOnOpen = true; } else if (si.wShowWindow == NativeMethods.SW_SHOWMAXIMIZED || si.wShowWindow == NativeMethods.SW_MAXIMIZE) { EDDOptions.Instance.MaximiseOnOpen = true; } } } SetLoadingMsg("Starting Program"); SwitchContext(EDDMainForm); // Ignition, and liftoff! } catch (Exception ex) { // There's so many ways that things could go wrong during init; let's fail for everything! EDDMainForm?.Dispose(); BaseUtils.ExceptionForm.ShowException(ex, "A fatal exception was encountered while initializing EDDiscovery.", Properties.Resources.URLProjectFeedback, isFatal: true, parent: MainForm); } }
// Initialize everything on the UI thread, and report+die for any problems or SwitchContext from SplashForm to EDDiscoveryForm. private void InitialiseEDD(object sender, EventArgs e) { var tim = (Timer)sender; tim?.Stop(); var launchArg = ((EDDFormLaunchArgs)tim?.Tag)?.Clone() ?? new EDDFormLaunchArgs(); tim?.Dispose(); EDDiscoveryForm EDDMainForm = null; try { System.Threading.Thread.CurrentThread.Name = "EDD Main Thread"; EDDMainForm = new EDDiscoveryForm(); SetLoadingMsg("Initialising Databases"); UserDatabase.Instance.Name = "UserDB"; UserDatabase.Instance.MinThreads = 1; UserDatabase.Instance.MaxThreads = 2; UserDatabase.Instance.MultiThreaded = true; // starts up the threads SystemsDatabase.Instance.Name = "SystemDB"; SystemsDatabase.Instance.MinThreads = 1; SystemsDatabase.Instance.MaxThreads = 8; SystemsDatabase.Instance.MultiThreaded = true; // starts up the threads try { UserDatabase.Instance.Initialize(); } catch (Exception ex) { EliteDangerousCore.DB.UserDatabase.Instance.ClearDown(); // need everything closed down System.Windows.Forms.MessageBox.Show("Error: User DB is corrupt at " + EliteDangerousCore.EliteConfigInstance.InstanceOptions.UserDatabasePath + Environment.NewLine + Environment.NewLine + "Database is unusable. Use safe mode to remove it and start again. All user settings will be lost" + Environment.NewLine + Environment.NewLine + ex.Message.ToString(), "User DB corrupt", System.Windows.Forms.MessageBoxButtons.OK); SwitchContext(new SafeModeForm(false)); return; } try { SystemsDatabase.Instance.Initialize(); } catch (Exception ex) { EliteDangerousCore.DB.UserDatabase.Instance.ClearDown(); // need everything closed down EliteDangerousCore.DB.SystemsDatabase.Instance.ClearDown(); System.Windows.Forms.MessageBox.Show("Error: System DB is corrupt at " + EliteDangerousCore.EliteConfigInstance.InstanceOptions.SystemDatabasePath + Environment.NewLine + Environment.NewLine + "Database is unusable. Use safe mode to remove it and start again. User settings will be retained" + Environment.NewLine + Environment.NewLine + ex.Message.ToString(), "System DB corrupt", System.Windows.Forms.MessageBoxButtons.OK); SwitchContext(new SafeModeForm(false)); return; } EDDOptions.Instance.NoWindowReposition |= launchArg.PositionReset; EDDOptions.Instance.NoTheme |= launchArg.ThemeReset; EDDOptions.Instance.TabsReset |= launchArg.TabsReset; EDDOptions.Instance.ResetLanguage |= launchArg.ResetLang; SetLoadingMsg("Starting EDD"); EDDMainForm.Init(SetLoadingMsg); // call the init function, which will initialize the eddiscovery system if (Environment.OSVersion.Platform == PlatformID.Win32NT) { NativeMethods.STARTUPINFO_I si = new NativeMethods.STARTUPINFO_I(); UnsafeNativeMethods.GetStartupInfo(si); // duplicate of form.cs WmCreate check of code. if ((si.dwFlags & NativeMethods.STARTF_USESHOWWINDOW) != 0) { if (si.wShowWindow == NativeMethods.SW_MINIMIZE || si.wShowWindow == NativeMethods.SW_SHOWMINNOACTIVE) { EDDOptions.Instance.MinimiseOnOpen = true; } else if (si.wShowWindow == NativeMethods.SW_SHOWMAXIMIZED || si.wShowWindow == NativeMethods.SW_MAXIMIZE) { EDDOptions.Instance.MaximiseOnOpen = true; } } } SetLoadingMsg("Starting Program"); SwitchContext(EDDMainForm); // Ignition, and liftoff! } catch (Exception ex) { // There's so many ways that things could go wrong during init; let's fail for everything! BaseUtils.ExceptionForm.ShowException(ex, "A fatal exception was encountered while initializing EDDiscovery.", Properties.Resources.URLProjectFeedback, isFatal: true, parent: MainForm); EDDMainForm?.Dispose(); } }