public static IEnumerable <XmlKeyValuePair> ValuesFromXmlFile(VirtualFile file) { XDocument xDocument = file.LoadAsXDocument(); foreach (XElement item in xDocument.Root.Elements()) { string key = item.Name.ToString(); string value = item.Value; value = value.Replace("\\n", "\n"); XmlKeyValuePair xmlKeyValuePair = default(XmlKeyValuePair); xmlKeyValuePair.key = key; xmlKeyValuePair.value = value; xmlKeyValuePair.lineNumber = ((IXmlLineInfo)item).LineNumber; yield return(xmlKeyValuePair); } }
private static IEnumerable <XElement> BackstoryTranslationElements(IEnumerable <Tuple <VirtualDirectory, ModContentPack, string> > folders, List <string> loadErrors) { Dictionary <ModContentPack, HashSet <string> > alreadyLoadedFiles = new Dictionary <ModContentPack, HashSet <string> >(); foreach (Tuple <VirtualDirectory, ModContentPack, string> folder in folders) { if (!alreadyLoadedFiles.ContainsKey(folder.Item2)) { alreadyLoadedFiles[folder.Item2] = new HashSet <string>(); } VirtualFile file = folder.Item1.GetFile("Backstories/Backstories.xml"); if (!file.Exists) { continue; } if (!file.FullPath.StartsWith(folder.Item3)) { Log.Error("Failed to get a relative path for a file: " + file.FullPath + ", located in " + folder.Item3); continue; } string item = file.FullPath.Substring(folder.Item3.Length); if (alreadyLoadedFiles[folder.Item2].Contains(item)) { continue; } alreadyLoadedFiles[folder.Item2].Add(item); XDocument xDocument; try { xDocument = file.LoadAsXDocument(); } catch (Exception ex) { loadErrors?.Add(string.Concat("Exception loading backstory translation data from file ", file, ": ", ex)); yield break; } foreach (XElement item2 in xDocument.Root.Elements()) { yield return(item2); } } }
public void AddDataFromFile(VirtualFile file, out bool xmlParseError) { xmlParseError = false; try { foreach (XElement item in file.LoadAsXDocument().Root.Elements()) { if (item.Name == "rep") { string key = ProcessedPath(item.Elements("path").First().Value); string translation = ProcessedTranslation(item.Elements("trans").First().Value); TryAddInjection(file, key, translation); usedOldRepSyntax = true; } else { string text = ProcessedPath(item.Name.ToString()); if (text.EndsWith(".slateRef")) { if (item.HasElements) { TryAddInjection(file, text, item.GetInnerXml()); } else { string translation2 = ProcessedTranslation(item.Value); TryAddInjection(file, text, translation2); } } else if (item.HasElements) { List <string> list = new List <string>(); List <Pair <int, string> > list2 = null; bool flag = false; foreach (XNode item2 in item.DescendantNodes()) { XElement xElement = item2 as XElement; if (xElement != null) { if (xElement.Name == "li") { list.Add(ProcessedTranslation(xElement.Value)); } else if (!flag) { loadErrors.Add(text + " has elements which are not 'li' (" + file.Name + ")"); flag = true; } } XComment xComment = item2 as XComment; if (xComment != null) { if (list2 == null) { list2 = new List <Pair <int, string> >(); } list2.Add(new Pair <int, string>(list.Count, xComment.Value)); } } TryAddFullListInjection(file, text, list, list2); } else { string translation3 = ProcessedTranslation(item.Value); TryAddInjection(file, text, translation3); } } } } catch (Exception ex) { loadErrors.Add("Exception loading translation data from file " + file.Name + ": " + ex); xmlParseError = true; } }