diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/Environment/Modules/World/Serialiser/SerialiseObjects.cs | 248 |
1 files changed, 124 insertions, 124 deletions
diff --git a/OpenSim/Region/Environment/Modules/World/Serialiser/SerialiseObjects.cs b/OpenSim/Region/Environment/Modules/World/Serialiser/SerialiseObjects.cs index ef90fd4..40e1771 100644 --- a/OpenSim/Region/Environment/Modules/World/Serialiser/SerialiseObjects.cs +++ b/OpenSim/Region/Environment/Modules/World/Serialiser/SerialiseObjects.cs | |||
@@ -1,125 +1,125 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) Contributors, http://opensimulator.org/ | 2 | * Copyright (c) Contributors, http://opensimulator.org/ |
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | 3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. |
4 | * | 4 | * |
5 | * Redistribution and use in source and binary forms, with or without | 5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions are met: | 6 | * modification, are permitted provided that the following conditions are met: |
7 | * * Redistributions of source code must retain the above copyright | 7 | * * Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. | 8 | * notice, this list of conditions and the following disclaimer. |
9 | * * Redistributions in binary form must reproduce the above copyright | 9 | * * Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the | 10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. | 11 | * documentation and/or other materials provided with the distribution. |
12 | * * Neither the name of the OpenSim Project nor the | 12 | * * Neither the name of the OpenSim Project nor the |
13 | * names of its contributors may be used to endorse or promote products | 13 | * names of its contributors may be used to endorse or promote products |
14 | * derived from this software without specific prior written permission. | 14 | * derived from this software without specific prior written permission. |
15 | * | 15 | * |
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | 16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY |
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | 19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY |
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System.Collections.Generic; | 28 | using System.Collections.Generic; |
29 | using System.IO; | 29 | using System.IO; |
30 | using System.IO.Compression; | 30 | using System.IO.Compression; |
31 | using System.Text; | 31 | using System.Text; |
32 | using System.Xml; | 32 | using System.Xml; |
33 | using OpenSim.Region.Environment.Scenes; | 33 | using OpenSim.Region.Environment.Scenes; |
34 | 34 | ||
35 | namespace OpenSim.Region.Environment.Modules.ExportSerialiser | 35 | namespace OpenSim.Region.Environment.Modules.ExportSerialiser |
36 | { | 36 | { |
37 | internal class SerialiseObjects : IFileSerialiser | 37 | internal class SerialiseObjects : IFileSerialiser |
38 | { | 38 | { |
39 | #region IFileSerialiser Members | 39 | #region IFileSerialiser Members |
40 | 40 | ||
41 | public string WriteToFile(Scene scene, string dir) | 41 | public string WriteToFile(Scene scene, string dir) |
42 | { | 42 | { |
43 | string targetFileName = dir + "objects.xml"; | 43 | string targetFileName = dir + "objects.xml"; |
44 | 44 | ||
45 | SaveSerialisedToFile(targetFileName, scene); | 45 | SaveSerialisedToFile(targetFileName, scene); |
46 | 46 | ||
47 | return "objects.xml"; | 47 | return "objects.xml"; |
48 | } | 48 | } |
49 | 49 | ||
50 | #endregion | 50 | #endregion |
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); | 54 | string xmlstream = GetObjectXml(scene); |
55 | 55 | ||
56 | MemoryStream stream = ReformatXmlString(xmlstream); | 56 | MemoryStream stream = ReformatXmlString(xmlstream); |
57 | 57 | ||
58 | stream.Seek(0, SeekOrigin.Begin); | 58 | stream.Seek(0, SeekOrigin.Begin); |
59 | CreateXmlFile(stream, fileName); | 59 | CreateXmlFile(stream, fileName); |
60 | 60 | ||
61 | stream.Seek(0, SeekOrigin.Begin); | 61 | stream.Seek(0, SeekOrigin.Begin); |
62 | CreateCompressedXmlFile(stream, fileName); | 62 | CreateCompressedXmlFile(stream, fileName); |
63 | } | 63 | } |
64 | 64 | ||
65 | private static MemoryStream ReformatXmlString(string xmlstream) | 65 | private static MemoryStream ReformatXmlString(string xmlstream) |
66 | { | 66 | { |
67 | MemoryStream stream = new MemoryStream(); | 67 | MemoryStream stream = new MemoryStream(); |
68 | XmlTextWriter formatter = new XmlTextWriter(stream, Encoding.UTF8); | 68 | XmlTextWriter formatter = new XmlTextWriter(stream, Encoding.UTF8); |
69 | XmlDocument doc = new XmlDocument(); | 69 | XmlDocument doc = new XmlDocument(); |
70 | 70 | ||
71 | doc.LoadXml(xmlstream); | 71 | doc.LoadXml(xmlstream); |
72 | formatter.Formatting = Formatting.Indented; | 72 | formatter.Formatting = Formatting.Indented; |
73 | doc.WriteContentTo(formatter); | 73 | doc.WriteContentTo(formatter); |
74 | formatter.Flush(); | 74 | formatter.Flush(); |
75 | return stream; | 75 | return stream; |
76 | } | 76 | } |
77 | 77 | ||
78 | private static string GetObjectXml(Scene scene) | 78 | private static string GetObjectXml(Scene scene) |
79 | { | 79 | { |
80 | string xmlstream = "<scene>"; | 80 | string xmlstream = "<scene>"; |
81 | 81 | ||
82 | List<EntityBase> EntityList = scene.GetEntities(); | 82 | List<EntityBase> EntityList = scene.GetEntities(); |
83 | List<string> EntityXml = new List<string>(); | 83 | List<string> EntityXml = new List<string>(); |
84 | 84 | ||
85 | foreach (EntityBase ent in EntityList) | 85 | foreach (EntityBase ent in EntityList) |
86 | { | 86 | { |
87 | if (ent is SceneObjectGroup) | 87 | if (ent is SceneObjectGroup) |
88 | { | 88 | { |
89 | EntityXml.Add(((SceneObjectGroup) ent).ToXmlString2()); | 89 | EntityXml.Add(((SceneObjectGroup) ent).ToXmlString2()); |
90 | } | 90 | } |
91 | } | 91 | } |
92 | EntityXml.Sort(); | 92 | EntityXml.Sort(); |
93 | 93 | ||
94 | foreach (string xml in EntityXml) | 94 | foreach (string xml in EntityXml) |
95 | xmlstream += xml; | 95 | xmlstream += xml; |
96 | 96 | ||
97 | xmlstream += "</scene>"; | 97 | xmlstream += "</scene>"; |
98 | return xmlstream; | 98 | return xmlstream; |
99 | } | 99 | } |
100 | 100 | ||
101 | private static void CreateXmlFile(MemoryStream xmlStream, string fileName) | 101 | private static void CreateXmlFile(MemoryStream xmlStream, string fileName) |
102 | { | 102 | { |
103 | FileStream objectsFile = new FileStream(fileName, FileMode.Create); | 103 | FileStream objectsFile = new FileStream(fileName, FileMode.Create); |
104 | 104 | ||
105 | xmlStream.WriteTo(objectsFile); | 105 | xmlStream.WriteTo(objectsFile); |
106 | objectsFile.Flush(); | 106 | objectsFile.Flush(); |
107 | objectsFile.Close(); | 107 | objectsFile.Close(); |
108 | } | 108 | } |
109 | 109 | ||
110 | private static void CreateCompressedXmlFile(MemoryStream xmlStream, string fileName) | 110 | private static void CreateCompressedXmlFile(MemoryStream xmlStream, string fileName) |
111 | { | 111 | { |
112 | #region GZip Compressed Version | 112 | #region GZip Compressed Version |
113 | 113 | ||
114 | FileStream objectsFileCompressed = new FileStream(fileName + ".gzs", FileMode.Create); | 114 | FileStream objectsFileCompressed = new FileStream(fileName + ".gzs", FileMode.Create); |
115 | MemoryStream gzipMSStream = new MemoryStream(); | 115 | MemoryStream gzipMSStream = new MemoryStream(); |
116 | GZipStream gzipStream = new GZipStream(gzipMSStream, CompressionMode.Compress); | 116 | GZipStream gzipStream = new GZipStream(gzipMSStream, CompressionMode.Compress); |
117 | xmlStream.WriteTo(gzipStream); | 117 | xmlStream.WriteTo(gzipStream); |
118 | gzipMSStream.WriteTo(objectsFileCompressed); | 118 | gzipMSStream.WriteTo(objectsFileCompressed); |
119 | objectsFileCompressed.Flush(); | 119 | objectsFileCompressed.Flush(); |
120 | objectsFileCompressed.Close(); | 120 | objectsFileCompressed.Close(); |
121 | 121 | ||
122 | #endregion | 122 | #endregion |
123 | } | 123 | } |
124 | } | 124 | } |
125 | } \ No newline at end of file | 125 | } \ No newline at end of file |