29 using System.Collections.Generic;
31 using System.Reflection;
38 using OpenSim.Region.CoreModules.Framework.InterfaceCommander;
39 using OpenSim.Region.Framework.Interfaces;
40 using OpenSim.Region.Framework.Scenes;
41 using OpenSim.Region.Framework.Scenes.Serialization;
43 namespace OpenSim.
Region.CoreModules.
World.Serialiser
45 [Extension(Path =
"/OpenSim/RegionModules", NodeName =
"RegionModule", Id =
"SerialiserModule")]
48 private static readonly ILog m_log =
49 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
52 private List<Scene> m_regions =
new List<Scene>();
53 private string m_savedir =
"exports";
54 private List<IFileSerialiser> m_serialisers =
new List<IFileSerialiser>();
56 #region ISharedRegionModule Members
58 public Type ReplaceableInterface
65 IConfig config = source.Configs[
"Serialiser"];
68 m_savedir = config.GetString(
"save_dir", m_savedir);
71 m_log.InfoFormat(
"[Serialiser] Enabled, using save dir \"{0}\"", m_savedir);
78 m_serialisers.Add(
new SerialiseTerrain());
79 m_serialisers.Add(
new SerialiseObjects());
105 m_regions.Remove(scene);
116 get {
return "ExportSerialisationModule"; }
122 #region IRegionSerialiser Members
126 SceneXmlLoader.LoadPrimsFromXml(scene, fileName, newIDS, loadOffset);
131 SceneXmlLoader.SavePrimsToXml(scene, fileName);
136 SceneXmlLoader.LoadPrimsFromXml2(scene, fileName);
141 SceneXmlLoader.LoadPrimsFromXml2(scene, reader, startScripts);
146 SceneXmlLoader.SavePrimsToXml2(scene, fileName);
151 SceneXmlLoader.SavePrimsToXml2(scene, stream, min, max);
156 SceneXmlLoader.SaveNamedPrimsToXml2(scene, primName, fileName);
161 return SceneXmlLoader.DeserializeGroupFromXml2(xmlString);
166 return SceneXmlLoader.SaveGroupToXml2(grp,
options);
171 SceneXmlLoader.SavePrimListToXml2(entityList, fileName);
176 SceneXmlLoader.SavePrimListToXml2(entityList, stream, min, max);
181 List<string> results =
new List<string>();
183 if (!Directory.Exists(saveDir))
185 Directory.CreateDirectory(saveDir);
190 foreach (IFileSerialiser serialiser
in m_serialisers)
192 results.Add(serialiser.WriteToFile(scene, saveDir));
196 TextWriter regionInfoWriter =
new StreamWriter(Path.Combine(saveDir,
"README.TXT"));
197 regionInfoWriter.WriteLine(
"Region Name: " + scene.RegionInfo.RegionName);
198 regionInfoWriter.WriteLine(
"Region ID: " + scene.RegionInfo.RegionID.ToString());
199 regionInfoWriter.WriteLine(
"Backup Time: UTC " + DateTime.UtcNow.ToString());
200 regionInfoWriter.WriteLine(
"Serialise Version: 0.1");
201 regionInfoWriter.Close();
203 TextWriter manifestWriter =
new StreamWriter(Path.Combine(saveDir,
"region.manifest"));
204 foreach (
string line
in results)
206 manifestWriter.WriteLine(line);
208 manifestWriter.Close();
228 private void InterfaceSaveRegion(Object[] args)
230 foreach (
Scene region
in m_regions)
232 if (region.
RegionInfo.RegionName == (
string) args[0])
235 SerialiseRegion(region, Path.Combine(m_savedir, region.
RegionInfo.RegionID.ToString()));
240 private void InterfaceSaveAllRegions(Object[] args)
242 foreach (
Scene region
in m_regions)
245 SerialiseRegion(region, Path.Combine(m_savedir, region.
RegionInfo.RegionID.ToString()));
void RegionLoaded(Scene scene)
This will be called once for every scene loaded. In a shared module this will be multiple times in on...
void SavePrimsToXml2(Scene scene, TextWriter stream, Vector3 min, Vector3 max)
Save prims in the xml2 format, optionally specifying a bounding box for which prims should be saved...
SceneObjectGroup DeserializeGroupFromXml2(string xmlString)
Deserializes a scene object from its xml2 representation. This does not load the object into the scen...
void RemoveRegion(Scene scene)
This is called whenever a Scene is removed. For shared modules, this can happen several times...
A scene object group is conceptually an object in the scene. The object is constituted of SceneObject...
void LoadPrimsFromXml(Scene scene, string fileName, bool newIDS, Vector3 loadOffset)
Load prims from the xml format
string SerializeGroupToXml2(SceneObjectGroup grp, Dictionary< string, object > options)
Serialize an individual scene object into the xml2 format
void SavePrimListToXml2(EntityBase[] entityList, TextWriter stream, Vector3 min, Vector3 max)
Save a set of prims in the xml2 format, optionally specifying a bounding box for which prims should b...
void SaveNamedPrimsToXml2(Scene scene, string primName, string fileName)
void LoadPrimsFromXml2(Scene scene, string fileName)
Load prims from the xml2 format
void Close()
This is the inverse to Initialise. After a Close(), this instance won't be usable anymore...
List< string > SerialiseRegion(Scene scene, string saveDir)
void SavePrimsToXml2(Scene scene, string fileName)
Save prims in the xml2 format
void SavePrimsToXml(Scene scene, string fileName)
Save prims in the xml format
void SavePrimListToXml2(EntityBase[] entityList, string fileName)
Save a set of prims in the xml2 format
void AddRegion(Scene scene)
This is called whenever a Scene is added. For shared modules, this can happen several times...
virtual RegionInfo RegionInfo
void PostInitialise()
This is called exactly once after all the shared region-modules have been instanciated and IRegionMod...
void Initialise(IConfigSource source)
This is called to initialize the region module. For shared modules, this is called exactly once...
void LoadPrimsFromXml2(Scene scene, TextReader reader, bool startScripts)
Load prims from the xml2 format