Beispiel #1
0
 public OptionsForm(MainForm mainForm)
 {
     InitializeComponent();
     this.Icon = mainForm.Icon;
     _settings = mainForm.Settings;
     CoreOpenFileDialog.InitialDirectory = mainForm.CorePath;
     LoadSettings(_settings);
 }
Beispiel #2
0
        public ObjectForm(TekSettings settings, AllegObject obj) : this()
        {
            _settings      = settings;
            _object        = obj;
            this.ForeColor = obj.Team.TeamColor;

            this.Text          = string.Concat(obj.Team.Faction.Name, ": ", obj.Name);
            InfoToolTip.Active = settings.ShowToolTips;
        }
Beispiel #3
0
        /// <summary>
        /// Constructs a new NewGameForm
        /// </summary>
        public NewGameForm(TekSettings settings, string corePath)
        {
            InitializeComponent();
            _settings = settings;
            _corePath = corePath;

            InfoToolTip.Active = settings.ShowToolTips;
            CoreOpenFileDialog.InitialDirectory = corePath;
            CoreTextBox.Text = Path.GetFileName(_settings.LastCore);
        }
Beispiel #4
0
        public StationForm(TekSettings settings, Station station) : base(settings, station)
        {
            InitializeComponent();

            _station         = station;
            station.Updated += new EventHandler(UpdateHandler);
            station.Closed  += new EventHandler(ClosedHandler);

            _station.Update();
        }
Beispiel #5
0
        /// <summary>
        /// Loads the settings into the form
        /// </summary>
        /// <param name="settings"></param>
        private void LoadSettings(TekSettings settings)
        {
            switch ((StartupAction)settings.Startup)
            {
            case StartupAction.DoNothing:
                DoNothingRadioButton.Checked = true;
                break;

            case StartupAction.LoadLastPlayed:
                LoadLastPlayedRadioButton.Checked  = true;
                NumberOfTeamsNumericUpDown.Enabled = true;
                break;

            case StartupAction.LoadLastUsed:
                LoadPreviousCoreRadioButton.Checked = true;
                NumberOfTeamsNumericUpDown.Enabled  = true;
                break;

            case StartupAction.LoadSpecified:
                LoadThisCoreRadioButton.Checked    = true;
                NumberOfTeamsNumericUpDown.Enabled = true;
                break;

            default:
                break;
            }

            NumberOfTeamsNumericUpDown.Value    = settings.NumTeams;
            LoadThisCoreTextBox.Text            = settings.SpecifiedCore;
            LoadThisCoreTextBox.SelectionStart  = LoadThisCoreTextBox.Text.Length;
            DefaultCoreLocationTextBox.Text     = settings.DefaultCoreLocation;
            RememberRecentCoresCheckBox.Checked = settings.RememberRecentCores;
            ShowToolTipsCheckBox.Checked        = settings.ShowToolTips;
            ShowBalloonHelpCheckBox.Checked     = settings.ShowBalloonHelp;
            ShowOverriddenCheckBox.Checked      = settings.ShowOverridden;
        }
