Example #1
0
        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();
            NotificationSettingsWindow.InitNotifications();

            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);

            if (SettingsManager.SilentLaunch)
            {
                if (Properties.Settings.Default.WindowUnlocked)
                {
                    WindowState = WindowState.Minimized;
                }
                else
                {
                    Opacity = 0.001;
                }
            }
        }
Example #2
0
        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();
            }
            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;
            var logDirectory = Helpers.RetrieveLogDirectory(false, null);
            var task         = Task.Factory.StartNew(() =>
            {
                viewModel = new MainWindowViewModel(Languages.Instance, logDirectory);
                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;
                }
            }
        }