private static void LoadXml()
{
if (!Utils.FileExists(filePath))
{
UpdateXml();
}
XmlDocument xmlDoc = new XmlDocument();
try
{
xmlDoc.Load(filePath);
}
catch (XmlException e)
{
Log.Error(string.Format("[SERVERTOOLS] Failed loading {0}: {1}", file, e.Message));
return;
}
XmlNode _XmlNode = xmlDoc.DocumentElement;
foreach (XmlNode childNode in _XmlNode.ChildNodes)
{
if (childNode.Name == "Messages")
{
dict.Clear();
foreach (XmlNode subChild in childNode.ChildNodes)
{
if (subChild.NodeType == XmlNodeType.Comment)
{
continue;
}
if (subChild.NodeType != XmlNodeType.Element)
{
Log.Warning(string.Format("[SERVERTOOLS] Unexpected XML node found in 'Messages' section: {0}", subChild.OuterXml));
continue;
}
XmlElement _line = (XmlElement)subChild;
if (!_line.HasAttribute("id"))
{
Log.Warning(string.Format("[SERVERTOOLS] Ignoring Message entry because of missing 'id' attribute: {0}", subChild.OuterXml));
continue;
}
if (!_line.HasAttribute("Message"))
{
Log.Warning(string.Format("[SERVERTOOLS] Ignoring Message entry because of missing a Message attribute: {0}", subChild.OuterXml));
continue;
}
int _id;
if (!int.TryParse(_line.GetAttribute("id"), out _id))
{
Log.Warning(string.Format("[SERVERTOOLS] Ignoring Message entry because of invalid (non-numeric) value for 'id' attribute: {0}", subChild.OuterXml));
continue;
}
if (!dict.ContainsKey(_line.GetAttribute("Message")))
{
dict.Add(_line.GetAttribute("Message"), _id);
}
}
}
}
}