public void RemoveReplayFromAvailables(String ReplayPath) { //Remove from available replays if (AvailableReplays.ContainsKey(ReplayPath)) { //Remove from dictionary AvailableReplays.Remove(ReplayPath); //Remove from XML XmlDocument doc = new XmlDocument(); doc.Load(xmlPath); XmlNode rootNode = doc.SelectSingleNode("Root"); foreach (XmlNode node in rootNode.ChildNodes) { if (node["ReplayPath"].InnerXml == ReplayPath) { rootNode.RemoveChild(node); doc.Save(xmlPath); break; } } } //Remove from available comments if (Comments.ContainsKey(ReplayPath)) { //Remove from dictionary Comments.Remove(ReplayPath); //Remove from XML XmlDocument doc = new XmlDocument(); doc.Load(xmlAdditionalInfoPath); XmlNode rootNode = doc.SelectSingleNode("Root"); foreach (XmlNode comment in rootNode.ChildNodes) { if (comment["ReplayPath"].InnerXml == ReplayPath) { rootNode.RemoveChild(comment); doc.Save(xmlAdditionalInfoPath); break; } } } }
/// <summary> /// Adds a newly parsed replay to the list of available files to display in MainWindow. /// </summary> /// <param name="ReplayPath">The path of the *.sc2replay</param> /// <param name="DataPath">The path of the *.xml</param> public void AddParsedReplayToAvailables(String ReplayPath, String DataPath) { //Adding the newly parsed replays to the XML. if (File.Exists(ReplayPath) && File.Exists(DataPath)) { XmlDocument doc = new XmlDocument(); if (!File.Exists(xmlPath)) { //XML version declaration XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration, "", ""); doc.AppendChild(xmlnode); //Adding a root element, cannot have empty XML. XmlElement rootElement = SerializeElement(doc, "Root", ""); doc.AppendChild(rootElement); doc.Save(xmlPath); } doc.Load(xmlPath); XmlNode rootNode = doc.SelectSingleNode("Root"); XmlElement availableReplayNode = doc.CreateElement("AvailableReplay"); XmlElement replayPathNode = SerializeElement(doc, "ReplayPath", ReplayPath); XmlElement dataPathNode = SerializeElement(doc, "DataPath", DataPath); availableReplayNode.AppendChild(replayPathNode); availableReplayNode.AppendChild(dataPathNode); rootNode.AppendChild(availableReplayNode); doc.Save(xmlPath); //Adding the newly available replays to the dictionary. if (AvailableReplays == null) { AvailableReplays = new Dictionary <String, String>(); } if (!AvailableReplays.ContainsKey(ReplayPath)) { AvailableReplays.Add(ReplayPath, DataPath); } } }