public void SaveIn(ModContentPack mod)
        {
            string    fullFolderPath = this.GetFullFolderPath(mod);
            string    str            = Path.Combine(fullFolderPath, this.fileName);
            XDocument xDocument      = new XDocument();
            XElement  xElement       = new XElement("DefPackage");

            xDocument.Add(xElement);
            try
            {
                foreach (Def def in this.defs)
                {
                    XElement content = DirectXmlSaver.XElementFromObject(def, def.GetType());
                    xElement.Add(content);
                }
                DirectXmlSaveFormatter.AddWhitespaceFromRoot(xElement);
                SaveOptions options = SaveOptions.DisableFormatting;
                xDocument.Save(str, options);
                Messages.Message("Saved in " + str, MessageTypeDefOf.PositiveEvent);
            }
            catch (Exception ex)
            {
                Messages.Message("Exception saving XML: " + ex.ToString(), MessageTypeDefOf.NegativeEvent);
                throw;
            }
        }
Beispiel #2
0
        private static void IndentXml(XElement element, int depth)
        {
            element.AddBeforeSelf(new XText(DirectXmlSaveFormatter.IndentString(depth, true)));
            bool startWithNewline = element.NextNode == null;

            element.AddAfterSelf(new XText(DirectXmlSaveFormatter.IndentString(depth - 1, startWithNewline)));
            foreach (XElement element2 in element.Elements().ToList <XElement>())
            {
                DirectXmlSaveFormatter.IndentXml(element2, depth + 1);
            }
        }
Beispiel #3
0
 public static void AddWhitespaceFromRoot(XElement root)
 {
     if (root.Elements().Any())
     {
         foreach (XElement item in root.Elements().ToList())
         {
             XText content = new XText("\n");
             item.AddAfterSelf(content);
         }
         root.Elements().First().AddBeforeSelf(new XText("\n"));
         root.Elements().Last().AddAfterSelf(new XText("\n"));
         foreach (XElement item2 in root.Elements().ToList())
         {
             DirectXmlSaveFormatter.IndentXml(item2, 1);
         }
     }
 }
Beispiel #4
0
 public static void AddWhitespaceFromRoot(XElement root)
 {
     if (!root.Elements().Any <XElement>())
     {
         return;
     }
     foreach (XElement xelement in root.Elements().ToList <XElement>())
     {
         XText content = new XText("\n");
         xelement.AddAfterSelf(content);
     }
     root.Elements().First <XElement>().AddBeforeSelf(new XText("\n"));
     root.Elements().Last <XElement>().AddAfterSelf(new XText("\n"));
     foreach (XElement element in root.Elements().ToList <XElement>())
     {
         DirectXmlSaveFormatter.IndentXml(element, 1);
     }
 }