diff options
author | Oren Hurvitz | 2012-07-24 19:48:08 +0300 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2012-09-14 20:25:03 +0100 |
commit | ce468215d576cc301a261d85bee9baa68a246ce6 (patch) | |
tree | ad2c6d7e3156bf8dab596f2772cc712d4f96c698 /OpenSim/Region/CoreModules/World/Archiver/DearchiveScenesGroup.cs | |
parent | Don't store the unnecessary VERSIONMIN. VERSIONMAX, METHOD or UserID (present... (diff) | |
download | opensim-SC_OLD-ce468215d576cc301a261d85bee9baa68a246ce6.zip opensim-SC_OLD-ce468215d576cc301a261d85bee9baa68a246ce6.tar.gz opensim-SC_OLD-ce468215d576cc301a261d85bee9baa68a246ce6.tar.bz2 opensim-SC_OLD-ce468215d576cc301a261d85bee9baa68a246ce6.tar.xz |
Support multi-region OAR files
Merged ArchiveWriteRequestPreparation.cs and ArchiveWriteRequestExecution.cs. This simplifies the code, and it's faster to write each scene to the archive as it's found rather than all at once at the end.
Diffstat (limited to 'OpenSim/Region/CoreModules/World/Archiver/DearchiveScenesGroup.cs')
-rw-r--r-- | OpenSim/Region/CoreModules/World/Archiver/DearchiveScenesGroup.cs | 232 |
1 files changed, 232 insertions, 0 deletions
diff --git a/OpenSim/Region/CoreModules/World/Archiver/DearchiveScenesGroup.cs b/OpenSim/Region/CoreModules/World/Archiver/DearchiveScenesGroup.cs new file mode 100644 index 0000000..3dcc020 --- /dev/null +++ b/OpenSim/Region/CoreModules/World/Archiver/DearchiveScenesGroup.cs | |||
@@ -0,0 +1,232 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
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 | ||
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 | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Linq; | ||
31 | using System.Text; | ||
32 | using OpenSim.Region.Framework.Scenes; | ||
33 | using OpenMetaverse; | ||
34 | using System.Drawing; | ||
35 | using log4net; | ||
36 | using System.Reflection; | ||
37 | using OpenSim.Framework.Serialization; | ||
38 | |||
39 | namespace OpenSim.Region.CoreModules.World.Archiver | ||
40 | { | ||
41 | /// <summary> | ||
42 | /// The regions included in an OAR file. | ||
43 | /// </summary> | ||
44 | public class DearchiveScenesInfo | ||
45 | { | ||
46 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
47 | |||
48 | /// <summary> | ||
49 | /// One region in the archive. | ||
50 | /// </summary> | ||
51 | public class RegionInfo | ||
52 | { | ||
53 | /// <summary> | ||
54 | /// The subdirectory in which the region is stored. | ||
55 | /// </summary> | ||
56 | public string Directory { get; set; } | ||
57 | |||
58 | /// <summary> | ||
59 | /// The region's coordinates (relative to the South-West corner of the block). | ||
60 | /// </summary> | ||
61 | public Point Location { get; set; } | ||
62 | |||
63 | /// <summary> | ||
64 | /// The UUID of the original scene from which this archived region was saved. | ||
65 | /// </summary> | ||
66 | public string OriginalID { get; set; } | ||
67 | |||
68 | /// <summary> | ||
69 | /// The scene in the current simulator into which this region is loaded. | ||
70 | /// If null then the region doesn't have a corresponding scene, and it won't be loaded. | ||
71 | /// </summary> | ||
72 | public Scene Scene { get; set; } | ||
73 | } | ||
74 | |||
75 | /// <summary> | ||
76 | /// Whether this archive uses the multi-region format. | ||
77 | /// </summary> | ||
78 | public Boolean MultiRegionFormat { get; set; } | ||
79 | |||
80 | /// <summary> | ||
81 | /// Maps (Region directory -> region) | ||
82 | /// </summary> | ||
83 | protected Dictionary<string, RegionInfo> m_directory2region = new Dictionary<string, RegionInfo>(); | ||
84 | |||
85 | /// <summary> | ||
86 | /// Maps (UUID of the scene in the simulator where the region will be loaded -> region) | ||
87 | /// </summary> | ||
88 | protected Dictionary<UUID, RegionInfo> m_newId2region = new Dictionary<UUID, RegionInfo>(); | ||
89 | |||
90 | public int LoadedCreationDateTime { get; set; } | ||
91 | public string DefaultOriginalID { get; set; } | ||
92 | |||
93 | // These variables are used while reading the archive control file | ||
94 | protected int? m_curY = null; | ||
95 | protected int? m_curX = null; | ||
96 | protected RegionInfo m_curRegion; | ||
97 | |||
98 | |||
99 | public DearchiveScenesInfo() | ||
100 | { | ||
101 | MultiRegionFormat = false; | ||
102 | } | ||
103 | |||
104 | |||
105 | // The following methods are used while reading the archive control file | ||
106 | |||
107 | public void StartRow() | ||
108 | { | ||
109 | m_curY = (m_curY == null) ? 0 : m_curY + 1; | ||
110 | m_curX = null; | ||
111 | } | ||
112 | |||
113 | public void StartRegion() | ||
114 | { | ||
115 | m_curX = (m_curX == null) ? 0 : m_curX + 1; | ||
116 | // Note: this doesn't mean we have a real region in this location; this could just be a "hole" | ||
117 | } | ||
118 | |||
119 | public void SetRegionOriginalID(string id) | ||
120 | { | ||
121 | m_curRegion = new RegionInfo(); | ||
122 | m_curRegion.Location = new Point((int)m_curX, (int)m_curY); | ||
123 | m_curRegion.OriginalID = id; | ||
124 | // 'curRegion' will be saved in 'm_directory2region' when SetRegionDir() is called | ||
125 | } | ||
126 | |||
127 | public void SetRegionDirectory(string directory) | ||
128 | { | ||
129 | m_curRegion.Directory = directory; | ||
130 | m_directory2region[directory] = m_curRegion; | ||
131 | } | ||
132 | |||
133 | |||
134 | /// <summary> | ||
135 | /// Sets all the scenes present in the simulator. | ||
136 | /// </summary> | ||
137 | /// <remarks> | ||
138 | /// This method matches regions in the archive to scenes in the simulator according to | ||
139 | /// their relative position. We only load regions if there's an existing Scene in the | ||
140 | /// grid location where the region should be loaded. | ||
141 | /// </remarks> | ||
142 | /// <param name="rootScene">The scene where the Load OAR operation was run</param> | ||
143 | /// <param name="simulatorScenes">All the scenes in the simulator</param> | ||
144 | public void SetSimulatorScenes(Scene rootScene, ArchiveScenesGroup simulatorScenes) | ||
145 | { | ||
146 | foreach (RegionInfo archivedRegion in m_directory2region.Values) | ||
147 | { | ||
148 | Point location = new Point((int)rootScene.RegionInfo.RegionLocX, (int)rootScene.RegionInfo.RegionLocY); | ||
149 | location.Offset(archivedRegion.Location); | ||
150 | |||
151 | Scene scene; | ||
152 | if (simulatorScenes.TryGetScene(location, out scene)) | ||
153 | { | ||
154 | archivedRegion.Scene = scene; | ||
155 | m_newId2region[scene.RegionInfo.RegionID] = archivedRegion; | ||
156 | } | ||
157 | else | ||
158 | { | ||
159 | m_log.WarnFormat("[ARCHIVER]: Not loading archived region {0} because there's no existing region at location {1},{2}", | ||
160 | archivedRegion.Directory, location.X, location.Y); | ||
161 | } | ||
162 | } | ||
163 | } | ||
164 | |||
165 | /// <summary> | ||
166 | /// Returns the archived region according to the path of a file in the archive. | ||
167 | /// Also, converts the full path into a path that is relative to the region's directory. | ||
168 | /// </summary> | ||
169 | /// <param name="fullPath">The path of a file in the archive</param> | ||
170 | /// <param name="scene">The corresponding Scene, or null if none</param> | ||
171 | /// <param name="relativePath">The path relative to the region's directory. (Or the original | ||
172 | /// path, if this file doesn't belong to a region.)</param> | ||
173 | /// <returns>True: use this file; False: skip it</returns> | ||
174 | public bool GetRegionFromPath(string fullPath, out Scene scene, out string relativePath) | ||
175 | { | ||
176 | scene = null; | ||
177 | relativePath = fullPath; | ||
178 | |||
179 | if (!MultiRegionFormat) | ||
180 | { | ||
181 | if (m_newId2region.Count > 0) | ||
182 | scene = m_newId2region.First().Value.Scene; | ||
183 | return true; | ||
184 | } | ||
185 | |||
186 | if (!fullPath.StartsWith(ArchiveConstants.REGIONS_PATH)) | ||
187 | return true; // this file doesn't belong to a region | ||
188 | |||
189 | string[] parts = fullPath.Split(new Char[] { '/' }, 3); | ||
190 | if (parts.Length != 3) | ||
191 | return false; | ||
192 | string regionDirectory = parts[1]; | ||
193 | relativePath = parts[2]; | ||
194 | |||
195 | RegionInfo region; | ||
196 | if (m_directory2region.TryGetValue(regionDirectory, out region)) | ||
197 | { | ||
198 | scene = region.Scene; | ||
199 | return (scene != null); | ||
200 | } | ||
201 | else | ||
202 | { | ||
203 | return false; | ||
204 | } | ||
205 | } | ||
206 | |||
207 | /// <summary> | ||
208 | /// Returns the original UUID of a region (from the simulator where the OAR was saved), | ||
209 | /// given the UUID of the scene it was loaded into in the current simulator. | ||
210 | /// </summary> | ||
211 | /// <param name="newID"></param> | ||
212 | /// <returns></returns> | ||
213 | public string GetOriginalRegionID(UUID newID) | ||
214 | { | ||
215 | RegionInfo region; | ||
216 | if (m_newId2region.TryGetValue(newID, out region)) | ||
217 | return region.OriginalID; | ||
218 | else | ||
219 | return DefaultOriginalID; | ||
220 | } | ||
221 | |||
222 | /// <summary> | ||
223 | /// Returns the scenes that have been (or will be) loaded. | ||
224 | /// </summary> | ||
225 | /// <returns></returns> | ||
226 | public List<UUID> GetLoadedScenes() | ||
227 | { | ||
228 | return m_newId2region.Keys.ToList(); | ||
229 | } | ||
230 | |||
231 | } | ||
232 | } | ||