using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace 开发辅助工具.Manager
{
    class ReactorXML
    {
        public ReactorXML()
        {

        }
        private string xml_path = "";
        /// <summary>
        /// 加载xml
        /// </summary>
        /// <param name="_xml_path"></param>
        public void LoadXML(string _xml_path)
        {
            xml_path = _xml_path;
        }
        public void Save(string _xml_path,List<string> files)
        {
            if (files.Count == 0) { return; }
            System.Xml.XmlDocument xml = new System.Xml.XmlDocument();
            xml.Load(xml_path);
            var list = xml.SelectNodes(@"Reactor_Project/Assembly");
            for (int i = 0; i < list.Count; i++)
            {
                list[i].ParentNode.RemoveChild(list[i]);
            }
            //var node_Target_File = xml.SelectSingleNode(@"Reactor_Project//General_Settings//Target_File");
            //if (node_Target_File != null)
            //{
            //    node_Target_File.InnerText = files[0];
            //}
            var node = xml.SelectSingleNode(@"Reactor_Project/Main_Assembly");
            if (node != null)
            {
                node.InnerText = files[0];
            }
            for (int i = 1; i < files.Count; i++)
            {
                var node2 = xml.SelectSingleNode(@"Reactor_Project");
                XmlNode childXmlNode = xml.CreateElement("Assembly");
                XmlNode childXmlNode2 = xml.CreateElement("Filename");
                childXmlNode2.InnerText = files[i];
                childXmlNode.AppendChild(childXmlNode2);
                node2.InsertAfter(childXmlNode, node);
                //node.AppendChild(childXmlNode);;
            }
            xml.Save(_xml_path);
        }
    }
}
