/// <summary> /// Crea un nuevo fichere XML de solo lectura para el mando. /// </summary> /// <param name="XMLUri"></param> /// <param name="objetoMando"></param> public static void updateXML(Mando mando) { File.SetAttributes(mando.XmlUri, FileAttributes.Normal); File.Delete(mando.XmlUri); using (System.IO.StreamWriter file = new System.IO.StreamWriter(mando.XmlUri)) { file.WriteLine("<Mando name='" + mando.Name + "' modificable='" + mando.Modificable + "'>"); Dictionary <string, Dictionary <string, Keys> > grupos = mando.Grupos; foreach (string keys in grupos.Keys) { file.WriteLine("\t<group name='" + keys + "'>"); Dictionary <string, Keys> buttons = grupos[keys]; foreach (string btn in buttons.Keys) { file.WriteLine("\t\t<btn name='" + btn + "' valor='" + buttons[btn] + "' />"); } file.WriteLine("\t</group>"); } file.WriteLine("</Mando>"); } File.SetAttributes(mando.XmlUri, FileAttributes.ReadOnly); }
/// <summary> /// Obtiene un mando a partir de un fichero XML de sistema. /// </summary> /// <param name="nombreMando">Nombre del mando</param> /// <returns>Objeto Mando</returns> public static List <Mando> getMandos(string XMLUri) { List <Mando> mandos = new List <Mando>(); foreach (string file in Directory.EnumerateFiles(XMLUri, "*.xml")) { Mando mando = new Mando(); XmlDocument doc = new XmlDocument(); doc.Load(file); XmlNode principal_node = doc["Mando"]; mando.XmlUri = file; mando.Name = principal_node.Attributes["name"].InnerText; mando.Icon = new BitmapImage(); mando.Icon.BeginInit(); mando.Icon.UriSource = new Uri("/Resources/Icons/Mandos/" + mando.Name + ".png", UriKind.RelativeOrAbsolute); mando.Icon.EndInit(); mando.Modificable = (principal_node.Attributes["modificable"].InnerText.ToLower() == "true") ? true : false; foreach (XmlNode secondary_nodes in principal_node.ChildNodes) { string groupName = secondary_nodes.Attributes["name"].InnerText; mando.addGroup(groupName); foreach (XmlNode btn_node in secondary_nodes.ChildNodes) { mando.addButton(groupName, btn_node.Attributes["name"].InnerText, btn_node.Attributes["valor"].InnerText); } } mandos.Add(mando); } return(mandos); }