예제 #1
0
        /// <summary>
        /// Loads user data from XML
        /// </summary>
        private void LoadSettings()
        {
            ShortcutsKey key = new ShortcutsKey();

            om.DataUpdatePending = true;

            sm        = new SaveModule <SettingsRoot>(Application.ProductName + "Save.xml");
            _settings = sm.ReadXML();

            if (null == _settings)
            {
                // When no user save file is available, try loading the init file instead to provide predefined profiles and settings
                _settings = sm.ReadXML(Application.ProductName + "Init.xml");
            }
            if (null == _settings)
            {
                _settings = new SettingsRoot();

                // prepare defaults..
                _settings.Version              = 0;
                _settings.MainWidth            = 559;
                _settings.MainHeight           = 723;
                _settings.HotKeyMethod         = (int)Shortcuts.SC_HotKeyMethod.SC_HotKeyMethod_Async;
                _settings.ShortcutResetEnable  = false;
                _settings.ShortcutResetKeyCode = 0x10000 | 0x75; // Shift F6
                _settings.ShortcutHitEnable    = false;
                _settings.ShortcutHitKeyCode   = 0x10000 | 0x76; // Shift F7
                _settings.ShortcutSplitEnable  = false;
                _settings.ShortcutSplitKeyCode = 0x10000 | 0x77; // Shift F8
                _settings.Inputfile            = "HitCounter.template";
                _settings.OutputFile           = "HitCounter.html";
                _settings.ProfileSelected      = "Unnamed";
                _settings.Profiles             = new Profiles();
            }
            if (_settings.Version == 0) // Coming from version 1.9 or older
            {
                _settings.Version                 = 1;
                _settings.ShowAttemptsCounter     = true;
                _settings.ShowHeadline            = true;
                _settings.ShowSplitsCountFinished = 999;
                _settings.ShowSplitsCountUpcoming = 999;
                _settings.StyleUseHighContrast    = false;
                _settings.StyleUseCustom          = false;
                _settings.StyleCssUrl             = "stylesheet_pink.css";
                _settings.StyleFontUrl            = "https://fonts.googleapis.com/css?family=Fontdiner%20Swanky";
            }
            if (_settings.Version == 1) // Coming from version 1.10
            {
                _settings.Version             = 2;
                _settings.MainWidth          += 31; // added new checkbox to datagrid
                _settings.ShowSessionProgress = true;
                _settings.StyleDesiredWidth   = 0;
            }
            if (_settings.Version == 2) // Coming from version 1.11 to 1.14
            {
                _settings.Version = 3;
                _settings.ShortcutHitUndoEnable    = false;
                _settings.ShortcutHitUndoKeyCode   = 0x10000 | 0x78; // Shift F9
                _settings.ShortcutSplitPrevEnable  = false;
                _settings.ShortcutSplitPrevKeyCode = 0x10000 | 0x79; // Shift F10
            }
            if (_settings.Version == 3)                              // Coming from version 1.15
            {
                _settings.Version       = 4;
                _settings.StyleFontName = "Fontdiner Swanky";
            }

            // Apply settings..
            sc.Initialize((Shortcuts.SC_HotKeyMethod)_settings.HotKeyMethod);
            profs = _settings.Profiles;

            this.ComboBox1.Items.AddRange(profs.GetProfileList());
            if (this.ComboBox1.Items.Count == 0)
            {
                this.ComboBox1.Items.Add("Unnamed");
            }
            this.ComboBox1.SelectedItem = _settings.ProfileSelected;

            key.key = new KeyEventArgs((Keys)_settings.ShortcutResetKeyCode);
            if (_settings.ShortcutResetEnable)
            {
                sc.Key_Set(Shortcuts.SC_Type.SC_Type_Reset, key);
            }
            else
            {
                sc.Key_PreSet(Shortcuts.SC_Type.SC_Type_Reset, key);
            }
            key.key = new KeyEventArgs((Keys)_settings.ShortcutHitKeyCode);
            if (_settings.ShortcutHitEnable)
            {
                sc.Key_Set(Shortcuts.SC_Type.SC_Type_Hit, key);
            }
            else
            {
                sc.Key_PreSet(Shortcuts.SC_Type.SC_Type_Hit, key);
            }
            key.key = new KeyEventArgs((Keys)_settings.ShortcutHitUndoKeyCode);
            if (_settings.ShortcutHitUndoEnable)
            {
                sc.Key_Set(Shortcuts.SC_Type.SC_Type_HitUndo, key);
            }
            else
            {
                sc.Key_PreSet(Shortcuts.SC_Type.SC_Type_HitUndo, key);
            }
            key.key = new KeyEventArgs((Keys)_settings.ShortcutSplitKeyCode);
            if (_settings.ShortcutSplitEnable)
            {
                sc.Key_Set(Shortcuts.SC_Type.SC_Type_Split, key);
            }
            else
            {
                sc.Key_PreSet(Shortcuts.SC_Type.SC_Type_Split, key);
            }
            key.key = new KeyEventArgs((Keys)_settings.ShortcutSplitPrevKeyCode);
            if (_settings.ShortcutSplitPrevEnable)
            {
                sc.Key_Set(Shortcuts.SC_Type.SC_Type_SplitPrev, key);
            }
            else
            {
                sc.Key_PreSet(Shortcuts.SC_Type.SC_Type_SplitPrev, key);
            }

            pi.SetActiveSplit(0);
            pi.SetSessionProgress(0, true);

            if (_settings.MainWidth > 400)
            {
                this.Width = _settings.MainWidth;
            }
            if (_settings.MainHeight > 400)
            {
                this.Height = _settings.MainHeight;
            }

            om.ShowAttemptsCounter     = _settings.ShowAttemptsCounter;
            om.ShowHeadline            = _settings.ShowHeadline;
            om.ShowSessionProgress     = _settings.ShowSessionProgress;
            om.ShowSplitsCountFinished = _settings.ShowSplitsCountFinished;
            om.ShowSplitsCountUpcoming = _settings.ShowSplitsCountUpcoming;
            om.StyleUseHighContrast    = _settings.StyleUseHighContrast;
            om.StyleUseCustom          = _settings.StyleUseCustom;
            om.StyleCssUrl             = _settings.StyleCssUrl;
            om.StyleFontUrl            = _settings.StyleFontUrl;
            om.StyleFontName           = _settings.StyleFontName;
            om.StyleDesiredWidth       = _settings.StyleDesiredWidth;

            om.FilePathIn        = _settings.Inputfile;
            om.FilePathOut       = _settings.OutputFile; // setting output filepath will allow writing output, so keep this line last
            om.DataUpdatePending = false;
        }
