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.
prebuild-update
Justin Clark-Casey (justincc) 2010-07-26 19:56:55 +01:00
parent d764c95d09
commit afdbeba4e4
1 changed files with 43 additions and 15 deletions

View File

@ -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<MediaEntry> mediaEntries = new List<MediaEntry>();
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<MediaEntry> mediaEntries = new List<MediaEntry>();
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);
}
}