/// <summary> /// Save the account database /// </summary> public static void Save() { string filePath = Persistance.GetSavePathname("accounts.xml"); using (StreamWriter sw = new StreamWriter(filePath)) { XmlTextWriter writer = new XmlTextWriter(sw); writer.Formatting = Formatting.Indented; writer.IndentChar = '\t'; writer.Indentation = 1; writer.WriteStartDocument(true); writer.WriteStartElement("accounts"); writer.WriteAttributeString("version", Account.AccountSaveVersion.ToString()); writer.WriteAttributeString("count", m_byId.Count.ToString()); foreach (Account a in m_byId.Values) { a.Serialize(writer); } writer.WriteEndElement(); writer.Close(); } }
private static void Load() { string filePath = Persistance.GetSavePathname("accounts.xml"); if (!File.Exists(filePath)) { Loaded = true; Console.WriteLine("Accounts: No account file found."); return; } XmlDocument doc = new XmlDocument(); doc.Load(filePath); XmlElement root = doc["accounts"]; int version = Persistance.Xml.GetXMLInt32(Persistance.Xml.GetAttribute(root, "version"), -1); int size = Persistance.Xml.GetXMLInt32(Persistance.Xml.GetAttribute(root, "count"), -1); foreach (XmlElement element in root.GetElementsByTagName("account")) { try { Account account = new Account(element, version); InternalAdd(account); } catch { Console.WriteLine("Account load failed"); } } Loaded = true; if (m_byId.Count != size) { Console.WriteLine("Accounts: Warning: Loaded {0} of {1} accounts.", m_byId.Count, size); } else { Console.WriteLine("Accounts: Loaded {0} accounts.", m_byId.Count); } }
/// <summary> /// Deserializes a list of IPAddress values from an xml element. /// </summary> /// <param name="node">The XmlElement from which to deserialize this subnode.</param> /// <param name="addressNodeName">The note within the XmlElement which contains the address list.</param> /// <returns>Address list, or null</returns> public static List <IPAddress> LoadAddressList(XmlElement node, string addressNodeName) { List <IPAddress> list = null; XmlElement addressList = node[addressNodeName]; if (addressList != null) { int count = GetXMLInt32(GetAttribute(addressList, "count", "0"), 0); list = new List <IPAddress>(count); foreach (XmlElement ip in addressList.GetElementsByTagName("ip")) { IPAddress address; if (IPAddress.TryParse(GetText(ip, null), out address)) { list.Add(Persistance.Intern(address)); } } } return(list); }