Beispiel #6
0
        /// <summary>
        /// Loads the Settings file
        /// </summary>
        /// <param name="filePath">The fully-qualified path of the Settings object.</param>
        /// <returns>a Settings object containing the user-defined settings.</returns>
        public static TekSettings Deserialize(string filePath)
        {
            TekSettings NewSettings = null;

            FileStream    FS    = null;
            XmlTextReader XmlIn = null;

            try
            {
                // Prepare to read the file
                FS    = new FileStream(filePath, FileMode.Open, FileAccess.Read);
                XmlIn = new XmlTextReader(FS);

                // Ignore all whitespace
                XmlIn.WhitespaceHandling = WhitespaceHandling.None;

                // Move to first node
                XmlIn.MoveToContent();

                // Doublecheck the name of the node
                if (!XmlIn.Name.Equals(SETTINGSNAME))
                {
                    throw new ArgumentException("An improperly formatted Settings file was encountered.");
                }

                if (XmlIn.AttributeCount != 1)
                {
                    throw new ArgumentException("There is no version associated with this Settings file.");
                }

                // Check the version of the settings file
                double SettingsVersion = double.Parse(XmlIn.GetAttribute(0));
                if (SettingsVersion != SETTINGSVERSION)
                {
                    string       VersionMismatchMessage;
                    DialogResult Result;
                    if (SettingsVersion < SETTINGSVERSION)
                    {
                        VersionMismatchMessage = "The version of the settings file is older than the version supported by this program.\nYour settings are compatible with the new version.\n\nDo you want to convert your settings to the new version?";
                    }
                    else
                    {
                        VersionMismatchMessage = "The version of the settings file is newer than the version supported by this program.\nErrors may result if you continue.\nIt is recommended to save over these settings to ensure validity.\n\nDo you want to attempt to load these settings?";
                    }

                    // Prompt the user what to do if the version mismatches.
                    Result = MessageBox.Show(VersionMismatchMessage, Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                    switch (Result)
                    {
                    case DialogResult.Yes:                              // Attempt to continue parsing
                        break;

                    case DialogResult.No:                               // Abort parsing. No settings loaded.
                    default:
                        XmlIn.Close();
                        FS.Close();
                        return(null);
                    }
                }

                // Read each individual setting
                NewSettings = new TekSettings();
                PropertyInfo Property = null;
                while (!XmlIn.EOF)
                {
                    if (!XmlIn.Read())
                    {
                        throw new ArgumentException("Expected an XmlNode but got none! Settings file may be corrupt.");
                    }

                    // If it's the end-root node, exit loop.
                    // If it's the end-property node, go to next.
                    if (XmlIn.NodeType == XmlNodeType.EndElement)
                    {
                        if (XmlIn.Name.Equals(SETTINGSNAME))
                        {
                            break;
                        }
                        else
                        {
                            continue;
                        }
                    }

                    // XmlNode type should be an Element or Text.

                    // If reading a property element...
                    if (XmlIn.NodeType == XmlNodeType.Element)
                    {
                        if (!XmlIn.Name.Equals("Core"))
                        {
                            Property = typeof(TekSettings).GetProperty(XmlIn.Name);
                        }
                    }

                    if (XmlIn.NodeType == XmlNodeType.Text)
                    {
                        if (Property != null)
                        {
                            if (Property.PropertyType.Equals(typeof(ArrayList)))
                            {
                                ArrayList List = (ArrayList)Property.GetValue(NewSettings, null);
                                List.Add(Convert.ChangeType(XmlIn.Value, typeof(string)));
                            }
                            else
                            {
                                Property.SetValue(NewSettings, Convert.ChangeType(XmlIn.Value, Property.PropertyType), null);
                            }
                        }
                    }
                }
            }
            catch (FileNotFoundException)
            {
                MessageBox.Show("Could not load Settings: file does not exist at that location.", Application.ProductName);
            }
            catch (EndOfStreamException)
            {
                MessageBox.Show("Could not load Settings: End of file reached prematurely.", Application.ProductName);
            }
            catch (PathTooLongException)
            {
                MessageBox.Show("You have specified a path that is too long. Please specify a shorter one.", Application.ProductName);
            }
            catch (IOException e)
            {
                MessageBox.Show("IOError: Could not read Settings.\n" + e.Message, Application.ProductName);
            }
            catch (XmlException e)
            {
                MessageBox.Show("XmlError: Could not read Settings.\n" + e.Message, Application.ProductName);
            }
            catch (Exception e)
            {
                MessageBox.Show("General Error: Could not read Settings.\n" + e.Message, Application.ProductName);
            }
            finally
            {
                // Clean up
                if (XmlIn != null)
                {
                    XmlIn.Close();
                }
                ;
                if (FS != null)
                {
                    FS.Close();
                }
            }

            return(NewSettings);
        }