Beispiel #1
0
        private void OpenXmlPTP(Stream stream)
        {
            XDocument xDoc = XDocument.Load(stream, LoadOptions.PreserveWhitespace);

            XElement MSG1Doc = xDoc.Element("MSG1");

            foreach (var NAME in MSG1Doc.Element("CharacterNames").Elements())
            {
                int    Index         = Convert.ToInt32(NAME.Attribute("Index").Value);
                string OldNameSource = NAME.Element("OldNameSource").Value;
                string NewName       = NAME.Element("NewName").Value;

                Names.Add(new PTPName(Index, OldNameSource, NewName));
            }

            foreach (var Message in MSG1Doc.Element("MSG").Elements())
            {
                int    Index = Convert.ToInt32(Message.Attribute("Index").Value);
                int    Type  = Message.Element("Type").Value == "MSG" ? 0 : 1;
                string Name  = Message.Element("Name").Value;
                int    CharacterNameIndex = Convert.ToInt32(Message.Element("CharacterNameIndex").Value);

                PTPMSG temp = new PTPMSG(Index, Type, Name, CharacterNameIndex);
                Msg.Add(temp);

                foreach (var Strings in Message.Element("MessageStrings").Elements())
                {
                    int    StringIndex = Convert.ToInt32(Strings.Attribute("Index").Value);
                    string NewString   = Strings.Element("NewString").Value;

                    PTPMSGstr temp2 = new PTPMSGstr(StringIndex, NewString)
                    {
                        CharacterIndex = CharacterNameIndex
                    };
                    temp.Strings.Add(temp2);

                    foreach (var Prefix in Strings.Elements("PrefixBytes"))
                    {
                        int    PrefixIndex = Convert.ToInt32(Prefix.Attribute("Index").Value);
                        string PrefixType  = Prefix.Attribute("Type").Value;
                        string PrefixBytes = Prefix.Value;

                        temp2.Prefix.Add(new TextBaseElement(PrefixType == "Text" ? true : false, StringTool.SplitString(PrefixBytes, '-')));
                    }

                    foreach (var Old in Strings.Elements("OldStringBytes"))
                    {
                        int    OldIndex = Convert.ToInt32(Old.Attribute("Index").Value);
                        string OldType  = Old.Attribute("Type").Value;
                        string OldBytes = Old.Value;

                        temp2.OldString.Add(new TextBaseElement(OldType == "Text" ? true : false, StringTool.SplitString(OldBytes, '-')));
                    }

                    foreach (var Postfix in Strings.Elements("PostfixBytes"))
                    {
                        int    PostfixIndex = Convert.ToInt32(Postfix.Attribute("Index").Value);
                        string PostfixType  = Postfix.Attribute("Type").Value;
                        string PostfixBytes = Postfix.Value;

                        temp2.Postfix.Add(new TextBaseElement(PostfixType == "Text" ? true : false, StringTool.SplitString(PostfixBytes, '-')));
                    }
                }
            }
        }
Beispiel #2
0
        public bool Open(string path)
        {
            try
            {
                names.Clear();
                msg.Clear();

                XDocument xDoc = XDocument.Load(path, LoadOptions.PreserveWhitespace);

                XElement MSG1Doc = xDoc.Element("MSG1");

                foreach (var NAME in MSG1Doc.Element("CharacterNames").Elements())
                {
                    int    Index         = Convert.ToInt32(NAME.Attribute("Index").Value);
                    string OldNameSource = NAME.Element("OldNameSource").Value;
                    string NewName       = NAME.Element("NewName").Value;

                    names.Add(new Names(Index, OldNameSource, NewName, NewCharList));
                }

                foreach (var Message in MSG1Doc.Element("MSG").Elements())
                {
                    int    Index = Convert.ToInt32(Message.Attribute("Index").Value);
                    string Type  = Message.Element("Type").Value;
                    string Name  = Message.Element("Name").Value;
                    int    CharacterNameIndex = Convert.ToInt32(Message.Element("CharacterNameIndex").Value);

                    string SourceBytes_str = Message.Element("SourceBytes").Value;

                    MSG temp = new MSG(Index, Type, Name, CharacterNameIndex, SourceBytes_str);
                    msg.Add(temp);

                    foreach (var Strings in Message.Element("MessageStrings").Elements())
                    {
                        int    StringIndex = Convert.ToInt32(Strings.Attribute("Index").Value);
                        string NewString   = Strings.Element("NewString").Value;

                        MSG.MSGstr temp2 = new MSG.MSGstr(StringIndex, NewString, NewCharList)
                        {
                            CharacterIndex = CharacterNameIndex
                        };
                        temp.Strings.Add(temp2);

                        foreach (var Prefix in Strings.Elements("PrefixBytes"))
                        {
                            int    PrefixIndex = Convert.ToInt32(Prefix.Attribute("Index").Value);
                            string PrefixType  = Prefix.Attribute("Type").Value;
                            string PrefixBytes = Prefix.Value;

                            temp2.Prefix.Add(new TextBaseElement(PrefixType, Utilities.String.SplitString(PrefixBytes, '-')));
                        }

                        foreach (var Old in Strings.Elements("OldStringBytes"))
                        {
                            int    OldIndex = Convert.ToInt32(Old.Attribute("Index").Value);
                            string OldType  = Old.Attribute("Type").Value;
                            string OldBytes = Old.Value;

                            temp2.OldString.Add(new TextBaseElement(OldType, Utilities.String.SplitString(OldBytes, '-')));
                        }

                        foreach (var Postfix in Strings.Elements("PostfixBytes"))
                        {
                            int    PostfixIndex = Convert.ToInt32(Postfix.Attribute("Index").Value);
                            string PostfixType  = Postfix.Attribute("Type").Value;
                            string PostfixBytes = Postfix.Value;

                            temp2.Postfix.Add(new TextBaseElement(PostfixType, Utilities.String.SplitString(PostfixBytes, '-')));
                        }
                    }
                }

                OpenFileName = Path.GetFileName(Path.GetFullPath(path));
                return(true);
            }
            catch (Exception e)
            {
                names.Clear();
                msg.Clear();
                OpenFileName = "";
                Logging.Write("PTPfactory", e.ToString());
                return(false);
            }
        }