Пример #1
0
        public MainWindow()
        {
            var app = Application.Current;

            if (app != null)
            {
                app.MainWindow = this;
            }

            _cancelled = false;

            if (AppArguments.Values.Any())
            {
                ProcessArguments();
            }

            if (_testGameDialog != null)
            {
                Logging.Write("Testing mode");
                var ui = new GameDialog();
                ui.ShowDialogWithoutBlocking();
                ((IGameUi)ui).OnResult(JsonConvert.DeserializeObject <Game.Result>(FileUtils.ReadAllText(_testGameDialog)), null);
                _cancelled = true;
            }

            if (_cancelled)
            {
                Close();
                return;
            }

            DataContext = new ViewModel();
            InputBindings.AddRange(new[] {
                new InputBinding(new NavigateCommand(this, "about"), new KeyGesture(Key.F1, ModifierKeys.Alt)),
                new InputBinding(new NavigateCommand(this, "settings"), new KeyGesture(Key.F1, ModifierKeys.Control)),
                new InputBinding(new NavigateCommand(this, "drive"), new KeyGesture(Key.F1)),
                new InputBinding(new NavigateCommand(this, "lapTimes"), new KeyGesture(Key.F2)),
                new InputBinding(new NavigateCommand(this, "stats"), new KeyGesture(Key.F3)),
                new InputBinding(new NavigateCommand(this, "media"), new KeyGesture(Key.F4))
            });
            InitializeComponent();

            LinkNavigator.Commands.Add(new Uri("cmd://enterkey"), Model.EnterKeyCommand);
            AppKeyHolder.ProceedMainWindow(this);

            foreach (var result in MenuLinkGroups.OfType <LinkGroupFilterable>()
                     .Where(x => x.Source.OriginalString.Contains(@"/online.xaml", StringComparison.OrdinalIgnoreCase)))
            {
                result.LinkChanged += OnlineLinkChanged;
            }

            foreach (var result in MenuLinkGroups.OfType <LinkGroupFilterable>()
                     .Where(x => x.GroupKey == "content"))
            {
                result.LinkChanged += ContentLinkChanged;
            }

            UpdateLiveTabs();
            SettingsHolder.Live.PropertyChanged += Live_PropertyChanged;

            UpdateServerTab();
            UpdateMinoratingLink();
            SettingsHolder.Online.PropertyChanged += Online_PropertyChanged;

            if (!OfficialStarterNotification() && PluginsManager.Instance.HasAnyNew())
            {
                Toast.Show("Don’t forget to install plugins!", ""); // TODO?
            }

            EntryPoint.HandleSecondInstanceMessages(this, HandleMessagesAsync);

            _defaultOnlineGroupCount = OnlineGroup.FixedLinks.Count;

            if (FileBasedOnlineSources.IsInitialized())
            {
                UpdateOnlineSourcesLinks();
            }
            FileBasedOnlineSources.Instance.Update += OnOnlineSourcesUpdate;

            Activated += OnActivated;

#if DEBUG
            LapTimesGrid.Source = new Uri("/Pages/Miscellaneous/LapTimes_Grid.xaml", UriKind.Relative);
#endif
        }
