Exemplo n.º 1
0
        public static CheckersSettings FromFile(string fileName)
        {
            CheckersSettings settings = null;

            if (File.Exists(fileName))
            {
                FileStream fs = File.OpenRead(fileName);
                try
                {
                    settings = (CheckersSettings)(new SoapFormatter()).Deserialize(fs);
                }
                catch (SerializationException e)
                {
                    MessageBox.Show("Could not load settings:\n" + e.Message + "\n\nUsing default settings.", "Checkers", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                fs.Close();
            }
            if ((settings != null) && ((settings.sounds == null) || (settings.sounds.Length != (new CheckersSettings()).sounds.Length)))
            {
                MessageBox.Show("Settings are corrupt.\n\nUsing default settings.", "Checkers", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                settings = null;
            }
            if (settings == null)
            {
                settings = new CheckersSettings();
                settings.Save();
            }
            return(settings);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Called when the dialog is shown.
        /// </summary>
        public new DialogResult OnShowDialog(IWin32Window owner)
        {
            if (settings == null)
            {
                settings = new CheckersSettings();
            }

            // Show settings
            ShowSettings();

            // Show dialog
            DialogResult result = base.ShowDialog(owner);

            // Set properties
            if (result != DialogResult.Cancel)
            {
                settings = new CheckersSettings();
                // General settings
                settings.HighlightSelection     = chkHighlightSelection.Checked;
                settings.HighlightPossibleMoves = chkHighlightPossibleMoves.Checked;
                settings.ShowJumpMessage        = chkShowJumpMessage.Checked;
                settings.ShowTextFeedback       = chkShowTextFeedback.Checked;
                // Net settings
                settings.FlashWindowOnGameEvents = chkFlashWindowOnGameEvents.Checked;
                settings.FlashWindowOnTurn       = chkFlashWindowOnTurn.Checked;
                settings.FlashWindowOnMessage    = chkFlashWindowOnMessage.Checked;
                settings.ShowNetPanelOnMessage   = chkShowNetPanelOnMessage.Checked;
                // Board appearance
                settings.BackColor      = picBackColor.BackColor;
                settings.BoardBackColor = picBoardBackColor.BackColor;
                settings.BoardForeColor = picBoardForeColor.BackColor;
                settings.BoardGridColor = picBoardGridColor.BackColor;
                // Sounds
                settings.sounds     = sounds;
                settings.MuteSounds = chkMuteSounds.Checked;
                // Save the settings
                settings.Save();
            }
            return(result);
        }