예제 #2
0
        /// <summary>
        /// Loads user data from XML
        /// </summary>
        private void LoadSettings()
        {
            int  baseVersion  = -1;
            bool isKeyInvalid = false;

            sm        = new SaveModule <SettingsRoot>(Application.ProductName + "Save.xml");
            _settings = sm.ReadXML(true);

            if (null == _settings)
            {
                // When no user save file is available, try loading the init file instead to provide predefined profiles and settings
                _settings = sm.ReadXML(false, Application.ProductName + "Init.xml");
            }
            if (null != _settings)
            {
                baseVersion = _settings.Version; // successfully loaded Save or Init file, so remember original version for upgrade
            }
            else
            {
                _settings = new SettingsRoot();

                // prepare defaults..
                _settings.Version              = 0;
                _settings.MainWidth            = 559;
                _settings.MainHeight           = 723;
                _settings.HotKeyMethod         = (int)Shortcuts.SC_HotKeyMethod.SC_HotKeyMethod_Async;
                _settings.ShortcutResetEnable  = false;
                _settings.ShortcutResetKeyCode = 0x10000 | 0x75; // Shift F6
                _settings.ShortcutHitEnable    = false;
                _settings.ShortcutHitKeyCode   = 0x10000 | 0x76; // Shift F7
                _settings.ShortcutSplitEnable  = false;
                _settings.ShortcutSplitKeyCode = 0x10000 | 0x77; // Shift F8
                _settings.Inputfile            = "HitCounter.template";
                _settings.OutputFile           = "HitCounter.html";
                _settings.ProfileSelected      = "Unnamed";
            }
            if (_settings.Version == 0) // Coming from version 1.9 or older
            {
                _settings.Version                 = 1;
                _settings.ShowAttemptsCounter     = true;
                _settings.ShowHeadline            = true;
                _settings.ShowSplitsCountFinished = 999;
                _settings.ShowSplitsCountUpcoming = 999;
                _settings.StyleUseHighContrast    = false;
                _settings.StyleUseCustom          = false;
                _settings.StyleCssUrl             = "stylesheet_pink.css";
                _settings.StyleFontUrl            = "https://fonts.googleapis.com/css?family=Fontdiner%20Swanky";
            }
            if (_settings.Version == 1) // Coming from version 1.10
            {
                _settings.Version             = 2;
                _settings.MainWidth          += 31; // added "SP" checkbox to datagrid
                _settings.ShowSessionProgress = true;
                _settings.StyleDesiredWidth   = 0;
            }
            if (_settings.Version == 2) // Coming from version 1.11 - 1.14
            {
                _settings.Version = 3;
                _settings.ShortcutHitUndoEnable    = false;
                _settings.ShortcutHitUndoKeyCode   = 0x10000 | 0x78; // Shift F9
                _settings.ShortcutSplitPrevEnable  = false;
                _settings.ShortcutSplitPrevKeyCode = 0x10000 | 0x79; // Shift F10
            }
            if (_settings.Version == 3)                              // Coming from version 1.15
            {
                _settings.Version       = 4;
                _settings.StyleFontName = "Fontdiner Swanky";
            }
            if (_settings.Version == 4) // Coming from version 1.16
            {
                _settings.Version                   = 5;
                _settings.MainWidth                += 50;             // added "WayHits" textbox to datagrid (50)
                _settings.MainHeight               += 13 + 70;        // added second line to datagrid column header(13) and "Succession" group box
                _settings.ShortcutWayHitEnable      = false;
                _settings.ShortcutWayHitKeyCode     = 0x10000 | 0x74; // Shift F5
                _settings.ShortcutWayHitUndoEnable  = false;
                _settings.ShortcutWayHitUndoKeyCode = 0x10000 | 0x7A; // Shift F11
                _settings.ShortcutPBEnable          = false;
                _settings.ShortcutPBKeyCode         = 0x10000 | 0x73; // Shift F4
                _settings.ShowFooter                = true;
                _settings.ShowHitsCombined          = true;
                _settings.ShowNumbers               = true;
                _settings.ShowPB   = true;
                _settings.Purpose  = (int)OutModule.OM_Purpose.OM_Purpose_SplitCounter;
                _settings.Severity = (int)OutModule.OM_Severity.OM_Severity_AnyHitsCritical;
                _settings.StyleUseHighContrastNames = false;
                _settings.SuccessionTitle           = "Predecessors";
                _settings.SuccessionHits            = 0;
                _settings.SuccessionHitsWay         = 0;
                _settings.SuccessionHitsPB          = 0;

                if (baseVersion < 0)
                {
                    // Use different hot keys when loaded without any previous settings
                    // (we don't have to take care of previous user/default settings)
                    _settings.ShortcutHitKeyCode        = 0x10000 | 0x70; // Shift F1
                    _settings.ShortcutWayHitKeyCode     = 0x10000 | 0x71; // Shift F2
                    _settings.ShortcutSplitKeyCode      = 0x10000 | 0x72; // Shift F3
                    _settings.ShortcutPBKeyCode         = 0x10000 | 0x73; // Shift F4
                    _settings.ShortcutHitUndoKeyCode    = 0x10000 | 0x74; // Shift F5
                    _settings.ShortcutWayHitUndoKeyCode = 0x10000 | 0x75; // Shift F6
                    _settings.ShortcutSplitPrevKeyCode  = 0x10000 | 0x76; // Shift F7
                    _settings.ShortcutResetKeyCode      = 0x10000 | 0x77; // Shift F8
                }
            }
            if (_settings.Version == 5) // Coming from version 1.17
            {
                _settings.Version     = 6;
                _settings.MainHeight -= 59; // "Succession" group box starts collapsed
                _settings.AlwaysOnTop = false;

                // Only enable progress bar when new settings were created
                _settings.ShowProgressBar = (baseVersion < 0 ? true : false);
                // Introduced with true in version 5, keep user setting when this version was used
                _settings.StyleProgressBarColored = (baseVersion == 5 ? true : false);
            }
            if (_settings.Version == 6) // Coming from version 1.18
            {
                _settings.Version       = 7;
                _settings.MainWidth    += 6;  // added tabs (6)
                _settings.MainHeight   += 27; // added tabs (27)
                _settings.MainPosX      = this.Left;
                _settings.MainPosY      = this.Top;
                _settings.ReadOnlyMode  = false;
                _settings.StyleUseRoman = false;
                _settings.StyleHightlightCurrentSplit = false;
                // Only enable progress bar integration of succession when new settings were created
                _settings.Succession.IntegrateIntoProgressBar = (baseVersion < 0 ? true : false);
                // Create succession with only one entry (there was only one available in older versions)
                SuccessionEntry suc_entry = new SuccessionEntry();
                suc_entry.ProfileSelected = _settings.ProfileSelected;
                _settings.Succession.SuccessionList.Add(suc_entry);
                // Introduced with false in version 6, keep user setting when this version was used
                _settings.StyleProgressBarColored = (baseVersion == 6 ? false : true);
            }
            if (_settings.Version == 7) // Coming from version 1.19
            {
                _settings.Version = 8;
                _settings.CheckUpdatesOnStartup = false;
                _settings.DarkMode = OsLayer.IsDarkModeActive();
                // Only use latest hot key method as default when new settings were created
                if (baseVersion < 0)
                {
                    _settings.HotKeyMethod = (int)Shortcuts.SC_HotKeyMethod.SC_HotKeyMethod_LLKb;
                }
                // Only enable time column when new settings were created
                _settings.ShowTimeCurrent           = (baseVersion < 0 ? true : false);
                _settings.ShowHits                  = true;
                _settings.ShowDiff                  = _settings.ShowPB; // was combined in previous versions
                _settings.ShowTimePB                = false;
                _settings.ShowTimeDiff              = false;
                _settings.ShowTimeFooter            = false;
                _settings.ShortcutTimerStartEnable  = false;
                _settings.ShortcutTimerStartKeyCode = 0x10000 | 0x6B; // Shift Add-Num
                _settings.ShortcutTimerStopEnable   = false;
                _settings.ShortcutTimerStopKeyCode  = 0x10000 | 0x6D; // Shift Subtract-Num
            }

            // Check for updates..
            if (_settings.CheckUpdatesOnStartup)
            {
                if (GitHubUpdate.QueryAllReleases())
                {
                    if (GitHubUpdate.GetLatestVersionName() != Application.ProductVersion.ToString())
                    {
                        if (GitHubUpdate.NewVersionDialog(this) == DialogResult.Yes)
                        {
                            GitHubUpdate.WebOpenLatestRelease();
                        }
                    }
                }
            }

            // Apply settings..

            // Setup window appearance..
            if (_settings.MainWidth < this.MinimumSize.Width)
            {
                _settings.MainWidth = this.MinimumSize.Width;
            }
            if (_settings.MainHeight < this.MinimumSize.Height)
            {
                _settings.MainHeight = this.MinimumSize.Height;
            }
            // set window size and when possible also set location (just make sure window is not outside of screen)
            this.SetBounds(_settings.MainPosX, _settings.MainPosY, _settings.MainWidth, _settings.MainHeight,
                           Program.IsOnScreen(_settings.MainPosX, _settings.MainPosY, _settings.MainWidth) ? BoundsSpecified.All : BoundsSpecified.Size);
            SetReadOnlyMode(_settings.ReadOnlyMode);
            SetAlwaysOnTop(_settings.AlwaysOnTop);
            Program.DarkMode = _settings.DarkMode;

            // Load profile data..
            if (_settings.Profiles.ProfileList.Count == 0)
            {
                // There is no profile at all, initially create a clean one
                Profile unnamed = new Profile();
                unnamed.Name = "Unnamed";
                _settings.Profiles.ProfileList.Add(unnamed);
            }
            if (_settings.Succession.SuccessionList.Count == 0)
            {
                // There is no succession at all create an empty succession
                SuccessionEntry first = new SuccessionEntry();
                first.ProfileSelected = _settings.Profiles.ProfileList[0].Name;
                _settings.Succession.SuccessionList.Add(first);
            }
            if (_settings.Succession.SuccessionList.Count <= _settings.Succession.ActiveIndex)
            {
                _settings.Succession.ActiveIndex = 0;
            }
            profCtrl.InitializeProfilesControl(_settings.Profiles, _settings.Succession);
            profCtrl.om.Settings = _settings;
            profCtrl.om.Update(); // Write first output once after application start

            // Configure hot keys..
            sc.Initialize((Shortcuts.SC_HotKeyMethod)_settings.HotKeyMethod);

            if (!LoadHotKeySettings(Shortcuts.SC_Type.SC_Type_Reset, _settings.ShortcutResetKeyCode, _settings.ShortcutResetEnable))
            {
                isKeyInvalid = true;
            }
            if (!LoadHotKeySettings(Shortcuts.SC_Type.SC_Type_Hit, _settings.ShortcutHitKeyCode, _settings.ShortcutHitEnable))
            {
                isKeyInvalid = true;
            }
            if (!LoadHotKeySettings(Shortcuts.SC_Type.SC_Type_HitUndo, _settings.ShortcutHitUndoKeyCode, _settings.ShortcutHitUndoEnable))
            {
                isKeyInvalid = true;
            }
            if (!LoadHotKeySettings(Shortcuts.SC_Type.SC_Type_WayHit, _settings.ShortcutWayHitKeyCode, _settings.ShortcutWayHitEnable))
            {
                isKeyInvalid = true;
            }
            if (!LoadHotKeySettings(Shortcuts.SC_Type.SC_Type_WayHitUndo, _settings.ShortcutWayHitUndoKeyCode, _settings.ShortcutWayHitUndoEnable))
            {
                isKeyInvalid = true;
            }
            if (!LoadHotKeySettings(Shortcuts.SC_Type.SC_Type_Split, _settings.ShortcutSplitKeyCode, _settings.ShortcutSplitEnable))
            {
                isKeyInvalid = true;
            }
            if (!LoadHotKeySettings(Shortcuts.SC_Type.SC_Type_SplitPrev, _settings.ShortcutSplitPrevKeyCode, _settings.ShortcutSplitPrevEnable))
            {
                isKeyInvalid = true;
            }
            if (!LoadHotKeySettings(Shortcuts.SC_Type.SC_Type_PB, _settings.ShortcutPBKeyCode, _settings.ShortcutPBEnable))
            {
                isKeyInvalid = true;
            }
            if (!LoadHotKeySettings(Shortcuts.SC_Type.SC_Type_TimerStart, _settings.ShortcutTimerStartKeyCode, _settings.ShortcutTimerStartEnable))
            {
                isKeyInvalid = true;
            }
            if (!LoadHotKeySettings(Shortcuts.SC_Type.SC_Type_TimerStop, _settings.ShortcutTimerStopKeyCode, _settings.ShortcutTimerStopEnable))
            {
                isKeyInvalid = true;
            }
            if (isKeyInvalid)
            {
                MessageBox.Show("Not all enabled hot keys could be registered successfully!", "Error setting up hot keys!");
            }
        }
