Exemplo n.º 1
0
        public SettingsForm(UserSettings userSettings)
        {
            InitializeComponent();

              Font = UserSettings.Instance.DefaultFont ?? Font;

              // UI Settings
              UserSettings = userSettings;
        }
Exemplo n.º 2
0
        public static bool Load()
        {
            bool ok = false;

            _instance = new UserSettings();

            string settingsFilePath = GetSettingsFilePath();
            if (!File.Exists(settingsFilePath))
                return ok;

            try
            {
                using (FileStream fs = new FileStream(settingsFilePath, FileMode.Open))
                {
                    if (fs.Length > 0)
                    {
                        BinaryFormatter bf = new BinaryFormatter();
                        _instance = bf.Deserialize(fs) as UserSettings;

                        // During 1st load, some members are set to null
                        if (_instance != null)
                        {
                            if (_instance._receivers == null)
                                _instance._receivers = new List<IReceiver>();

                            if (_instance._layout == null)
                                _instance._layout = new LayoutSettings();
                        }

                        ok = true;
                    }
                }
            }
            catch (Exception)
            {
                // The settings file might be corrupted or from too different version, delete it...
                try
                {
                    File.Delete(settingsFilePath);
                }
                catch
                {
                    ok = false;
                }
            }

            return ok;
        }