Пример #2
0
        public MainWindow()
        {
            var app = Application.Current;

            if (app != null)
            {
                app.MainWindow = this;
            }

            _cancelled = false;

            if (_testGameDialog != null)
            {
                Logging.Write("Testing mode");
                var ui = new GameDialog();
                ui.ShowDialogWithoutBlocking();
                ((IGameUi)ui).OnResult(JsonConvert.DeserializeObject <Game.Result>(FileUtils.ReadAllText(_testGameDialog)), null);
                _cancelled = true;
            }

            if (_cancelled)
            {
                Close();
                return;
            }

            InitializeSubGroups();
            DataContext = new ViewModel();
            InputBindings.AddRange(new[] {
                new InputBinding(new NavigateCommand(this, "content"), new KeyGesture(Key.F1, ModifierKeys.Control)),
                new InputBinding(new NavigateCommand(this, "server"), new KeyGesture(Key.F2, ModifierKeys.Control)),
                new InputBinding(new NavigateCommand(this, "settings"), new KeyGesture(Key.F3, ModifierKeys.Control)),
                new InputBinding(new NavigateCommand(this, "about"), new KeyGesture(Key.F4, ModifierKeys.Control)),
                new InputBinding(new NavigateCommand(this, "drive"), new KeyGesture(Key.F1)),
                new InputBinding(new NavigateCommand(this, "lapTimes"), new KeyGesture(Key.F2)),
                new InputBinding(new NavigateCommand(this, "stats"), new KeyGesture(Key.F3)),
                new InputBinding(new NavigateCommand(this, "media"), new KeyGesture(Key.F4)),
                new InputBinding(new DelegateCommand(() => {
                    if (Keyboard.FocusedElement is TextBoxBase || Keyboard.FocusedElement is CheckBox)
                    {
                        return;
                    }

                    try {
                        if (Clipboard.ContainsData(DataFormats.FileDrop))
                        {
                            var data = Clipboard.GetFileDropList().OfType <string>().ToList();
                            Dispatcher.InvokeAsync(() => {
                                ProcessDroppedFiles(data);
                            });
                        }
                        else if (Clipboard.ContainsData(DataFormats.UnicodeText))
                        {
                            var list = Clipboard.GetText().SplitLines();
                            Dispatcher.InvokeAsync(() => {
                                ProcessDroppedFiles(list);
                            });
                        }
                    } catch (Exception e) {
                        Logging.Warning(e);
                    }
                }), new KeyGesture(Key.V, ModifierKeys.Control)),
            });
            InitializeComponent();

            LinkNavigator.Commands.Add(new Uri("cmd://enterkey"), Model.EnterKeyCommand);
            AppKeyHolder.ProceedMainWindow(this);

            foreach (var result in MenuLinkGroups.OfType <LinkGroupFilterable>()
                     .Where(x => x.Source.OriginalString.Contains(@"/online.xaml", StringComparison.OrdinalIgnoreCase)))
            {
                result.LinkChanged += OnlineLinkChanged;
            }

            foreach (var result in MenuLinkGroups.OfType <LinkGroupFilterable>()
                     .Where(x => x.Source.OriginalString.Contains(@"/laptimes_table.xaml", StringComparison.OrdinalIgnoreCase)))
            {
                result.LinkChanged += LapTimesLinkChanged;
            }

            foreach (var result in MenuLinkGroups.OfType <LinkGroupFilterable>()
                     .Where(x => x.GroupKey == "media" || x.GroupKey == "content"))
            {
                result.LinkChanged += ContentLinkChanged;
            }

            UpdateLiveTabs();
            SettingsHolder.Live.PropertyChanged += OnLiveSettingsPropertyChanged;

            UpdateServerTab();
            UpdateMinoratingLink();
            SettingsHolder.Online.PropertyChanged += OnOnlineSettingsPropertyChanged;

            if (!OfficialStarterNotification() && PluginsManager.Instance.HasAnyNew())
            {
                Toast.Show("Don’t forget to install plugins!", ""); // TODO?
            }

            _defaultOnlineGroupCount = OnlineGroup.FixedLinks.Count;

            if (FileBasedOnlineSources.IsInitialized())
            {
                UpdateOnlineSourcesLinks();
            }

            FileBasedOnlineSources.Instance.Update += OnOnlineSourcesUpdate;

            Activated += OnActivated;

            if (SettingsHolder.Drive.SelectedStarterType != SettingsHolder.DriveSettings.SteamStarterType)
            {
                TitleLinks.Remove(OriginalLauncher);
            }
            else
            {
                LinkNavigator.Commands.Add(new Uri("cmd://originalLauncher"), new DelegateCommand(SteamStarter.StartOriginalLauncher));
            }

            ContentInstallationManager.PluginsNavigator = this;

#if DEBUG
            LapTimesGrid.Source = new Uri("/Pages/Miscellaneous/LapTimes_Grid.xaml", UriKind.Relative);
#endif
        }