예제 #3
0
        private void Settings_Load(object sender, EventArgs e)
        {
            sc        = ((Form1)Owner).sc;
            om        = ((Form1)Owner).profCtrl.om;
            _settings = om.Settings;

            LoadHotKey(Shortcuts.SC_Type.SC_Type_Reset, cbScReset, txtReset);
            LoadHotKey(Shortcuts.SC_Type.SC_Type_Hit, cbScHit, txtHit);
            LoadHotKey(Shortcuts.SC_Type.SC_Type_HitUndo, cbScHitUndo, txtHitUndo);
            LoadHotKey(Shortcuts.SC_Type.SC_Type_WayHit, cbScWayHit, txtWayHit);
            LoadHotKey(Shortcuts.SC_Type.SC_Type_WayHitUndo, cbScWayHitUndo, txtWayHitUndo);
            LoadHotKey(Shortcuts.SC_Type.SC_Type_Split, cbScNextSplit, txtNextSplit);
            LoadHotKey(Shortcuts.SC_Type.SC_Type_SplitPrev, cbScPrevSplit, txtPrevSplit);
            LoadHotKey(Shortcuts.SC_Type.SC_Type_PB, cbScPB, txtPB);
            LoadHotKey(Shortcuts.SC_Type.SC_Type_TimerStart, cbScTimerStart, txtTimerStart);
            LoadHotKey(Shortcuts.SC_Type.SC_Type_TimerStop, cbScTimerStop, txtTimerStop);

            radioHotKeyMethod_sync.Checked  = (sc.NextStart_Method == Shortcuts.SC_HotKeyMethod.SC_HotKeyMethod_Sync);
            radioHotKeyMethod_async.Checked = (sc.NextStart_Method == Shortcuts.SC_HotKeyMethod.SC_HotKeyMethod_Async);
            radioHotKeyMethod_llkb.Checked  = (sc.NextStart_Method == Shortcuts.SC_HotKeyMethod.SC_HotKeyMethod_LLKb);

            if (!sc.IsGlobalHotKeySupported)
            {
                tab_globalshortcuts.Text    = tab_globalshortcuts.Text + " (OS not supported)";
                tab_globalshortcuts.Enabled = false;
            }

            // Style
            numStyleDesiredWidth.Value      = _settings.StyleDesiredWidth;
            cbHighContrast.Checked          = _settings.StyleUseHighContrast;
            cbHighContrastNames.Checked     = _settings.StyleUseHighContrastNames;
            cbUseRoman.Checked              = _settings.StyleUseRoman;
            cbHighlightCurrentSplit.Checked = _settings.StyleHightlightCurrentSplit;
            cbProgressBarColored.Checked    = !_settings.StyleProgressBarColored;
            cbSuperscriptPB.Checked         = _settings.StyleSuperscriptPB;
            cbApCustomCss.Checked           = _settings.StyleUseCustom;
            txtCssUrl.Text   = _settings.StyleCssUrl;
            txtFontUrl.Text  = _settings.StyleFontUrl;
            txtFontName.Text = _settings.StyleFontName;

            // Behavior
            cbShowAttempts.Checked            = _settings.ShowAttemptsCounter;
            cbShowHeadline.Checked            = _settings.ShowHeadline;
            cbShowFooter.Checked              = _settings.ShowFooter;
            cbShowSessionProgress.Checked     = _settings.ShowSessionProgress;
            cbShowProgressBar.Checked         = _settings.ShowProgressBar;
            cbSuccessionToProgressBar.Checked = _settings.Succession.IntegrateIntoProgressBar;
            numShowSplitsCountFinished.Value  = _settings.ShowSplitsCountFinished;
            numShowSplitsCountUpcoming.Value  = _settings.ShowSplitsCountUpcoming;
            cbShowHits.Checked                   = _settings.ShowHits;
            cbShowHitsCombined.Checked           = _settings.ShowHitsCombined;
            cbShowNumbers.Checked                = _settings.ShowNumbers;
            cbShowPB.Checked                     = _settings.ShowPB;
            cbShowDiff.Checked                   = _settings.ShowDiff;
            cbShowTimeCurrent.Checked            = _settings.ShowTimeCurrent;
            cbShowTimePB.Checked                 = _settings.ShowTimePB;
            cbShowTimeDiff.Checked               = _settings.ShowTimeDiff;
            cbShowTimeFooter.Checked             = _settings.ShowTimeFooter;
            radioPurposeChecklist.Checked        = (om.Purpose == OutModule.OM_Purpose.OM_Purpose_Checklist);
            radioPurposeDeathCounter.Checked     = (om.Purpose == OutModule.OM_Purpose.OM_Purpose_DeathCounter);
            radioPurposeSplitCounter.Checked     = (om.Purpose == OutModule.OM_Purpose.OM_Purpose_SplitCounter);
            radioPurposeNoDeath.Checked          = (om.Purpose == OutModule.OM_Purpose.OM_Purpose_NoDeath);
            radioPurposeResetCounter.Checked     = (om.Purpose == OutModule.OM_Purpose.OM_Purpose_ResetCounter);
            radioSeverityBossHitCritical.Checked = (om.Severity == OutModule.OM_Severity.OM_Severity_BossHitCritical);
            radioSeverityComparePB.Checked       = (om.Severity == OutModule.OM_Severity.OM_Severity_ComparePB);
            radioSeverityAnyHitCritical.Checked  = (om.Severity == OutModule.OM_Severity.OM_Severity_AnyHitsCritical);

            // Update
            lblVersionCurrent.Text = Application.ProductVersion.ToString();
            CheckForUpdates(sender, null);
            cbCheckUpdatesOnStartup.Checked = _settings.CheckUpdatesOnStartup;

            ApplyAppearance(sender, null);
            this.UpdateDarkMode();
            IsFormLoaded = true;
        }
