/// <summary> /// Creates a new setting situation by loading from the filename if it exists. Otherwise a default is created. /// </summary> /// <param name="filename"></param> public Settings(string filename) { _filename = filename; if (_filename != null && File.Exists(_filename)) { _settingInfo = Load(_filename); } else { _settingInfo = new SettingInfo(); } }
/// <summary> /// Creates a new instance of the settings dialog /// </summary> public frmSettings() { InitializeComponent(); if (DesignMode) return; _specificCultures = CultureInfo.GetCultures(CultureTypes.SpecificCultures); string[] specificCultureNames = new string[_specificCultures.Length]; for (int i = 0; i < _specificCultures.Length; i++) { specificCultureNames[i] = _specificCultures[i].DisplayName; } foreach (int i in _supportedIndices) { cmbCultureInfo.Items.Add(specificCultureNames[i]); } //cmbCultureInfo.Items.Add(CultureInfo.CurrentCulture); //cmbCultureInfo.Items.AddRange(specificCultureNames); _settingValues = Settings.Info ?? new SettingInfo(); cmbCultureInfo.Text = _settingValues.PreferredCulture.DisplayName; }
private static void Save(SettingInfo settings, string fileName) { Stream stream = null; try { if(Directory.Exists(Path.GetDirectoryName(fileName)) == false) { Directory.CreateDirectory(Path.GetDirectoryName(fileName)); } IFormatter formatter = new BinaryFormatter(); stream = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None); formatter.Serialize(stream, VERSION); formatter.Serialize(stream, settings); } catch(Exception ex) { Debug.Write(ex.ToString()); // do nothing, just ignore any possible errors } finally { if (null != stream) stream.Close(); } }