public void LoadConfig(string configFile) { ConfigFile = configFile; Items.Clear(); using (KeyManagerDataSet DConfig = new KeyManagerDataSet()) { DConfig.ReadXml(configFile); if (DConfig.KeyManager.Count == 0) { throw new FormatException("Invalid configuration file: " + configFile); } KeyManagerDataSet.KeyManagerRow ptrDev = DConfig.KeyManager[0]; ActivationSequence = ptrDev.ActivationSequence; SequenceTimeout = ptrDev.SequenceTimeout; ActivationType = (KeyManagerActivationSequenceType)Enum.Parse(typeof(KeyManagerActivationSequenceType), ptrDev.ActivationType); Modifier = (Keys)ptrDev.ComboKeyModifiers; ActivationKey = (Keys)ptrDev.ComboKey; foreach (KeyManagerDataSet.KeyManagerItemRow ptrItem in ptrDev.GetKeyManagerItemRows()) { KeyManagerItem tItem = new KeyManagerItem(); tItem.Name = ptrItem.Name; tItem.Application = ptrItem.Application; tItem.Argument = ptrItem.Arguments; tItem.ActionType = (KeyManagerActionType)Enum.Parse(typeof(KeyManagerActionType), ptrItem.ActionType); tItem.HotKey = ptrItem.HotKey; Items.Add(tItem); } } }
public void Save(string filePath) { using (KeyManagerDataSet DConfig = new KeyManagerDataSet()) { KeyManagerDataSet.KeyManagerRow ptrDev = DConfig.KeyManager.NewKeyManagerRow(); ptrDev.ID = 0; ptrDev.ActivationSequence = ActivationSequence; ptrDev.SequenceTimeout = SequenceTimeout; ptrDev.ActivationType = ActivationType.ToString(); ptrDev.ComboKeyModifiers = (int)Modifier; ptrDev.ComboKey = (int)ActivationKey; DConfig.KeyManager.AddKeyManagerRow(ptrDev); int tID = 0; foreach (KeyManagerItem ptrItem in Items) { KeyManagerDataSet.KeyManagerItemRow tItem = DConfig.KeyManagerItem.NewKeyManagerItemRow(); tItem.ID = tID++; tItem.ParentKey = ptrDev.ID; tItem.Name = ptrItem.Name; tItem.Application = ptrItem.Application; tItem.Arguments = ptrItem.Argument; tItem.ActionType = ptrItem.ActionType.ToString(); tItem.HotKey = ptrItem.HotKey; DConfig.KeyManagerItem.AddKeyManagerItemRow(tItem); } DConfig.WriteXml(filePath); } }