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, '-'))); } } } }
public PTPName(int index, string oldName, string newName) { Index = index; NewName = newName; OldName = StringTool.SplitString(oldName, '-'); }