public bool SetXMLState(UUID itemID, string xml)
{
if (xml == String.Empty)
return false;
XmlDocument doc = new XmlDocument();
try
{
doc.LoadXml(xml);
}
catch (Exception)
{
m_log.Error("[XEngine]: Exception decoding XML data from region transfer");
return false;
}
XmlNodeList rootL = doc.GetElementsByTagName("State");
if (rootL.Count < 1)
return false;
XmlElement rootE = (XmlElement)rootL[0];
if (rootE.GetAttribute("Engine") != ScriptEngineName)
return false;
// On rez from inventory, that ID will have changed. It was only
// advisory anyway. So we don't check it anymore.
//
// if (rootE.GetAttribute("UUID") != itemID.ToString())
// return;
XmlNodeList stateL = rootE.GetElementsByTagName("ScriptState");
if (stateL.Count != 1)
return false;
XmlElement stateE = (XmlElement)stateL[0];
if (World.m_trustBinaries)
{
XmlNodeList assemL = rootE.GetElementsByTagName("Assembly");
if (assemL.Count != 1)
return false;
XmlElement assemE = (XmlElement)assemL[0];
string fn = assemE.GetAttribute("Filename");
string base64 = assemE.InnerText;
string path = Path.Combine(m_ScriptEnginesPath, World.RegionInfo.RegionID.ToString());
path = Path.Combine(path, fn);
if (!File.Exists(path))
{
Byte[] filedata = Convert.FromBase64String(base64);
try
{
using (FileStream fs = File.Create(path))
{
fs.Write(filedata, 0, filedata.Length);
fs.Close();
}
}
catch (IOException ex)
{
// if there already exists a file at that location, it may be locked.
m_log.ErrorFormat("[XEngine]: File {0} already exists! {1}", path, ex.Message);
}
try
{
using (FileStream fs = File.Create(path + ".text"))
{
using (StreamWriter sw = new StreamWriter(fs))
{
sw.Write(base64);
sw.Close();
}
fs.Close();
}
}
catch (IOException ex)
{
// if there already exists a file at that location, it may be locked.
m_log.ErrorFormat("[XEngine]: File {0} already exists! {1}", path, ex.Message);
}
}
}
string statepath = Path.Combine(m_ScriptEnginesPath, World.RegionInfo.RegionID.ToString());
statepath = Path.Combine(statepath, itemID.ToString() + ".state");
try
{
using (FileStream sfs = File.Create(statepath))
{
using (StreamWriter ssw = new StreamWriter(sfs))
{
ssw.Write(stateE.OuterXml);
ssw.Close();
}
sfs.Close();
}
}
catch (IOException ex)
{
// if there already exists a file at that location, it may be locked.
m_log.ErrorFormat("[XEngine]: File {0} already exists! {1}", statepath, ex.Message);
}
XmlNodeList mapL = rootE.GetElementsByTagName("LineMap");
if (mapL.Count > 0)
{
XmlElement mapE = (XmlElement)mapL[0];
string mappath = Path.Combine(m_ScriptEnginesPath, World.RegionInfo.RegionID.ToString());
mappath = Path.Combine(mappath, mapE.GetAttribute("Filename"));
try
{
using (FileStream mfs = File.Create(mappath))
{
using (StreamWriter msw = new StreamWriter(mfs))
{
msw.Write(mapE.InnerText);
msw.Close();
}
mfs.Close();
}
}
catch (IOException ex)
{
// if there already exists a file at that location, it may be locked.
m_log.ErrorFormat("[XEngine]: File {0} already exists! {1}", statepath, ex.Message);
}
}
return true;
}