Exemple #1
0
 public XMLdata(NodeInfo Info) : this()
 {
     nodeinfo = NewNodeinfo(Info);
 }
Exemple #2
0
        public static List <XMLdata> ReadFolder(string modname, string language)
        {
            string            OriPath  = StaticVars.DIRBASE + modname + "\\Defs\\";
            string            EngPath  = StaticVars.DIRBASE + modname + "\\Languages\\English\\";
            string            ChnPath  = StaticVars.DIRBASE + modname + "\\Languages\\" + language + "\\";
            List <NodeInfo>   nodeori  = new List <NodeInfo>();
            List <NodeInfo>   nodeeng  = new List <NodeInfo>();
            List <NodeInfo>   nodechn  = new List <NodeInfo>();
            XmlDocument       xdoc     = new XmlDocument();
            XmlReaderSettings settings = new XmlReaderSettings()
            {
                IgnoreComments = true
            };

            NodeInfo XNodeInfo = new NodeInfo()
            {
                FileName = "", SubFolder = "", TypeFolder = "", NodeName = "", NodeText = ""
            };
            XMLdata        Xdata;
            List <XMLdata> lstXMLdata = new List <XMLdata>();
            Dictionary <string, NodeInfo> DestDict = new Dictionary <string, NodeInfo>();
            Dictionary <string, NodeInfo> EngDict  = new Dictionary <string, NodeInfo>();

            XNodeInfo.TypeFolder = "Keyed";
            if (Directory.Exists(EngPath + "Keyed\\"))
            {
                nodeeng.AddRange(ReadFileList(Directory.GetFiles(EngPath + "Keyed\\")));
            }
            else if (Directory.Exists(ChnPath + "Keyed\\"))
            {
                nodeeng.AddRange(ReadFileList(Directory.GetFiles(ChnPath + "Keyed\\")));
            }
            if (Directory.Exists(ChnPath + "Keyed\\"))
            {
                nodechn.AddRange(ReadFileList(Directory.GetFiles(ChnPath + "Keyed\\")));
            }
            // 读取Keyed下的中文和英文文本

            XNodeInfo.TypeFolder = "DefInjected";
            if (Directory.Exists(EngPath + "\\DefInjected\\"))
            {
                foreach (string dir in Directory.GetDirectories(EngPath + "\\DefInjected\\"))
                {
                    XNodeInfo.SubFolder = Path.GetFileName(dir);
                    nodeeng.AddRange(ReadFileList(Directory.GetFiles(Path.GetFullPath(dir))));
                }
            }
            else if (Directory.Exists(ChnPath + "\\DefInjected\\"))
            {
                foreach (string dir in Directory.GetDirectories(ChnPath + "\\DefInjected\\"))
                {
                    XNodeInfo.SubFolder = Path.GetFileName(dir);
                    nodeeng.AddRange(ReadFileList(Directory.GetFiles(Path.GetFullPath(dir))));
                }
            }
            if (Directory.Exists(ChnPath + "\\DefInjected\\"))
            {
                foreach (string dir in Directory.GetDirectories(ChnPath + "\\DefInjected\\"))
                {
                    XNodeInfo.SubFolder = Path.GetFileName(dir);
                    nodechn.AddRange(ReadFileList(Directory.GetFiles(Path.GetFullPath(dir))));
                }
            }
            // 读取DefInjected下的中文和英文文本

            foreach (NodeInfo no in nodechn)
            {
                DestDict.Add(no.NodeKey, new NodeInfo()
                {
                    FileName = no.FileName, NodeName = no.NodeName, NodeText = no.NodeText, SubFolder = no.SubFolder, TypeFolder = no.TypeFolder
                });
            }
            // 把中文内容生成词典

            foreach (NodeInfo no in nodeeng)
            {
                EngDict.Add(no.NodeKey, new NodeInfo()
                {
                    FileName = no.FileName, NodeName = no.NodeName, NodeText = no.NodeText, SubFolder = no.SubFolder, TypeFolder = no.TypeFolder
                });
            }
            // 将英文文本生成词典

            ////////////////////

            // 读取Def文件夹中有关英文文本的定义部分
            nodeori = ReadOriginal(OriPath);
            foreach (NodeInfo ss in nodeori)
            {
                Xdata = new XMLdata(ss);
                lstXMLdata.Add(Xdata);
            }
            // 将定义的英文文本生成初始总表

            foreach (XMLdata data in lstXMLdata)
            {
                EngDict.TryGetValue(data.NodeKey(), out NodeInfo s);
                if (s != null)
                {
                    string t = s.NodeText;
                    data.SetDest(t);
                }
                EngDict.Remove(data.NodeKey());
            }
            // 从英文词典中查询词条并插入到总表中。

            foreach (NodeInfo ss in EngDict.Values)
            {
                Xdata = new XMLdata(ss, true);
                lstXMLdata.Add(Xdata);
            }
            // 英文字典剩余的部分追加到总表。用以保留自己额外添加的文本
            ////////////////////

            foreach (XMLdata data in lstXMLdata)
            {
                DestDict.TryGetValue(data.NodeKey(), out NodeInfo s);
                if (s != null)
                {
                    string t = s.NodeText;
                    data.SetDest(t);
                }

                DestDict.Remove(data.NodeKey());
            }
            // 从中文字典中查询词条并插入到总表中。

            foreach (NodeInfo ss in DestDict.Values)
            {
                Xdata = new XMLdata(ss, false);
                lstXMLdata.Add(Xdata);
            }
            // 中文字典剩余的部分追加到总表。用以保留自己额外添加的文本

            return(lstXMLdata);

            ////////////////////////////////// 以下是调用到的子函数

            List <NodeInfo> ReadFileList(string[] list)
            {
                List <NodeInfo> data = new List <NodeInfo>();

                if (list.Length > 0)
                {
                    foreach (string str in list)
                    {
                        XNodeInfo.FileName = Path.GetFileName(str);
                        xdoc.Load(XmlReader.Create(str, settings));

                        XmlNode xn = xdoc.ChildNodes[1];
                        foreach (XmlNode nn in xn.ChildNodes)
                        {
                            data.Add(new NodeInfo()
                            {
                                FileName = XNodeInfo.FileName, NodeName = nn.Name, NodeText = nn.InnerText, SubFolder = XNodeInfo.SubFolder, TypeFolder = XNodeInfo.TypeFolder
                            });
                        }
                    }
                }
                return(data);
            }

            List <NodeInfo> ReadOriginal(string path)
            {
                List <NodeInfo> data   = new List <NodeInfo>();
                NodeInfo        nodels = new NodeInfo();
                string          dename = "";

                if (!Directory.Exists(path))
                {
                    return(data);
                }

                foreach (string folders in Directory.GetDirectories(path))
                {
                    foreach (string file in Directory.GetFiles(folders))
                    {
                        nodels = new NodeInfo()
                        {
                            TypeFolder = "DefInjected"
                        };

                        nodels.FileName = Path.GetFileName(file);
                        xdoc.Load(XmlReader.Create(file, settings));
                        XmlNode     n   = xdoc.ChildNodes[1];
                        XmlNodeList lst = n.ChildNodes;
                        foreach (XmlNode xn in lst)
                        {
                            nodels.SubFolder = xn.Name;
                            foreach (XmlNode xnn in xn.ChildNodes)
                            {
                                if (xnn.Name == "defName")
                                {
                                    dename = xnn.InnerText;
                                }
                                switch (xnn.Name.ToLower())
                                {
                                case "defname":
                                    dename = xnn.InnerText;
                                    break;

                                default:
                                    break;
                                }
                                if (dename != "")
                                {
                                    switch (xnn.Name.ToLower())
                                    {
                                    case "label":
                                    case "description":
                                    case "deathmessage":
                                    case "jobstring":

                                        nodels.NodeName = GetNodeName(dename, xnn.Name.ToLower());
                                        nodels.NodeText = xnn.InnerText;
                                        data.Add(Getnewnode(nodels));
                                        break;

                                    default:
                                        break;
                                    }
                                }
                            }
                            dename = "";
                        }
                    }
                }
                return(data);
            }
        }