public void LoadFrom(XmlNode xn) { MappedType = (ControllerType)Enum.Parse(typeof(ControllerType), xn.Attributes["type"].Value, true); Source = (SourceType)Enum.Parse(typeof(SourceType), xn.Attributes["source"].Value, true); UUID = xn.Attributes["uuid"] != null?Guid.Parse(xn.Attributes["uuid"].Value) : Guid.NewGuid(); if (Source == SourceType.RawInput) { VendorID = int.Parse(xn.Attributes["vid"].Value, NumberStyles.HexNumber); ProductID = int.Parse(xn.Attributes["pid"].Value, NumberStyles.HexNumber); ReportHash = uint.Parse(xn.Attributes["rpt_hash"].Value); DeviceIndex = int.Parse(xn.Attributes["idx"].Value); } else if (Source == SourceType.XInput) { DeviceIndex = int.Parse(xn.Attributes["idx"].Value); } else if (Source == SourceType.MUNIA) { DevicePath = xn.Attributes["devicepath"].Value; } else if (Source == SourceType.Arduino) { string port = xn.Attributes["arduino_port"].Value; ArduinoPort = SerialPortInfo.GetPorts().FirstOrDefault(spi => spi.Name == port) ?? new SerialPortInfo { Name = port }; ArduinoSource = (ControllerType)Enum.Parse(typeof(ControllerType), xn.Attributes["arduino_type"].Value, true); } foreach (XmlNode n in xn["buttons"].ChildNodes) { var btn = new ButtonMap(); btn.LoadFrom(n); ButtonMaps.Add(btn); } foreach (XmlNode n in xn["axes"].ChildNodes) { var axis = new AxisMap(); axis.LoadFrom(n); AxisMaps.Add(axis); } foreach (XmlNode n in xn["buttons_to_axis"].ChildNodes) { var button = new ButtonToAxisMap(); button.LoadFrom(n); ButtonToAxisMaps.Add(button); } foreach (XmlNode n in xn["axis_to_buttons"].ChildNodes) { var axis = new AxisToButtonMap(); axis.LoadFrom(n); AxisToButtonMaps.Add(axis); } }
public void LoadFrom(XmlNode xn) { MappedType = (ControllerType)Enum.Parse(typeof(ControllerType), xn.Attributes["type"].Value, true); Source = (SourceType)Enum.Parse(typeof(SourceType), xn.Attributes["source"].Value, true); UUID = xn.Attributes["uuid"] != null?Guid.Parse(xn.Attributes["uuid"].Value) : Guid.NewGuid(); if (Source == SourceType.RawInput) { VendorID = int.Parse(xn.Attributes["vid"].Value, NumberStyles.HexNumber); ProductID = int.Parse(xn.Attributes["pid"].Value, NumberStyles.HexNumber); ReportHash = uint.Parse(xn.Attributes["rpt_hash"].Value); } DeviceIndex = int.Parse(xn.Attributes["idx"].Value); foreach (XmlNode n in xn["buttons"].ChildNodes) { var btn = new ButtonMap(); btn.LoadFrom(n); ButtonMaps.Add(btn); } foreach (XmlNode n in xn["axes"].ChildNodes) { var axis = new AxisMap(); axis.LoadFrom(n); AxisMaps.Add(axis); } foreach (XmlNode n in xn["buttons_to_axis"].ChildNodes) { var button = new ButtonToAxisMap(); button.LoadFrom(n); ButtonToAxisMaps.Add(button); } foreach (XmlNode n in xn["axis_to_buttons"].ChildNodes) { var axis = new AxisToButtonMap(); axis.LoadFrom(n); AxisToButtonMaps.Add(axis); } }