From afdbeba4e46f631b320b75bd304197959e650c2e Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 26 Jul 2010 19:56:55 +0100 Subject: Put a wrapper around the media texture region serialization THIS WILL BREAK EXISTING MEDIA TEXTURE PERSISTENCE. Please delete your existing sqlite databases if you are experimenting with this branch. This wrapper will make it easier to maintain compatibility if the media texture data evolves. This will also make it easier to store non-sl media texture data. --- OpenSim/Data/SQLite/SQLiteRegionData.cs | 58 ++++++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 15 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Data/SQLite/SQLiteRegionData.cs b/OpenSim/Data/SQLite/SQLiteRegionData.cs index 7acbd22..b564419 100644 --- a/OpenSim/Data/SQLite/SQLiteRegionData.cs +++ b/OpenSim/Data/SQLite/SQLiteRegionData.cs @@ -31,6 +31,7 @@ using System.Data; using System.Drawing; using System.IO; using System.Reflection; +using System.Xml; using log4net; using Mono.Data.Sqlite; using OpenMetaverse; @@ -1862,17 +1863,26 @@ namespace OpenSim.Data.SQLite if (!(row["Media"] is System.DBNull)) { - string rawMeArray = (string)row["Media"]; - OSDArray osdMeArray = (OSDArray)OSDParser.DeserializeLLSDXml(rawMeArray); - - List mediaEntries = new List(); - foreach (OSD osdMe in osdMeArray) + using (StringReader sr = new StringReader((string)row["Media"])) { - MediaEntry me = (osdMe is OSDMap ? MediaEntry.FromOSD(osdMe) : new MediaEntry()); - mediaEntries.Add(me); + using (XmlTextReader xtr = new XmlTextReader(sr)) + { + xtr.ReadStartElement("osmedia"); + + OSDArray osdMeArray = (OSDArray)OSDParser.DeserializeLLSDXml(xtr.ReadInnerXml()); + + List mediaEntries = new List(); + foreach (OSD osdMe in osdMeArray) + { + MediaEntry me = (osdMe is OSDMap ? MediaEntry.FromOSD(osdMe) : new MediaEntry()); + mediaEntries.Add(me); + } + + s.Media = mediaEntries; + + xtr.ReadEndElement(); + } } - - s.Media = mediaEntries; } return s; @@ -1921,14 +1931,32 @@ namespace OpenSim.Data.SQLite if (null != s.Media) { - OSDArray meArray = new OSDArray(); - foreach (MediaEntry me in s.Media) + using (StringWriter sw = new StringWriter()) { - OSD osd = (null == me ? new OSD() : me.GetOSD()); - meArray.Add(osd); + using (XmlTextWriter xtw = new XmlTextWriter(sw)) + { + xtw.WriteStartElement("osmedia"); + xtw.WriteAttributeString("type", "sl"); + xtw.WriteAttributeString("major_version", "0"); + xtw.WriteAttributeString("minor_version", "1"); + + OSDArray meArray = new OSDArray(); + foreach (MediaEntry me in s.Media) + { + OSD osd = (null == me ? new OSD() : me.GetOSD()); + meArray.Add(osd); + } + + xtw.WriteStartElement("osdata"); + xtw.WriteRaw(OSDParser.SerializeLLSDXmlString(meArray)); + xtw.WriteEndElement(); + + xtw.WriteEndElement(); + + xtw.Flush(); + row["Media"] = sw.ToString(); + } } - - row["Media"] = OSDParser.SerializeLLSDXmlString(meArray); } } -- cgit v1.1