public static void LoadKeyMappings(string path) { using(FileStream file = File.OpenRead(path)) using(StreamReader reader = new StreamReader(file)) { Dictionary<string, KeyMapper> output = new Dictionary<string, KeyMapper>(); string currentGUI = ""; while(!reader.EndOfStream) { string line = reader.ReadLine(); if (line == "") continue; if (line[0] == '/' && line[1] == '/') continue; if (line[0] == '#') { line = line.Remove(0, 1); output.Add(line, new KeyMapper()); currentGUI = line; continue; } string[] parts = line.Split(new string[]{": "}, StringSplitOptions.RemoveEmptyEntries); string[] firstParts = parts[0].Split(new string[] { ", " }, StringSplitOptions.RemoveEmptyEntries); string[] secondParts = parts[1].Split(new string[] { ", " }, StringSplitOptions.RemoveEmptyEntries); string command = firstParts[0]; string key = secondParts[0]; string keyHelp = ""; if (firstParts.Length > 1) keyHelp = firstParts[1]; else keyHelp = key; string modifiers = ""; if (secondParts.Length > 1) modifiers = secondParts[1]; else modifiers = "None"; MappedKey mappedKey = new MappedKey((Keys)Enum.Parse(typeof(Keys), key), (Modifiers)Enum.Parse(typeof(Modifiers), modifiers), keyHelp); output[currentGUI].AddMapping(command, mappedKey); } keyMapperDatabase = output; } }
public void AddMapping(string name, MappedKey key) { AddMapping(name, new List<MappedKey> { key }); }