예제 #4
0
        /// <summary>
        /// Loads user data from XML
        /// </summary>
        private void LoadSettings()
        {
            int  baseVersion  = -1;
            bool isKeyInvalid = false;

            sm        = new SaveModule <SettingsRoot>(Application.ProductName + "Save.xml");
            _settings = sm.ReadXML();

            if (null == _settings)
            {
                // When no user save file is available, try loading the init file instead to provide predefined profiles and settings
                _settings = sm.ReadXML(Application.ProductName + "Init.xml");
            }
            if (null != _settings)
            {
                baseVersion = _settings.Version; // successfully loaded Save or Init file, so remember original version for upgrade
            }
            else
            {
                _settings = new SettingsRoot();

                // prepare defaults..
                _settings.Version              = 0;
                _settings.MainWidth            = 559;
                _settings.MainHeight           = 723;
                _settings.HotKeyMethod         = (int)Shortcuts.SC_HotKeyMethod.SC_HotKeyMethod_Async;
                _settings.ShortcutResetEnable  = false;
                _settings.ShortcutResetKeyCode = 0x10000 | 0x75; // Shift F6
                _settings.ShortcutHitEnable    = false;
                _settings.ShortcutHitKeyCode   = 0x10000 | 0x76; // Shift F7
                _settings.ShortcutSplitEnable  = false;
                _settings.ShortcutSplitKeyCode = 0x10000 | 0x77; // Shift F8
                _settings.Inputfile            = "HitCounter.template";
                _settings.OutputFile           = "HitCounter.html";
                _settings.ProfileSelected      = "Unnamed";
                _settings.Profiles             = new Profiles();
            }
            if (_settings.Version == 0) // Coming from version 1.9 or older
            {
                _settings.Version                 = 1;
                _settings.ShowAttemptsCounter     = true;
                _settings.ShowHeadline            = true;
                _settings.ShowSplitsCountFinished = 999;
                _settings.ShowSplitsCountUpcoming = 999;
                _settings.StyleUseHighContrast    = false;
                _settings.StyleUseCustom          = false;
                _settings.StyleCssUrl             = "stylesheet_pink.css";
                _settings.StyleFontUrl            = "https://fonts.googleapis.com/css?family=Fontdiner%20Swanky";
            }
            if (_settings.Version == 1) // Coming from version 1.10
            {
                _settings.Version             = 2;
                _settings.MainWidth          += 31; // added "SP" checkbox to datagrid
                _settings.ShowSessionProgress = true;
                _settings.StyleDesiredWidth   = 0;
            }
            if (_settings.Version == 2) // Coming from version 1.11 - 1.14
            {
                _settings.Version = 3;
                _settings.ShortcutHitUndoEnable    = false;
                _settings.ShortcutHitUndoKeyCode   = 0x10000 | 0x78; // Shift F9
                _settings.ShortcutSplitPrevEnable  = false;
                _settings.ShortcutSplitPrevKeyCode = 0x10000 | 0x79; // Shift F10
            }
            if (_settings.Version == 3)                              // Coming from version 1.15
            {
                _settings.Version       = 4;
                _settings.StyleFontName = "Fontdiner Swanky";
            }
            if (_settings.Version == 4) // Coming from version 1.16
            {
                _settings.Version                   = 5;
                _settings.MainWidth                += 50;             // added "WayHits" textbox to datagrid (50)
                _settings.MainHeight               += 13 + 70;        // added second line to datagrid column header(13) and "Succession" group box
                _settings.ShortcutWayHitEnable      = false;
                _settings.ShortcutWayHitKeyCode     = 0x10000 | 0x74; // Shift F5
                _settings.ShortcutWayHitUndoEnable  = false;
                _settings.ShortcutWayHitUndoKeyCode = 0x10000 | 0x7A; // Shift F11
                _settings.ShortcutPBEnable          = false;
                _settings.ShortcutPBKeyCode         = 0x10000 | 0x73; // Shift F4
                _settings.ShowFooter                = true;
                _settings.ShowHitsCombined          = true;
                _settings.ShowNumbers               = true;
                _settings.ShowPB   = true;
                _settings.Purpose  = (int)OutModule.OM_Purpose.OM_Purpose_SplitCounter;
                _settings.Severity = (int)OutModule.OM_Severity.OM_Severity_AnyHitsCritical;
                _settings.StyleUseHighContrastNames = false;
                _settings.SuccessionTitle           = "Predecessors";
                _settings.SuccessionHits            = 0;
                _settings.SuccessionHitsWay         = 0;
                _settings.SuccessionHitsPB          = 0;

                if (baseVersion < 0)
                {
                    // Use different hot keys when loaded without any previous settings
                    // (we don't have to take care of previous user/default settings)
                    _settings.ShortcutHitKeyCode        = 0x10000 | 0x70; // Shift F1
                    _settings.ShortcutWayHitKeyCode     = 0x10000 | 0x71; // Shift F2
                    _settings.ShortcutSplitKeyCode      = 0x10000 | 0x72; // Shift F3
                    _settings.ShortcutPBKeyCode         = 0x10000 | 0x73; // Shift F4
                    _settings.ShortcutHitUndoKeyCode    = 0x10000 | 0x74; // Shift F5
                    _settings.ShortcutWayHitUndoKeyCode = 0x10000 | 0x75; // Shift F6
                    _settings.ShortcutSplitPrevKeyCode  = 0x10000 | 0x76; // Shift F7
                    _settings.ShortcutResetKeyCode      = 0x10000 | 0x77; // Shift F8
                }
            }
            if (_settings.Version == 5) // Coming from version 1.17
            {
                _settings.Version     = 6;
                _settings.MainHeight -= 59; // "Succession" group box starts collapsed
                _settings.AlwaysOnTop = false;

                // Only enable progress bar when new settings were created
                _settings.ShowSessionProgress = (baseVersion < 0 ? true : false);
                // Introduced with true in version 5, keep user setting when this version was used
                _settings.StyleProgressBarColored = (baseVersion == 5 ? true : false);
            }
            if (_settings.Version == 6) // Coming from version 1.18
            {
                _settings.Version       = 7;
                _settings.MainPosX      = this.Left;
                _settings.MainPosY      = this.Top;
                _settings.StyleUseRoman = false;
                // Introduced with false in version 6, keep user setting when this version was used
                _settings.StyleProgressBarColored = (baseVersion == 6 ? false : true);
            }

            // Apply settings..
            sc.Initialize((Shortcuts.SC_HotKeyMethod)_settings.HotKeyMethod);
            profs = _settings.Profiles;
            profs.SetProfileInfo(pi);

            this.ComboBox1.Items.AddRange(profs.GetProfileList());
            if (this.ComboBox1.Items.Count == 0)
            {
                this.ComboBox1.Items.Add("Unnamed");
            }
            this.ComboBox1.SelectedItem = _settings.ProfileSelected;

            if (!LoadHotKeySettings(Shortcuts.SC_Type.SC_Type_Reset, _settings.ShortcutResetKeyCode, _settings.ShortcutResetEnable))
            {
                isKeyInvalid = true;
            }
            if (!LoadHotKeySettings(Shortcuts.SC_Type.SC_Type_Hit, _settings.ShortcutHitKeyCode, _settings.ShortcutHitEnable))
            {
                isKeyInvalid = true;
            }
            if (!LoadHotKeySettings(Shortcuts.SC_Type.SC_Type_HitUndo, _settings.ShortcutHitUndoKeyCode, _settings.ShortcutHitUndoEnable))
            {
                isKeyInvalid = true;
            }
            if (!LoadHotKeySettings(Shortcuts.SC_Type.SC_Type_WayHit, _settings.ShortcutWayHitKeyCode, _settings.ShortcutWayHitEnable))
            {
                isKeyInvalid = true;
            }
            if (!LoadHotKeySettings(Shortcuts.SC_Type.SC_Type_WayHitUndo, _settings.ShortcutWayHitUndoKeyCode, _settings.ShortcutWayHitUndoEnable))
            {
                isKeyInvalid = true;
            }
            if (!LoadHotKeySettings(Shortcuts.SC_Type.SC_Type_Split, _settings.ShortcutSplitKeyCode, _settings.ShortcutSplitEnable))
            {
                isKeyInvalid = true;
            }
            if (!LoadHotKeySettings(Shortcuts.SC_Type.SC_Type_SplitPrev, _settings.ShortcutSplitPrevKeyCode, _settings.ShortcutSplitPrevEnable))
            {
                isKeyInvalid = true;
            }
            if (!LoadHotKeySettings(Shortcuts.SC_Type.SC_Type_PB, _settings.ShortcutPBKeyCode, _settings.ShortcutPBEnable))
            {
                isKeyInvalid = true;
            }
            if (isKeyInvalid)
            {
                MessageBox.Show("Not all enabled hot keys could be registered successfully!", "Error setting up hot keys!");
            }

            pi.SetSessionProgress(0, true);
            SetSuccession(_settings.SuccessionHits, _settings.SuccessionHitsWay, _settings.SuccessionHitsPB, _settings.SuccessionTitle, _settings.ShowSuccession);
            SuccessionChanged(null, null);

            if (_settings.MainWidth < this.MinimumSize.Width)
            {
                _settings.MainWidth = this.MinimumSize.Width;
            }
            if (_settings.MainHeight < this.MinimumSize.Height)
            {
                _settings.MainHeight = this.MinimumSize.Height;
            }
            // set window size and when possible also set location (just make sure window is not outside of screen)
            this.SetBounds(_settings.MainPosX, _settings.MainPosY, _settings.MainWidth, _settings.MainHeight,
                           IsOnScreen(_settings.MainPosX, _settings.MainPosY, _settings.MainWidth, _settings.MainHeight) ? BoundsSpecified.All : BoundsSpecified.Size);
            SetAlwaysOnTop(_settings.AlwaysOnTop);

            om.ShowAttemptsCounter     = _settings.ShowAttemptsCounter;
            om.ShowHeadline            = _settings.ShowHeadline;
            om.ShowFooter              = _settings.ShowFooter;
            om.ShowSessionProgress     = _settings.ShowSessionProgress;
            om.ShowProgressBar         = _settings.ShowProgressBar;
            om.ShowSplitsCountFinished = _settings.ShowSplitsCountFinished;
            om.ShowSplitsCountUpcoming = _settings.ShowSplitsCountUpcoming;
            om.ShowHitsCombined        = _settings.ShowHitsCombined;
            om.ShowNumbers             = _settings.ShowNumbers;
            om.ShowPB = _settings.ShowPB;
            if (_settings.Purpose < (int)OutModule.OM_Purpose.OM_Purpose_MAX)
            {
                om.Purpose = (OutModule.OM_Purpose)_settings.Purpose;
            }
            else
            {
                om.Purpose = OutModule.OM_Purpose.OM_Purpose_SplitCounter;
            }
            if (_settings.Severity < (int)OutModule.OM_Severity.OM_Severity_MAX)
            {
                om.Severity = (OutModule.OM_Severity)_settings.Severity;
            }
            else
            {
                om.Severity = OutModule.OM_Severity.OM_Severity_AnyHitsCritical;
            }

            om.StyleUseHighContrast      = _settings.StyleUseHighContrast;
            om.StyleUseHighContrastNames = _settings.StyleUseHighContrastNames;
            om.StyleUseRoman             = _settings.StyleUseRoman;
            om.StyleProgressBarColored   = _settings.StyleProgressBarColored;
            om.StyleUseCustom            = _settings.StyleUseCustom;
            om.StyleCssUrl        = _settings.StyleCssUrl;
            om.StyleFontUrl       = _settings.StyleFontUrl;
            om.StyleFontName      = _settings.StyleFontName;
            om.StyleDesiredWidth  = _settings.StyleDesiredWidth;
            om.StyleSuperscriptPB = _settings.StyleSuperscriptPB;

            om.FilePathIn  = _settings.Inputfile;
            om.FilePathOut = _settings.OutputFile; // setting output filepath will allow writing output, so keep this line last
        }