/// <summary>
        ///     Initializes a new instance of the <see cref="MainWindow" /> class. Creates the program's documents directories if needed,
        ///     initializes structures, and loads the settings from registry.
        /// </summary>
        public MainWindow()
        {
            InitializeComponent();

            MWInstance = this;
            TempBSE_BS = new TeamBoxScore();

            Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US");
            Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture("en-US");
            setDefaultCulture(CultureInfo.CreateSpecificCulture("en-US"));

            //btnInject.Visibility = Visibility.Hidden;
#if DEBUG
            btnTest.Visibility = Visibility.Visible;
#else
            btnTest.Visibility = Visibility.Hidden;
            #endif

            if (Directory.Exists(PSFiltersPath) == false)
            {
                Directory.CreateDirectory(PSFiltersPath);
            }
            if (Directory.Exists(ASCFiltersPath) == false)
            {
                Directory.CreateDirectory(ASCFiltersPath);
            }
            var appTempPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\NBA Stats Tracker\" + @"Temp\";
            if (Directory.Exists(appTempPath) == false)
            {
                Directory.CreateDirectory(appTempPath);
            }

            TST[0] = new TeamStats(-1, "$$NewDB");
            TSTOpp[0] = new TeamStats(-1, "$$NewDB");

            for (var i = 0; i < 30; i++)
            {
                RealTST[i] = new TeamStats();
            }

            RegistryKey rk = null;

            try
            {
                rk = Registry.CurrentUser;
            }
            catch (Exception ex)
            {
                App.ForceCriticalError(ex, "Registry.CurrentUser");
            }

            Debug.Assert(rk != null, "rk != null");
            rk = rk.OpenSubKey(@"SOFTWARE\2K Sports\NBA 2K12");
            if (rk == null)
            {
                SavesPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\2K Sports\NBA 2K12\Saves\";
            }
            else
            {
                try
                {
                    SavesPath = rk.GetValue("Saves").ToString();
                }
                catch (Exception)
                {
                    SavesPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\2K Sports\NBA 2K12\Saves\";
                }
            }

            CSV.ReplaceREDitorSortingChars = true;

            if (App.RealNBAOnly)
            {
                mnuFileGetRealStats_Click(null, null);
                MessageBox.Show("Nothing but net! Thanks for using NBA Stats Tracker!");
                Environment.Exit(-1);
            }
            else
            {
                var exportTeamsOnly = Tools.GetRegistrySetting("ExportTeamsOnly", 1);
                mnuOptionsExportTeamsOnly.IsChecked = exportTeamsOnly == 1;

                var compatibilityCheck = Tools.GetRegistrySetting("CompatibilityCheck", 1);
                mnuOptionsCompatibilityCheck.IsChecked = compatibilityCheck == 1;

                IsImperial = Tools.GetRegistrySetting("IsImperial", 1) == 1;
                mnuOptionsIsImperial.IsChecked = IsImperial;

                // Displays a message to urge the user to donate at the 50th start of the program.
                var timesStarted = Tools.GetRegistrySetting("TimesStarted", -1);
                if (timesStarted == -1)
                {
                    Tools.SetRegistrySetting("TimesStarted", 1);
                }
                else if (timesStarted <= 50)
                {
                    if (timesStarted == 50)
                    {
                        var r =
                            MessageBox.Show(
                                "Hey there! This is a friendly reminder from the creator of NBA Stats Tracker.\n\n"
                                + "You seem to like using NBA Stats Tracker a lot, and I'm sure you enjoy the fact that it's free. "
                                + "However, if you believe that I deserve your support and you want to help me to continue my studies, "
                                + "as well as continue developing and supporting NBA Stats Tracker, you can always donate!\n\n"
                                + "Even a small amount can help a lot!\n\n" + "Would you like to find out how you can donate?\n\n"
                                + "Clicking Cancel will make sure this message never shows up again.",
                                "NBA Stats Tracker - A friendly reminder",
                                MessageBoxButton.YesNoCancel,
                                MessageBoxImage.Information);
                        if (r == MessageBoxResult.Yes)
                        {
                            mnuHelpDonate_Click(null, null);
                        }
                        else if (r == MessageBoxResult.No)
                        {
                            timesStarted = -1;
                        }
                    }
                    Tools.SetRegistrySetting("TimesStarted", timesStarted + 1);
                }
            }
            UIScheduler = TaskScheduler.FromCurrentSynchronizationContext();

            SearchCache = new List<SearchItem>();

            #region Keyboard Shortcuts

            CmndImport.InputGestures.Add(new KeyGesture(Key.I, ModifierKeys.Control));
            CommandBindings.Add(new CommandBinding(CmndImport, btnImport2K12_Click));

            CmndExport.InputGestures.Add(new KeyGesture(Key.E, ModifierKeys.Control));
            CommandBindings.Add(new CommandBinding(CmndExport, btnExport2K12_Click));

            CmndOpen.InputGestures.Add(new KeyGesture(Key.O, ModifierKeys.Control));
            CommandBindings.Add(new CommandBinding(CmndOpen, btnOpen_Click));

            CmndSave.InputGestures.Add(new KeyGesture(Key.S, ModifierKeys.Control));
            CommandBindings.Add(new CommandBinding(CmndSave, btnSaveCurrentSeason_Click));

            CmndFind.InputGestures.Add(new KeyGesture(Key.F, ModifierKeys.Control));
            CommandBindings.Add(new CommandBinding(CmndFind, QuickFind));

            #endregion

            //prepareImageCache();
        }
        /// <summary>
        ///     Initializes a new instance of the <see cref="MainWindow" /> class.
        ///     Creates the program's documents directories if needed, initializes structures, and loads the settings from registry.
        /// </summary>
        public MainWindow()
        {
            InitializeComponent();

            MWInstance = this;
            bs = new TeamBoxScore();

            Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US");

            //btnInject.Visibility = Visibility.Hidden;
            #if DEBUG
            btnTest.Visibility = Visibility.Visible;
            #else
            btnTest.Visibility = Visibility.Hidden;
            #endif

            if (Directory.Exists(PSFiltersPath) == false)
            {
                Directory.CreateDirectory(PSFiltersPath);
            }
            if (Directory.Exists(ASCFiltersPath) == false)
            {
                Directory.CreateDirectory(ASCFiltersPath);
            }
            if (Directory.Exists(AppTempPath) == false)
            {
                Directory.CreateDirectory(AppTempPath);
            }

            TST[0] = new TeamStats(-1, "$$NewDB");
            TSTOpp[0] = new TeamStats(-1, "$$NewDB");

            for (int i = 0; i < 30; i++)
            {
                RealTST[i] = new TeamStats();
            }

            RegistryKey rk = null;

            try
            {
                rk = Registry.CurrentUser;
            }
            catch (Exception ex)
            {
                App.ErrorReport(ex, "Registry.CurrentUser");
            }

            Debug.Assert(rk != null, "rk != null");
            rk = rk.OpenSubKey(@"SOFTWARE\2K Sports\NBA 2K12");
            if (rk == null)
            {
                SavesPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\2K Sports\NBA 2K12\Saves\";
            }
            else
            {
                try
                {
                    SavesPath = rk.GetValue("Saves").ToString();
                }
                catch (Exception)
                {
                    SavesPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\2K Sports\NBA 2K12\Saves\";
                }
            }

            // TODO: Re-enable downloading NBA stats when possible
            mnuFileGetRealStats.IsEnabled = false;
            btnDownloadBoxScore.IsEnabled = false;
            btnGrabNBAStats.IsEnabled = false;
            //

            if (App.RealNBAOnly)
            {
                // TODO: Re-enable downloading NBA stats when possible
                /*
                mnuFileGetRealStats_Click(null, null);
                MessageBox.Show("Nothing but net! Thanks for using NBA Stats Tracker!");
                Environment.Exit(-1);
                */
                //
                MessageBox.Show("This feature is temporarily disabled. Sorry for the inconvenience.", "NBA Stats Tracker",
                                MessageBoxButton.OK, MessageBoxImage.Information);
                Environment.Exit(-1);
            }
            else
            {
                int importSetting = Misc.GetRegistrySetting("NBA2K12ImportMethod", 0);
                if (importSetting == 0)
                {
                    mnuOptionsImportREDitor.IsChecked = true;
                }
                else
                {
                    Misc.SetRegistrySetting("NBA2K12ImportMethod", 0);
                    mnuOptionsImportREDitor.IsChecked = true;
                }

                int exportTeamsOnly = Misc.GetRegistrySetting("ExportTeamsOnly", 1);
                mnuOptionsExportTeamsOnly.IsChecked = exportTeamsOnly == 1;

                int compatibilityCheck = Misc.GetRegistrySetting("CompatibilityCheck", 1);
                mnuOptionsCompatibilityCheck.IsChecked = compatibilityCheck == 1;

                IsImperial = Misc.GetRegistrySetting("IsImperial", 1) == 1;
                mnuOptionsIsImperial.IsChecked = IsImperial;

                // Displays a message to urge the user to donate at the 50th start of the program.
                int timesStarted = Misc.GetRegistrySetting("TimesStarted", -1);
                if (timesStarted == -1)
                {
                    Misc.SetRegistrySetting("TimesStarted", 1);
                }
                else if (timesStarted <= 50)
                {
                    if (timesStarted == 50)
                    {
                        MessageBoxResult r =
                            MessageBox.Show(
                                "Hey there! This is a friendly reminder from the creator of NBA Stats Tracker.\n\n" +
                                "You seem to like using NBA Stats Tracker a lot, and I'm sure you enjoy the fact that it's free. " +
                                "However, if you believe that I deserve your support and you want to help me to continue my studies, " +
                                "as well as continue developing and supporting NBA Stats Tracker, you can always donate!\n\n" +
                                "Even a small amount can help a lot!\n\n" + "Would you like to find out how you can donate?\n\n" +
                                "Clicking Cancel will make sure this message never shows up again.",
                                "NBA Stats Tracker - A friendly reminder", MessageBoxButton.YesNoCancel, MessageBoxImage.Information);
                        if (r == MessageBoxResult.Yes)
                        {
                            mnuHelpDonate_Click(null, null);
                        }
                        else if (r == MessageBoxResult.No)
                        {
                            timesStarted = -1;
                        }
                    }
                    Misc.SetRegistrySetting("TimesStarted", timesStarted + 1);
                }
            }
            UIScheduler = TaskScheduler.FromCurrentSynchronizationContext();

            List<string> metricsNames = PAbbr.MetricsNames;
            for (int i = 0; i < metricsNames.Count; i++)
            {
                string name = metricsNames[i];
                PAbbr.MetricsDict.Add(name, double.NaN);
            }

            #region Keyboard Shortcuts

            CmndImport.InputGestures.Add(new KeyGesture(Key.I, ModifierKeys.Control));
            CommandBindings.Add(new CommandBinding(CmndImport, btnImport2K12_Click));

            CmndExport.InputGestures.Add(new KeyGesture(Key.E, ModifierKeys.Control));
            CommandBindings.Add(new CommandBinding(CmndExport, btnExport2K12_Click));

            CmndOpen.InputGestures.Add(new KeyGesture(Key.O, ModifierKeys.Control));
            CommandBindings.Add(new CommandBinding(CmndOpen, FileOpen));

            CmndSave.InputGestures.Add(new KeyGesture(Key.S, ModifierKeys.Control));
            CommandBindings.Add(new CommandBinding(CmndSave, btnSaveCurrentSeason_Click));

            #endregion

            //prepareImageCache();
        }