public PreferencesForm(Config config) { InitializeComponent(); _config = config; cbResolution.Items.Add(""); if (_config.Resolutions.Count <= 0) _config.Resolutions.AddRange(Resources.Resolutions.Split(' ')); _config.Resolutions.Sort(delegate(string s1, string s2) { int i1 = int.Parse(s1.Split('x')[0]); int i2 = int.Parse(s2.Split('x')[0]); int result = i1.CompareTo(i2); int i3 = int.Parse(s1.Split('x')[1]); int i4 = int.Parse(s2.Split('x')[1]); return result != 0 ? result : i3.CompareTo(i4); }); cbResolution.Items.AddRange(_config.Resolutions.ToArray()); if (_config.Arguments.ContainsKey("+fullscreen")) { if (_config.Arguments["+fullscreen"] == "1") cbWindowed.Checked = false; else cbWindowed.Checked = true; } if (_config.Options.ContainsKey("-localUpdate")) cbLocalUpdate.Checked = _config.Options["-localUpdate"]; string resolution = ""; if (_config.Arguments.ContainsKey("+szx")) { resolution = _config.Arguments["+szx"] + "x"; if (_config.Arguments.ContainsKey("+szy")) { resolution += _config.Arguments["+szy"]; for (int i = 0; i < cbResolution.Items.Count; i++) { if (resolution == (string)cbResolution.Items[i]) { cbResolution.SelectedIndex = i; break; } } } } }
private void preferencesToolStripMenuItem_Click(object sender, EventArgs e) { PreferencesForm preferences = new PreferencesForm(_config); DialogResult result = preferences.ShowDialog(); if (result == DialogResult.OK) { _config = preferences.Config; _config.Serialize(Path.Combine(_appDataFolder, _configName)); } preferences.Dispose(); }
/// <summary> /// Loads the config, either supplied through command line argument, the default config.xml, or creates a new one if none exists /// </summary> private void LoadConfig() { try { if (_args.ContainsKey("config") && _args["config"] != null) _configName = _args["config"]; _config = Config.Deserialize(Path.Combine(_appDataFolder, _configName)); } catch (Exception) { _config = CreateDefaultConfig(); try { _config.Serialize(Path.Combine(_appDataFolder, _configName)); } catch (Exception ex) { MessageBox.Show("There's a problem creating a new config file.\n\n" + ex.Message + "\n\nShutting down application.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); Log.LogInfo(ex); Application.Exit(); } } if (string.IsNullOrEmpty(_config.ParentPath)) _config.ParentPath = GetParentPath(); if (_config == null) Application.Exit(); }