OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
DearchiveScenesGroup.cs
Go to the documentation of this file.
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 {
44  public class DearchiveScenesInfo
45  {
46  private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
47 
51  public class RegionInfo
52  {
56  public string Directory { get; set; }
57 
61  public Point Location { get; set; }
62 
66  public string OriginalID { get; set; }
67 
72  public Scene Scene { get; set; }
73 
77  public Vector3 RegionSize { get; set; }
78 
79  public RegionInfo()
80  {
81  RegionSize = new Vector3(256f,256f,float.MaxValue);
82  }
83  }
84 
88  public Boolean MultiRegionFormat { get; set; }
89 
93  protected Dictionary<string, RegionInfo> m_directory2region = new Dictionary<string, RegionInfo>();
94 
98  protected Dictionary<UUID, RegionInfo> m_newId2region = new Dictionary<UUID, RegionInfo>();
99 
100  public int LoadedCreationDateTime { get; set; }
101  public string DefaultOriginalID { get; set; }
102 
103  // These variables are used while reading the archive control file
104  protected int? m_curY = null;
105  protected int? m_curX = null;
107 
108 
110  {
111  MultiRegionFormat = false;
112  }
113 
114 
115  // The following methods are used while reading the archive control file
116 
117  public void StartRow()
118  {
119  m_curY = (m_curY == null) ? 0 : m_curY + 1;
120  m_curX = null;
121  }
122 
123  public void StartRegion()
124  {
125  m_curX = (m_curX == null) ? 0 : m_curX + 1;
126  // Note: this doesn't mean we have a real region in this location; this could just be a "hole"
127  }
128 
129  public void SetRegionOriginalID(string id)
130  {
131  m_curRegion = new RegionInfo();
132  int x = (int)((m_curX == null) ? 0 : m_curX);
133  int y = (int)((m_curY == null) ? 0 : m_curY);
134 
135  m_curRegion.Location = new Point(x, y);
136  m_curRegion.OriginalID = id;
137  // 'curRegion' will be saved in 'm_directory2region' when SetRegionDir() is called
138  }
139 
140  public void SetRegionDirectory(string directory)
141  {
142  if(m_curRegion != null)
143  {
144  m_curRegion.Directory = directory;
145  m_directory2region[directory] = m_curRegion;
146  }
147  }
148 
149  public void SetRegionSize(Vector3 size)
150  {
151  if(m_curRegion != null)
152  m_curRegion.RegionSize = size;
153  }
154 
165  public void SetSimulatorScenes(Scene rootScene, ArchiveScenesGroup simulatorScenes)
166  {
167  foreach (RegionInfo archivedRegion in m_directory2region.Values)
168  {
169  Point location = new Point((int)rootScene.RegionInfo.RegionLocX,
170  (int)rootScene.RegionInfo.RegionLocY);
171 
172  location.Offset(archivedRegion.Location);
173 
174  Scene scene;
175  if (simulatorScenes.TryGetScene(location, out scene))
176  {
177  archivedRegion.Scene = scene;
178  m_newId2region[scene.RegionInfo.RegionID] = archivedRegion;
179  }
180  else
181  {
182  m_log.WarnFormat("[ARCHIVER]: Not loading archived region {0} because there's no existing region at location {1},{2}",
183  archivedRegion.Directory, location.X, location.Y);
184  }
185  }
186  }
187 
197  public bool GetRegionFromPath(string fullPath, out Scene scene, out string relativePath)
198  {
199  scene = null;
200  relativePath = fullPath;
201 
202  if (!MultiRegionFormat)
203  {
204  if (m_newId2region.Count > 0)
205  scene = m_newId2region.First().Value.Scene;
206  return true;
207  }
208 
209  if (!fullPath.StartsWith(ArchiveConstants.REGIONS_PATH))
210  return true; // this file doesn't belong to a region
211 
212  string[] parts = fullPath.Split(new Char[] { '/' }, 3);
213  if (parts.Length != 3)
214  return false;
215  string regionDirectory = parts[1];
216  relativePath = parts[2];
217 
218  RegionInfo region;
219  if (m_directory2region.TryGetValue(regionDirectory, out region))
220  {
221  scene = region.Scene;
222  return (scene != null);
223  }
224  else
225  {
226  return false;
227  }
228  }
229 
236  public string GetOriginalRegionID(UUID newID)
237  {
238  RegionInfo region;
239  if (m_newId2region.TryGetValue(newID, out region))
240  return region.OriginalID;
241  else
242  return DefaultOriginalID;
243  }
244 
249  public List<UUID> GetLoadedScenes()
250  {
251  return m_newId2region.Keys.ToList();
252  }
253 
254  public int GetScenesCount()
255  {
256  return m_directory2region.Count;
257  }
258  }
259 }
List< UUID > GetLoadedScenes()
Returns the scenes that have been (or will be) loaded.
bool GetRegionFromPath(string fullPath, out Scene scene, out string relativePath)
Returns the archived region according to the path of a file in the archive. Also, converts the full p...
A group of regions arranged in a rectangle, possibly with holes.
Constants for the archiving module
OpenSim.Framework.RegionInfo RegionInfo
string GetOriginalRegionID(UUID newID)
Returns the original UUID of a region (from the simulator where the OAR was saved), given the UUID of the scene it was loaded into in the current simulator.
void SetSimulatorScenes(Scene rootScene, ArchiveScenesGroup simulatorScenes)
Sets all the scenes present in the simulator.
string OriginalID
The UUID of the original scene from which this archived region was saved.