From 2681de366b22d1fc57d808c0cd98da0426a0379e Mon Sep 17 00:00:00 2001
From: MW
Date: Mon, 22 Oct 2007 11:06:54 +0000
Subject: Made some changes to the load/save xml format, So that the old format
can still be used, I have added new console commands of "load-xml2" and
"save-xml2", if the old versions worked for you then please continue using
them (at least for now). The new versions haven't been tested that much, so
their format could be subject to change.
---
OpenSim/Region/Application/OpenSimMain.cs | 23 ++++++++-
OpenSim/Region/Environment/Scenes/Scene.cs | 58 ++++++++++++++++++++++
OpenSim/Region/Environment/Scenes/SceneManager.cs | 10 ++++
.../Region/Environment/Scenes/SceneObjectGroup.cs | 33 ++++++++++--
4 files changed, 120 insertions(+), 4 deletions(-)
(limited to 'OpenSim')
diff --git a/OpenSim/Region/Application/OpenSimMain.cs b/OpenSim/Region/Application/OpenSimMain.cs
index c367537..d2f5648 100644
--- a/OpenSim/Region/Application/OpenSimMain.cs
+++ b/OpenSim/Region/Application/OpenSimMain.cs
@@ -146,7 +146,6 @@ namespace OpenSim
m_networkServersInfo.loadFromConfiguration(m_config);
}
-
///
/// Performs initialisation of the scene, such as loading configuration from disk.
///
@@ -485,6 +484,28 @@ namespace OpenSim
}
break;
+ case "save-xml2":
+ if (cmdparams.Length > 0)
+ {
+ m_sceneManager.SaveCurrentSceneToXml2(cmdparams[0]);
+ }
+ else
+ {
+ m_sceneManager.SaveCurrentSceneToXml2(DEFAULT_PRIM_BACKUP_FILENAME);
+ }
+ break;
+
+ case "load-xml2":
+ if (cmdparams.Length > 0)
+ {
+ m_sceneManager.LoadCurrentSceneFromXml2(cmdparams[0]);
+ }
+ else
+ {
+ m_sceneManager.LoadCurrentSceneFromXml2(DEFAULT_PRIM_BACKUP_FILENAME);
+ }
+ break;
+
case "terrain":
if (!m_sceneManager.RunTerrainCmdOnCurrentScene(cmdparams, ref result))
{
diff --git a/OpenSim/Region/Environment/Scenes/Scene.cs b/OpenSim/Region/Environment/Scenes/Scene.cs
index f7e3543..553e55f 100644
--- a/OpenSim/Region/Environment/Scenes/Scene.cs
+++ b/OpenSim/Region/Environment/Scenes/Scene.cs
@@ -709,6 +709,64 @@ namespace OpenSim.Region.Environment.Scenes
file.Close();
}
+ public void LoadPrimsFromXml2(string fileName)
+ {
+ XmlDocument doc = new XmlDocument();
+ XmlNode rootNode;
+ if ((fileName.StartsWith("http:")) | (File.Exists(fileName)))
+ {
+ XmlTextReader reader = new XmlTextReader(fileName);
+ reader.WhitespaceHandling = WhitespaceHandling.None;
+ doc.Load(reader);
+ reader.Close();
+ rootNode = doc.FirstChild;
+ foreach (XmlNode aPrimNode in rootNode.ChildNodes)
+ {
+ CreatePrimFromXml(aPrimNode.OuterXml);
+ }
+ }
+ else
+ {
+ throw new Exception("Could not open file " + fileName + " for reading");
+ }
+ }
+
+ public void CreatePrimFromXml(string xmlData)
+ {
+ SceneObjectGroup obj = new SceneObjectGroup(xmlData);
+ AddEntityFromStorage(obj);
+
+ SceneObjectPart rootPart = obj.GetChildPart(obj.UUID);
+ if ((rootPart.ObjectFlags & (uint)LLObject.ObjectFlags.Phantom) == 0)
+ rootPart.PhysActor = phyScene.AddPrimShape(
+ rootPart.Name,
+ rootPart.Shape,
+ new PhysicsVector(rootPart.AbsolutePosition.X, rootPart.AbsolutePosition.Y,
+ rootPart.AbsolutePosition.Z),
+ new PhysicsVector(rootPart.Scale.X, rootPart.Scale.Y, rootPart.Scale.Z),
+ new Quaternion(rootPart.RotationOffset.W, rootPart.RotationOffset.X,
+ rootPart.RotationOffset.Y, rootPart.RotationOffset.Z));
+ }
+
+ public void SavePrimsToXml2(string fileName)
+ {
+ FileStream file = new FileStream(fileName, FileMode.Create);
+ StreamWriter stream = new StreamWriter(file);
+ int primCount = 0;
+ stream.WriteLine("\n");
+ foreach (EntityBase ent in Entities.Values)
+ {
+ if (ent is SceneObjectGroup)
+ {
+ stream.WriteLine(((SceneObjectGroup)ent).ToXmlString2());
+ primCount++;
+ }
+ }
+ stream.WriteLine("\n");
+ stream.Close();
+ file.Close();
+ }
+
#endregion
#region Add/Remove Avatar Methods
diff --git a/OpenSim/Region/Environment/Scenes/SceneManager.cs b/OpenSim/Region/Environment/Scenes/SceneManager.cs
index e3da550..d2718df 100644
--- a/OpenSim/Region/Environment/Scenes/SceneManager.cs
+++ b/OpenSim/Region/Environment/Scenes/SceneManager.cs
@@ -85,6 +85,16 @@ namespace OpenSim.Region.Environment.Scenes
public void LoadCurrentSceneFromXml(string filename)
{
CurrentOrFirstScene.LoadPrimsFromXml(filename);
+ }
+
+ public void SaveCurrentSceneToXml2(string filename)
+ {
+ CurrentOrFirstScene.SavePrimsToXml2(filename);
+ }
+
+ public void LoadCurrentSceneFromXml2(string filename)
+ {
+ CurrentOrFirstScene.LoadPrimsFromXml2(filename);
}
public bool RunTerrainCmdOnCurrentScene(string[] cmdparams, ref string result)
diff --git a/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs b/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs
index 1839051..bb2eadb 100644
--- a/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs
+++ b/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs
@@ -272,7 +272,6 @@ namespace OpenSim.Region.Environment.Scenes
reader.Read();
reader.ReadStartElement("SceneObjectGroup");
- // reader.ReadStartElement("RootPart");
m_rootPart = SceneObjectPart.FromXml(reader);
reader.Read();
@@ -286,8 +285,7 @@ namespace OpenSim.Region.Environment.Scenes
if (reader.Name == "SceneObjectPart")
{
SceneObjectPart Part = SceneObjectPart.FromXml(reader);
- AddPart(Part);
-
+ AddPart(Part);
}
break;
case XmlNodeType.EndElement:
@@ -375,6 +373,35 @@ namespace OpenSim.Region.Environment.Scenes
writer.WriteEndElement();
}
+ public string ToXmlString2()
+ {
+ using (StringWriter sw = new StringWriter())
+ {
+ using (XmlTextWriter writer = new XmlTextWriter(sw))
+ {
+ ToXml2(writer);
+ }
+
+ return sw.ToString();
+ }
+ }
+
+ public void ToXml2(XmlTextWriter writer)
+ {
+ writer.WriteStartElement(String.Empty, "SceneObjectGroup", String.Empty);
+ m_rootPart.ToXml(writer);
+ writer.WriteStartElement(String.Empty, "OtherParts", String.Empty);
+ foreach (SceneObjectPart part in m_parts.Values)
+ {
+ if (part.UUID != m_rootPart.UUID)
+ {
+ part.ToXml(writer);
+ }
+ }
+ writer.WriteEndElement();
+ writer.WriteEndElement();
+ }
+
#region Copying
///
--
cgit v1.1