public MainWindow() { var procName = Process.GetCurrentProcess().ProcessName; var processes = Process.GetProcessesByName(procName); if (processes.Length > 1) { System.Windows.Forms.MessageBox.Show($"EDEngineer already running, you can bring it up with your shortcut ({SettingsManager.Shortcut}).", "Oops", MessageBoxButtons.OK, MessageBoxIcon.Warning); Application.Current.Shutdown(); return; } SettingsManager.Init(); try { ReleaseNotesManager.ShowReleaseNotesIfNecessary(); } catch { // silently fail if release notes can't be shown } Languages.InitLanguages(); InitializeComponent(); if (Properties.Settings.Default.WindowUnlocked) { AllowsTransparency = false; WindowStyle = WindowStyle.SingleBorderWindow; Topmost = false; ShowInTaskbar = true; } else { AllowsTransparency = true; WindowStyle = WindowStyle.None; Topmost = true; ShowInTaskbar = false; } viewModel = new MainWindowViewModel(Languages.Instance); DataContext = viewModel; RefreshCargoSources(); viewModel.PropertyChanged += (o, e) => { if (e.PropertyName == "ShowOnlyForFavorites" || e.PropertyName == "ShowZeroes" || e.PropertyName == "CurrentCommander") { RefreshCargoSources(); } }; serverBridge = new ServerBridge(viewModel, SettingsManager.AutoRunServer); }
public MainWindow() { var procName = Process.GetCurrentProcess().ProcessName; var processes = Process.GetProcessesByName(procName); if (processes.Length > 1) { System.Windows.Forms.MessageBox.Show($"EDEngineer already running, you can bring it up with your shortcut ({SettingsManager.Shortcut}).", "Oops", MessageBoxButtons.OK, MessageBoxIcon.Warning); Application.Current.Shutdown(); return; } InitializeComponent(); SettingsManager.Init(); try { ReleaseNotesManager.ShowReleaseNotesIfNecessary(); if (ReleaseNotesManager.RequireReset) { Properties.Settings.Default.ClearAggregation = true; Properties.Settings.Default.Save(); } } catch { // silently fail if release notes can't be shown } NotificationSettingsWindow.InitNotifications(); if (Properties.Settings.Default.WindowUnlocked) { AllowsTransparency = false; WindowStyle = WindowStyle.SingleBorderWindow; Topmost = false; ShowInTaskbar = true; } else { AllowsTransparency = true; WindowStyle = WindowStyle.None; Topmost = true; ShowInTaskbar = false; } var dimensions = SettingsManager.Dimensions; Width = dimensions.Width; Left = dimensions.Left; Top = dimensions.Top; Height = dimensions.Height; WindowState = SettingsManager.Maximized ? WindowState.Maximized : WindowState; var logDirectory = Helpers.RetrieveLogDirectory(false, null); var task = Task.Factory.StartNew(() => { viewModel = new MainWindowViewModel(Languages.Instance, logDirectory); if (ReleaseNotesManager.RequireReset) { viewModel.ChangeAllFilters(true); } viewModel.PropertyChanged += (o, e) => { if (e.PropertyName == "ShowOnlyForFavorites" || e.PropertyName == "ShowZeroes" || e.PropertyName == "CurrentCommander" || e.PropertyName == "MaterialSubkindFilter" || e.PropertyName == "IngredientsGrouped") { RefreshCargoSources(); } if (e.PropertyName == "IngredientsGrouped") { viewModel.CurrentComparer = viewModel.CurrentComparer; } }; }); task.ContinueWith(t => { new Popups.ErrorWindow(t.Exception?.Flatten() ?? new Exception("Unknown Error")).ShowDialog(); Close(); }, CancellationToken.None, TaskContinuationOptions.OnlyOnFaulted, TaskScheduler.FromCurrentSynchronizationContext()); task.ContinueWith(t => { serverBridge = new ServerBridge(viewModel, SettingsManager.AutoRunServer); DataContext = viewModel; RefreshCargoSources(); PostLoad(dimensions); if (!SettingsManager.SilentLaunch) { var sb = (Storyboard)FindResource("HideSplash"); Storyboard.SetTarget(sb, Splash); sb.Begin(); } viewModel.InitiateWatch(); }, CancellationToken.None, TaskContinuationOptions.OnlyOnRanToCompletion, TaskScheduler.FromCurrentSynchronizationContext()); if (SettingsManager.SilentLaunch) { Splash.Visibility = Visibility.Collapsed; if (Properties.Settings.Default.WindowUnlocked) { WindowState = WindowState.Minimized; } else { Opacity = 0.001; } } }