internal void ShowDialogOptions()
        {
            try
            {
                var           ratingSources = DraftRatings.Get().Keys.ToArray();
                OptionsWindow optionsWindow = new OptionsWindow().Init(ConfigModel, ratingSources);
                optionsWindow.Owner = this;
                optionsWindow.ShowDialog();

                // The code will continue here only when the options window gets closed
                var newConfig = JsonConvert.DeserializeObject <ConfigModel>(JsonConvert.SerializeObject(ConfigModel));
                newConfig.LogFilePath               = optionsWindow.LogFilePathTextBox.Text.Trim();
                newConfig.GameFilePath              = optionsWindow.GameFilePathTextBox.Text.Trim();
                newConfig.RunOnStartup              = optionsWindow.RunOnStartupCheckbox.IsChecked ?? false;
                newConfig.ShowOpponentCardsAuto     = optionsWindow.ShowOpponentCardsCheckbox.IsChecked ?? false;
                newConfig.ShowOpponentCardsExternal = optionsWindow.ShowOpponentCardsExternalCheckBox.IsChecked ?? true;
                newConfig.MinimizeToSystemTray      = optionsWindow.MinimizeToTrayCheckBox.IsChecked ?? false;
                newConfig.AutoShowHideForMatch      = optionsWindow.AutoShowHideForMatchCheckBox.IsChecked ?? false;
                newConfig.ForceCardPopup            = optionsWindow.ForceCardPopupCheckbox.IsChecked ?? false;
                newConfig.OrderLibraryCardsBy       = optionsWindow.OrderLibraryComboBox.SelectedValue.ToString();
                newConfig.ForceCardPopupSide        = optionsWindow.ForceCardPopupSideComboBox?.SelectedValue?.ToString() ?? ConfigModel.ForceCardPopupSide;
                newConfig.ShowLimitedRatingsSource  = optionsWindow.ShowLimitedRatingsSourceComboBox?.SelectedValue?.ToString() ?? ConfigModel.ShowLimitedRatingsSource;

                if (JsonConvert.SerializeObject(ConfigModel) != JsonConvert.SerializeObject(newConfig))
                {
                    bool   oldLimitedRatings       = ConfigModel.ShowLimitedRatings;
                    string oldLimitedRatingsSource = ConfigModel.ShowLimitedRatingsSource;
                    newConfig.Save();
                    Utilities.CopyProperties(newConfig, ConfigModel);

                    if (MainWindowVM.MainWindowContext == WindowContext.Drafting &&
                        (ConfigModel.ShowLimitedRatings != oldLimitedRatings || ConfigModel.ShowLimitedRatingsSource != oldLimitedRatingsSource))
                    {
                        if (ConfigModel.ShowLimitedRatingsSource != oldLimitedRatingsSource)
                        {
                            SetCardsDraft(MainWindowVM.DraftingVM.CurrentDraftPickProgress);
                        }

                        DraftingControl.SetPopupRatingsSource(ConfigModel.ShowLimitedRatings, ConfigModel.ShowLimitedRatingsSource);
                    }

                    ResourcesLocator.LocateLogFilePath(ConfigModel);
                    ResourcesLocator.LocateGameClientFilePath(ConfigModel);
                    FileMonitor.SetFilePath(newConfig.LogFilePath);
                    //vm.ValidateUserId(newConfig.UserId);
                    //ServerApiGetCollection();

                    StartupManager.ManageRunOnStartup(newConfig.RunOnStartup);
                    ReadyControl.Init(ConfigModel.GameFilePath);

                    MainWindowVM.OrderLibraryCardsBy = ConfigModel.OrderLibraryCardsBy == "Converted Mana Cost" ? CardsListOrder.ManaCost : CardsListOrder.DrawChance;
                }

                UpdateCardPopupPosition();
            }
            catch (Exception ex)
            {
                Log.Write(LogEventLevel.Error, ex, "Unexpected error:");
            }
        }
        public MainWindow(
            ConfigModel configApp,
            ICollection <Card> allCards,
            MainWindowVM viewModel,
            ProcessMonitor processMonitor,
            LogFileZipper zipper,
            ServerApiCaller api,
            StartupShortcutManager startupManager,
            LogSplitter logSplitter,
            MtgaResourcesLocator resourcesLocator,
            FileMonitor fileMonitor,
            DraftCardsPicker draftHelper,
            ReaderMtgaOutputLog readerMtgaOutputLog,
            InGameTracker2 inMatchTracker,
            ExternalProviderTokenManager tokenManager,
            PasswordHasher passwordHasher,
            CacheSingleton <Dictionary <string, DraftRatings> > draftRatings,
            DraftHelperRunner draftHelperRunner)
        {
            // Set the config model reference
            ConfigModel = configApp;


            Reader = readerMtgaOutputLog;
            processMonitor.OnProcessMonitorStatusChanged += OnProcessMonitorStatusChanged;
            Zipper           = zipper;
            Api              = api;
            StartupManager   = startupManager;
            LogSplitter      = logSplitter;
            ResourcesLocator = resourcesLocator;
            FileMonitor      = fileMonitor;
            fileMonitor.OnFileSizeChangedNewText += OnFileSizeChangedNewText;
            DraftHelper = draftHelper;
            //this.logProcessor = logProcessor;
            InGameTracker     = inMatchTracker;
            TokenManager      = tokenManager;
            PasswordHasher    = passwordHasher;
            DraftRatings      = draftRatings;
            DraftHelperRunner = draftHelperRunner;
            ResourcesLocator.LocateLogFilePath(ConfigModel);
            ResourcesLocator.LocateGameClientFilePath(ConfigModel);

            fileMonitor.SetFilePath(ConfigModel.LogFilePath);

            // Set the view model
            MainWindowVM = viewModel;

            // Set the data context to the view model
            DataContext = MainWindowVM;

            InitializeComponent();

            WelcomeControl.Init(tokenManager);
            PlayingControl.Init(MainWindowVM);
            StatusBarTop.Init(this, MainWindowVM);
            ReadyControl.Init(ConfigModel.GameFilePath);
            DraftingControl.Init(allCards, MainWindowVM.DraftingVM);

            DraftingControl.SetPopupRatingsSource(ConfigModel.ShowLimitedRatings, ConfigModel.ShowLimitedRatingsSource);

            processMonitor.Start(new System.Threading.CancellationToken());

            FileMonitor.Start(new System.Threading.CancellationToken());

            var timer = new DispatcherTimer {
                Interval = TimeSpan.FromMilliseconds(200)
            };

            timer.Tick += (sender, e) =>
            {
                MainWindowVM.SetCardsDraftFromBuffered();
                MainWindowVM.SetCardsInMatchTrackingFromBuffered();
            };
            timer.Start();

            var timerTokenRefresh = new DispatcherTimer {
                Interval = TimeSpan.FromMinutes(9)
            };

            timerTokenRefresh.Tick += (sender, e) =>
            {
                RefreshAccessToken();
            };
            timerTokenRefresh.Start();
        }