public void Load() { if (!File.Exists(path)) { createDefaultConfig(); return; } XDocument doc = XDocument.Load(path); IEnumerable<MainFormModel> configs = from m in doc.Descendants("Configuration") let startStopKeyAttr = m.Attribute("StartStopKey") let recordAttr = m.Attribute("RecordKey") select new MainFormModel { StartStopKey = new HotkeyBox.HotkeyValue(startStopKeyAttr == null ? "" : startStopKeyAttr.Value), RecordKey = new HotkeyBox.HotkeyValue(recordAttr == null ? "" : recordAttr.Value), Actions = (from al in m.Elements("ActionList") let action = al.Element("Action") let enable = al.Attribute("Enable") select new Tuple<ActionItem, bool>( element2Action(action), enable != null && enable.Value.ToLower().Equals("true") )) .ToList() }; MainFormModel config = configs.FirstOrDefault(); if (config == null) return; StartStopKey = config.StartStopKey; RecordKey = config.RecordKey; Actions = config.Actions; }
private void createDefaultConfig() { StartStopKey = new HotkeyBox.HotkeyValue {Key = Keys.F5}; RecordKey = new HotkeyBox.HotkeyValue {Key = Keys.F9}; Actions = new List<Tuple<ActionItem, bool>>(); Save(); }