From 27453890d5a5d09e47c638ccef92f45b1ce360b2 Mon Sep 17 00:00:00 2001 From: Melanie Date: Mon, 21 Dec 2009 10:26:52 +0000 Subject: Script State Fix: Part 2 Change the reader to wrap old-style definitions in new style wrappers. Change importer to not check irrelevant data that can't be reconstructed This removes the last bit of knowledge of XEngine's .state files from core. --- .../Region/Framework/Interfaces/IScriptModule.cs | 2 +- .../Framework/Scenes/SceneObjectPartInventory.cs | 55 +++++++++++++++++++--- 2 files changed, 49 insertions(+), 8 deletions(-) (limited to 'OpenSim/Region/Framework') diff --git a/OpenSim/Region/Framework/Interfaces/IScriptModule.cs b/OpenSim/Region/Framework/Interfaces/IScriptModule.cs index f11e571..98efcbe 100644 --- a/OpenSim/Region/Framework/Interfaces/IScriptModule.cs +++ b/OpenSim/Region/Framework/Interfaces/IScriptModule.cs @@ -35,7 +35,7 @@ namespace OpenSim.Region.Framework.Interfaces string ScriptEngineName { get; } string GetXMLState(UUID itemID); - void SetXMLState(UUID itemID, string xml); + bool SetXMLState(UUID itemID, string xml); bool PostScriptEvent(UUID itemID, string name, Object[] args); bool PostObjectEvent(UUID itemID, string name, Object[] args); diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs index 22eedba..47e4ad0 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs @@ -26,6 +26,7 @@ */ using System; +using System.Xml; using System.IO; using System.Collections.Generic; using System.Reflection; @@ -283,15 +284,55 @@ namespace OpenSim.Region.Framework.Scenes private void RestoreSavedScriptState(UUID oldID, UUID newID) { + IScriptModule[] engines = m_part.ParentGroup.Scene.RequestModuleInterfaces(); + if (engines == null) // No engine at all + return; + if (m_part.ParentGroup.m_savedScriptState.ContainsKey(oldID)) { - string fpath = Path.Combine("ScriptEngines/"+m_part.ParentGroup.Scene.RegionInfo.RegionID.ToString(), - newID.ToString()+".state"); - FileStream fs = File.Create(fpath); - Byte[] buffer = enc.GetBytes(m_part.ParentGroup.m_savedScriptState[oldID]); - fs.Write(buffer,0,buffer.Length); - fs.Close(); - m_part.ParentGroup.m_savedScriptState.Remove(oldID); + XmlDocument doc = new XmlDocument(); + + doc.LoadXml(m_part.ParentGroup.m_savedScriptState[oldID]); + + ////////// CRUFT WARNING /////////////////////////////////// + // + // Old objects will have ... + // This format is XEngine ONLY + // + // New objects have ... + // This can be passed to any engine + // + XmlNode n = doc.SelectSingleNode("ScriptState"); + if (n != null) // Old format data + { + XmlDocument newDoc = new XmlDocument(); + + XmlElement rootN = newDoc.CreateElement("", "State", ""); + XmlAttribute uuidA = newDoc.CreateAttribute("", "UUID", ""); + uuidA.Value = oldID.ToString(); + rootN.Attributes.Append(uuidA); + XmlAttribute engineA = newDoc.CreateAttribute("", "Engine", ""); + engineA.Value = "XEngine"; + rootN.Attributes.Append(engineA); + + newDoc.AppendChild(rootN); + + XmlNode stateN = newDoc.ImportNode(n, true); + rootN.AppendChild(stateN); + + // This created document has only the minimun data + // necessary for XEngine to parse it successfully + + m_part.ParentGroup.m_savedScriptState[oldID] = newDoc.OuterXml; + } + foreach (IScriptModule e in engines) + { + if (e != null) + { + if (e.SetXMLState(newID, m_part.ParentGroup.m_savedScriptState[oldID])) + break; + } + } } } -- cgit v1.1