aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules/ExportSerialiser/SerialiseObjects.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Environment/Modules/ExportSerialiser/SerialiseObjects.cs')
-rw-r--r--OpenSim/Region/Environment/Modules/ExportSerialiser/SerialiseObjects.cs48
1 files changed, 35 insertions, 13 deletions
diff --git a/OpenSim/Region/Environment/Modules/ExportSerialiser/SerialiseObjects.cs b/OpenSim/Region/Environment/Modules/ExportSerialiser/SerialiseObjects.cs
index 7e5cf47..277370d 100644
--- a/OpenSim/Region/Environment/Modules/ExportSerialiser/SerialiseObjects.cs
+++ b/OpenSim/Region/Environment/Modules/ExportSerialiser/SerialiseObjects.cs
@@ -51,6 +51,32 @@ namespace OpenSim.Region.Environment.Modules.ExportSerialiser
51 51
52 public void SaveSerialisedToFile(string fileName, Scene scene) 52 public void SaveSerialisedToFile(string fileName, Scene scene)
53 { 53 {
54 string xmlstream = GetObjectXml(scene);
55
56 MemoryStream stream = ReformatXmlString(xmlstream);
57
58 stream.Seek(0, SeekOrigin.Begin);
59 CreateXmlFile(stream, fileName);
60
61 stream.Seek(0, SeekOrigin.Begin);
62 CreateCompressedXmlFile(stream, fileName);
63 }
64
65 private static MemoryStream ReformatXmlString(string xmlstream)
66 {
67 MemoryStream stream = new MemoryStream();
68 XmlTextWriter formatter = new XmlTextWriter(stream, Encoding.UTF8);
69 XmlDocument doc = new XmlDocument();
70
71 doc.LoadXml(xmlstream);
72 formatter.Formatting = Formatting.Indented;
73 doc.WriteContentTo(formatter);
74 formatter.Flush();
75 return stream;
76 }
77
78 private static string GetObjectXml(Scene scene)
79 {
54 string xmlstream = "<scene>"; 80 string xmlstream = "<scene>";
55 81
56 List<EntityBase> EntityList = scene.GetEntities(); 82 List<EntityBase> EntityList = scene.GetEntities();
@@ -69,29 +95,25 @@ namespace OpenSim.Region.Environment.Modules.ExportSerialiser
69 xmlstream += xml; 95 xmlstream += xml;
70 96
71 xmlstream += "</scene>"; 97 xmlstream += "</scene>";
98 return xmlstream;
99 }
72 100
73 MemoryStream stream = new MemoryStream(); 101 private static void CreateXmlFile(MemoryStream xmlStream, string fileName)
74 XmlTextWriter formatter = new XmlTextWriter(stream, Encoding.UTF8); 102 {
75 XmlDocument doc = new XmlDocument();
76
77 doc.LoadXml(xmlstream);
78 formatter.Formatting = Formatting.Indented;
79 doc.WriteContentTo(formatter);
80 formatter.Flush();
81
82 stream.Seek(0, SeekOrigin.Begin);
83
84 FileStream objectsFile = new FileStream(fileName, FileMode.Create); 103 FileStream objectsFile = new FileStream(fileName, FileMode.Create);
85 104
86 stream.WriteTo(objectsFile); 105 xmlStream.WriteTo(objectsFile);
87 objectsFile.Flush(); 106 objectsFile.Flush();
88 objectsFile.Close(); 107 objectsFile.Close();
108 }
89 109
110 private static void CreateCompressedXmlFile(MemoryStream xmlStream, string fileName)
111 {
90 #region GZip Compressed Version 112 #region GZip Compressed Version
91 FileStream objectsFileCompressed = new FileStream(fileName + ".gzs", FileMode.Create); 113 FileStream objectsFileCompressed = new FileStream(fileName + ".gzs", FileMode.Create);
92 MemoryStream gzipMSStream = new MemoryStream(); 114 MemoryStream gzipMSStream = new MemoryStream();
93 GZipStream gzipStream = new GZipStream(gzipMSStream, CompressionMode.Compress); 115 GZipStream gzipStream = new GZipStream(gzipMSStream, CompressionMode.Compress);
94 stream.WriteTo(gzipStream); 116 xmlStream.WriteTo(gzipStream);
95 gzipMSStream.WriteTo(objectsFileCompressed); 117 gzipMSStream.WriteTo(objectsFileCompressed);
96 objectsFileCompressed.Flush(); 118 objectsFileCompressed.Flush();
97 objectsFileCompressed.Close(); 119 objectsFileCompressed.Close();