Ejemplo n.º 1
0
        /// <summary>
        /// Create a PersistedSettings object from settings file read from disk.
        /// </summary>
        /// <param name="instance">Uninitialized object.</param>
        /// <returns>True if restore from disk succeeds.</returns>
        public static bool ReadFromDisk(out PersistedSettings instance)
        {
            bool success = true;

            instance = null;

            try
            {
                XmlSerializer reader = new XmlSerializer(typeof(PersistedSettings));
                using (StreamReader file = new StreamReader(PersistFilename))
                {
                    PersistedSettings ps = new PersistedSettings();
                    ps = (PersistedSettings)reader.Deserialize(file);

                    instance = ps;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Unable to restore application settings from \""
                                + Path.GetFileName(PersistFilename)
                                + "\".  Using application defaults.  "
                                + Environment.NewLine + Environment.NewLine + ex.Message, ex.GetType().Name);
                success = false;
            }

            return(success);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="args">Command line args</param>
        public MainForm(string[] args)
        {
            bool success = PersistedSettings.ReadFromDisk(out _settings);

            if (!success)
            {
                // Object creation failed.  Create a default PersistedSettings object.
                _settings = new PersistedSettings();
                _settings.SetValidDefaultState();
            }

            InitializeComponent();
            Score = -1;
            ParseCommandLineArgs(args);
        }