ArchiveReadRequest.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  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. using System;
  28. using System.Collections.Generic;
  29. using System.IO;
  30. using System.IO.Compression;
  31. using System.Net;
  32. using System.Reflection;
  33. using System.Text;
  34. using System.Xml;
  35. using log4net;
  36. using OpenMetaverse;
  37. using OpenSim.Framework;
  38. using OpenSim.Framework.Serialization;
  39. using OpenSim.Framework.Serialization.External;
  40. using OpenSim.Region.CoreModules.World.Terrain;
  41. using OpenSim.Region.Framework.Interfaces;
  42. using OpenSim.Region.Framework.Scenes;
  43. using OpenSim.Services.Interfaces;
  44. namespace OpenSim.Region.CoreModules.World.Archiver
  45. {
  46. /// <summary>
  47. /// Handles an individual archive read request
  48. /// </summary>
  49. public class ArchiveReadRequest
  50. {
  51. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  52. /// <summary>
  53. /// The maximum major version of OAR that we can read. Minor versions shouldn't need a max number since version
  54. /// bumps here should be compatible.
  55. /// </summary>
  56. public static int MAX_MAJOR_VERSION = 1;
  57. /// <summary>
  58. /// Has the control file been loaded for this archive?
  59. /// </summary>
  60. public bool ControlFileLoaded { get; private set; }
  61. protected Scene m_scene;
  62. protected Stream m_loadStream;
  63. protected Guid m_requestId;
  64. protected string m_errorMessage;
  65. /// <value>
  66. /// Should the archive being loaded be merged with what is already on the region?
  67. /// </value>
  68. protected bool m_merge;
  69. /// <value>
  70. /// Should we ignore any assets when reloading the archive?
  71. /// </value>
  72. protected bool m_skipAssets;
  73. /// <summary>
  74. /// Used to cache lookups for valid uuids.
  75. /// </summary>
  76. private IDictionary<UUID, bool> m_validUserUuids = new Dictionary<UUID, bool>();
  77. private IUserManagement m_UserMan;
  78. private IUserManagement UserManager
  79. {
  80. get
  81. {
  82. if (m_UserMan == null)
  83. {
  84. m_UserMan = m_scene.RequestModuleInterface<IUserManagement>();
  85. }
  86. return m_UserMan;
  87. }
  88. }
  89. public ArchiveReadRequest(Scene scene, string loadPath, bool merge, bool skipAssets, Guid requestId)
  90. {
  91. m_scene = scene;
  92. try
  93. {
  94. m_loadStream = new GZipStream(ArchiveHelpers.GetStream(loadPath), CompressionMode.Decompress);
  95. }
  96. catch (EntryPointNotFoundException e)
  97. {
  98. m_log.ErrorFormat(
  99. "[ARCHIVER]: Mismatch between Mono and zlib1g library version when trying to create compression stream."
  100. + "If you've manually installed Mono, have you appropriately updated zlib1g as well?");
  101. m_log.Error(e);
  102. }
  103. m_errorMessage = String.Empty;
  104. m_merge = merge;
  105. m_skipAssets = skipAssets;
  106. m_requestId = requestId;
  107. }
  108. public ArchiveReadRequest(Scene scene, Stream loadStream, bool merge, bool skipAssets, Guid requestId)
  109. {
  110. m_scene = scene;
  111. m_loadStream = loadStream;
  112. m_merge = merge;
  113. m_skipAssets = skipAssets;
  114. m_requestId = requestId;
  115. }
  116. /// <summary>
  117. /// Dearchive the region embodied in this request.
  118. /// </summary>
  119. public void DearchiveRegion()
  120. {
  121. // The same code can handle dearchiving 0.1 and 0.2 OpenSim Archive versions
  122. DearchiveRegion0DotStar();
  123. }
  124. private void DearchiveRegion0DotStar()
  125. {
  126. int successfulAssetRestores = 0;
  127. int failedAssetRestores = 0;
  128. List<string> serialisedSceneObjects = new List<string>();
  129. List<string> serialisedParcels = new List<string>();
  130. string filePath = "NONE";
  131. TarArchiveReader archive = new TarArchiveReader(m_loadStream);
  132. byte[] data;
  133. TarArchiveReader.TarEntryType entryType;
  134. try
  135. {
  136. while ((data = archive.ReadEntry(out filePath, out entryType)) != null)
  137. {
  138. //m_log.DebugFormat(
  139. // "[ARCHIVER]: Successfully read {0} ({1} bytes)", filePath, data.Length);
  140. if (TarArchiveReader.TarEntryType.TYPE_DIRECTORY == entryType)
  141. continue;
  142. if (filePath.StartsWith(ArchiveConstants.OBJECTS_PATH))
  143. {
  144. serialisedSceneObjects.Add(Encoding.UTF8.GetString(data));
  145. }
  146. else if (filePath.StartsWith(ArchiveConstants.ASSETS_PATH) && !m_skipAssets)
  147. {
  148. if (LoadAsset(filePath, data))
  149. successfulAssetRestores++;
  150. else
  151. failedAssetRestores++;
  152. if ((successfulAssetRestores + failedAssetRestores) % 250 == 0)
  153. m_log.Debug("[ARCHIVER]: Loaded " + successfulAssetRestores + " assets and failed to load " + failedAssetRestores + " assets...");
  154. }
  155. else if (!m_merge && filePath.StartsWith(ArchiveConstants.TERRAINS_PATH))
  156. {
  157. LoadTerrain(filePath, data);
  158. }
  159. else if (!m_merge && filePath.StartsWith(ArchiveConstants.SETTINGS_PATH))
  160. {
  161. LoadRegionSettings(filePath, data);
  162. }
  163. else if (!m_merge && filePath.StartsWith(ArchiveConstants.LANDDATA_PATH))
  164. {
  165. serialisedParcels.Add(Encoding.UTF8.GetString(data));
  166. }
  167. else if (filePath == ArchiveConstants.CONTROL_FILE_PATH)
  168. {
  169. LoadControlFile(filePath, data);
  170. }
  171. }
  172. //m_log.Debug("[ARCHIVER]: Reached end of archive");
  173. }
  174. catch (Exception e)
  175. {
  176. m_log.ErrorFormat(
  177. "[ARCHIVER]: Aborting load with error in archive file {0}. {1}", filePath, e);
  178. m_errorMessage += e.ToString();
  179. m_scene.EventManager.TriggerOarFileLoaded(m_requestId, m_errorMessage);
  180. return;
  181. }
  182. finally
  183. {
  184. archive.Close();
  185. }
  186. if (!m_skipAssets)
  187. {
  188. m_log.InfoFormat("[ARCHIVER]: Restored {0} assets", successfulAssetRestores);
  189. if (failedAssetRestores > 0)
  190. {
  191. m_log.ErrorFormat("[ARCHIVER]: Failed to load {0} assets", failedAssetRestores);
  192. m_errorMessage += String.Format("Failed to load {0} assets", failedAssetRestores);
  193. }
  194. }
  195. if (!m_merge)
  196. {
  197. m_log.Info("[ARCHIVER]: Clearing all existing scene objects");
  198. m_scene.DeleteAllSceneObjects();
  199. }
  200. LoadParcels(serialisedParcels);
  201. LoadObjects(serialisedSceneObjects);
  202. m_log.InfoFormat("[ARCHIVER]: Successfully loaded archive");
  203. m_scene.EventManager.TriggerOarFileLoaded(m_requestId, m_errorMessage);
  204. }
  205. /// <summary>
  206. /// Load serialized scene objects.
  207. /// </summary>
  208. /// <param name="serialisedSceneObjects"></param>
  209. protected void LoadObjects(List<string> serialisedSceneObjects)
  210. {
  211. // Reload serialized prims
  212. m_log.InfoFormat("[ARCHIVER]: Loading {0} scene objects. Please wait.", serialisedSceneObjects.Count);
  213. IRegionSerialiserModule serialiser = m_scene.RequestModuleInterface<IRegionSerialiserModule>();
  214. int sceneObjectsLoadedCount = 0;
  215. foreach (string serialisedSceneObject in serialisedSceneObjects)
  216. {
  217. /*
  218. m_log.DebugFormat("[ARCHIVER]: Loading xml with raw size {0}", serialisedSceneObject.Length);
  219. // Really large xml files (multi megabyte) appear to cause
  220. // memory problems
  221. // when loading the xml. But don't enable this check yet
  222. if (serialisedSceneObject.Length > 5000000)
  223. {
  224. m_log.Error("[ARCHIVER]: Ignoring xml since size > 5000000);");
  225. continue;
  226. }
  227. */
  228. SceneObjectGroup sceneObject = serialiser.DeserializeGroupFromXml2(serialisedSceneObject);
  229. // For now, give all incoming scene objects new uuids. This will allow scenes to be cloned
  230. // on the same region server and multiple examples a single object archive to be imported
  231. // to the same scene (when this is possible).
  232. sceneObject.ResetIDs();
  233. // Try to retain the original creator/owner/lastowner if their uuid is present on this grid
  234. // or creator data is present. Otherwise, use the estate owner instead.
  235. foreach (SceneObjectPart part in sceneObject.Parts)
  236. {
  237. if (part.CreatorData == null || part.CreatorData == string.Empty)
  238. {
  239. if (!ResolveUserUuid(part.CreatorID))
  240. part.CreatorID = m_scene.RegionInfo.EstateSettings.EstateOwner;
  241. }
  242. if (UserManager != null)
  243. UserManager.AddUser(part.CreatorID, part.CreatorData);
  244. if (!ResolveUserUuid(part.OwnerID))
  245. part.OwnerID = m_scene.RegionInfo.EstateSettings.EstateOwner;
  246. if (!ResolveUserUuid(part.LastOwnerID))
  247. part.LastOwnerID = m_scene.RegionInfo.EstateSettings.EstateOwner;
  248. // And zap any troublesome sit target information
  249. // part.SitTargetOrientation = new Quaternion(0, 0, 0, 1);
  250. // part.SitTargetPosition = new Vector3(0, 0, 0);
  251. // Fix ownership/creator of inventory items
  252. // Not doing so results in inventory items
  253. // being no copy/no mod for everyone
  254. lock (part.TaskInventory)
  255. {
  256. TaskInventoryDictionary inv = part.TaskInventory;
  257. foreach (KeyValuePair<UUID, TaskInventoryItem> kvp in inv)
  258. {
  259. if (!ResolveUserUuid(kvp.Value.OwnerID))
  260. {
  261. kvp.Value.OwnerID = m_scene.RegionInfo.EstateSettings.EstateOwner;
  262. }
  263. if (kvp.Value.CreatorData == null || kvp.Value.CreatorData == string.Empty)
  264. {
  265. if (!ResolveUserUuid(kvp.Value.CreatorID))
  266. kvp.Value.CreatorID = m_scene.RegionInfo.EstateSettings.EstateOwner;
  267. }
  268. if (UserManager != null)
  269. UserManager.AddUser(kvp.Value.CreatorID, kvp.Value.CreatorData);
  270. }
  271. }
  272. }
  273. if (m_scene.AddRestoredSceneObject(sceneObject, true, false))
  274. {
  275. sceneObjectsLoadedCount++;
  276. sceneObject.CreateScriptInstances(0, false, m_scene.DefaultScriptEngine, 0);
  277. sceneObject.ResumeScripts();
  278. }
  279. }
  280. m_log.InfoFormat("[ARCHIVER]: Restored {0} scene objects to the scene", sceneObjectsLoadedCount);
  281. int ignoredObjects = serialisedSceneObjects.Count - sceneObjectsLoadedCount;
  282. if (ignoredObjects > 0)
  283. m_log.WarnFormat("[ARCHIVER]: Ignored {0} scene objects that already existed in the scene", ignoredObjects);
  284. }
  285. /// <summary>
  286. /// Load serialized parcels.
  287. /// </summary>
  288. /// <param name="serialisedParcels"></param>
  289. protected void LoadParcels(List<string> serialisedParcels)
  290. {
  291. // Reload serialized parcels
  292. m_log.InfoFormat("[ARCHIVER]: Loading {0} parcels. Please wait.", serialisedParcels.Count);
  293. List<LandData> landData = new List<LandData>();
  294. foreach (string serialisedParcel in serialisedParcels)
  295. {
  296. LandData parcel = LandDataSerializer.Deserialize(serialisedParcel);
  297. if (!ResolveUserUuid(parcel.OwnerID))
  298. parcel.OwnerID = m_scene.RegionInfo.EstateSettings.EstateOwner;
  299. // m_log.DebugFormat(
  300. // "[ARCHIVER]: Adding parcel {0}, local id {1}, area {2}",
  301. // parcel.Name, parcel.LocalID, parcel.Area);
  302. landData.Add(parcel);
  303. }
  304. if (!m_merge)
  305. {
  306. bool setupDefaultParcel = (landData.Count == 0);
  307. m_scene.LandChannel.Clear(setupDefaultParcel);
  308. }
  309. m_scene.EventManager.TriggerIncomingLandDataFromStorage(landData);
  310. m_log.InfoFormat("[ARCHIVER]: Restored {0} parcels.", landData.Count);
  311. }
  312. /// <summary>
  313. /// Look up the given user id to check whether it's one that is valid for this grid.
  314. /// </summary>
  315. /// <param name="uuid"></param>
  316. /// <returns></returns>
  317. private bool ResolveUserUuid(UUID uuid)
  318. {
  319. if (!m_validUserUuids.ContainsKey(uuid))
  320. {
  321. UserAccount account = m_scene.UserAccountService.GetUserAccount(m_scene.RegionInfo.ScopeID, uuid);
  322. if (account != null)
  323. m_validUserUuids.Add(uuid, true);
  324. else
  325. m_validUserUuids.Add(uuid, false);
  326. }
  327. if (m_validUserUuids[uuid])
  328. return true;
  329. else
  330. return false;
  331. }
  332. /// <summary>
  333. /// Load an asset
  334. /// </summary>
  335. /// <param name="assetFilename"></param>
  336. /// <param name="data"></param>
  337. /// <returns>true if asset was successfully loaded, false otherwise</returns>
  338. private bool LoadAsset(string assetPath, byte[] data)
  339. {
  340. // Right now we're nastily obtaining the UUID from the filename
  341. string filename = assetPath.Remove(0, ArchiveConstants.ASSETS_PATH.Length);
  342. int i = filename.LastIndexOf(ArchiveConstants.ASSET_EXTENSION_SEPARATOR);
  343. if (i == -1)
  344. {
  345. m_log.ErrorFormat(
  346. "[ARCHIVER]: Could not find extension information in asset path {0} since it's missing the separator {1}. Skipping",
  347. assetPath, ArchiveConstants.ASSET_EXTENSION_SEPARATOR);
  348. return false;
  349. }
  350. string extension = filename.Substring(i);
  351. string uuid = filename.Remove(filename.Length - extension.Length);
  352. if (ArchiveConstants.EXTENSION_TO_ASSET_TYPE.ContainsKey(extension))
  353. {
  354. sbyte assetType = ArchiveConstants.EXTENSION_TO_ASSET_TYPE[extension];
  355. if (assetType == (sbyte)AssetType.Unknown)
  356. m_log.WarnFormat("[ARCHIVER]: Importing {0} byte asset {1} with unknown type", data.Length, uuid);
  357. //m_log.DebugFormat("[ARCHIVER]: Importing asset {0}, type {1}", uuid, assetType);
  358. AssetBase asset = new AssetBase(new UUID(uuid), String.Empty, assetType, UUID.Zero.ToString());
  359. asset.Data = data;
  360. // We're relying on the asset service to do the sensible thing and not store the asset if it already
  361. // exists.
  362. m_scene.AssetService.Store(asset);
  363. /**
  364. * Create layers on decode for image assets. This is likely to significantly increase the time to load archives so
  365. * it might be best done when dearchive takes place on a separate thread
  366. if (asset.Type=AssetType.Texture)
  367. {
  368. IJ2KDecoder cacheLayerDecode = scene.RequestModuleInterface<IJ2KDecoder>();
  369. if (cacheLayerDecode != null)
  370. cacheLayerDecode.syncdecode(asset.FullID, asset.Data);
  371. }
  372. */
  373. return true;
  374. }
  375. else
  376. {
  377. m_log.ErrorFormat(
  378. "[ARCHIVER]: Tried to dearchive data with path {0} with an unknown type extension {1}",
  379. assetPath, extension);
  380. return false;
  381. }
  382. }
  383. /// <summary>
  384. /// Load region settings data
  385. /// </summary>
  386. /// <param name="settingsPath"></param>
  387. /// <param name="data"></param>
  388. /// <returns>
  389. /// true if settings were loaded successfully, false otherwise
  390. /// </returns>
  391. private bool LoadRegionSettings(string settingsPath, byte[] data)
  392. {
  393. RegionSettings loadedRegionSettings;
  394. try
  395. {
  396. loadedRegionSettings = RegionSettingsSerializer.Deserialize(data);
  397. }
  398. catch (Exception e)
  399. {
  400. m_log.ErrorFormat(
  401. "[ARCHIVER]: Could not parse region settings file {0}. Ignoring. Exception was {1}",
  402. settingsPath, e);
  403. return false;
  404. }
  405. RegionSettings currentRegionSettings = m_scene.RegionInfo.RegionSettings;
  406. currentRegionSettings.AgentLimit = loadedRegionSettings.AgentLimit;
  407. currentRegionSettings.AllowDamage = loadedRegionSettings.AllowDamage;
  408. currentRegionSettings.AllowLandJoinDivide = loadedRegionSettings.AllowLandJoinDivide;
  409. currentRegionSettings.AllowLandResell = loadedRegionSettings.AllowLandResell;
  410. currentRegionSettings.BlockFly = loadedRegionSettings.BlockFly;
  411. currentRegionSettings.BlockShowInSearch = loadedRegionSettings.BlockShowInSearch;
  412. currentRegionSettings.BlockTerraform = loadedRegionSettings.BlockTerraform;
  413. currentRegionSettings.DisableCollisions = loadedRegionSettings.DisableCollisions;
  414. currentRegionSettings.DisablePhysics = loadedRegionSettings.DisablePhysics;
  415. currentRegionSettings.DisableScripts = loadedRegionSettings.DisableScripts;
  416. currentRegionSettings.Elevation1NE = loadedRegionSettings.Elevation1NE;
  417. currentRegionSettings.Elevation1NW = loadedRegionSettings.Elevation1NW;
  418. currentRegionSettings.Elevation1SE = loadedRegionSettings.Elevation1SE;
  419. currentRegionSettings.Elevation1SW = loadedRegionSettings.Elevation1SW;
  420. currentRegionSettings.Elevation2NE = loadedRegionSettings.Elevation2NE;
  421. currentRegionSettings.Elevation2NW = loadedRegionSettings.Elevation2NW;
  422. currentRegionSettings.Elevation2SE = loadedRegionSettings.Elevation2SE;
  423. currentRegionSettings.Elevation2SW = loadedRegionSettings.Elevation2SW;
  424. currentRegionSettings.FixedSun = loadedRegionSettings.FixedSun;
  425. currentRegionSettings.SunPosition = loadedRegionSettings.SunPosition;
  426. currentRegionSettings.ObjectBonus = loadedRegionSettings.ObjectBonus;
  427. currentRegionSettings.RestrictPushing = loadedRegionSettings.RestrictPushing;
  428. currentRegionSettings.TerrainLowerLimit = loadedRegionSettings.TerrainLowerLimit;
  429. currentRegionSettings.TerrainRaiseLimit = loadedRegionSettings.TerrainRaiseLimit;
  430. currentRegionSettings.TerrainTexture1 = loadedRegionSettings.TerrainTexture1;
  431. currentRegionSettings.TerrainTexture2 = loadedRegionSettings.TerrainTexture2;
  432. currentRegionSettings.TerrainTexture3 = loadedRegionSettings.TerrainTexture3;
  433. currentRegionSettings.TerrainTexture4 = loadedRegionSettings.TerrainTexture4;
  434. currentRegionSettings.UseEstateSun = loadedRegionSettings.UseEstateSun;
  435. currentRegionSettings.WaterHeight = loadedRegionSettings.WaterHeight;
  436. currentRegionSettings.Save();
  437. m_scene.TriggerEstateSunUpdate();
  438. IEstateModule estateModule = m_scene.RequestModuleInterface<IEstateModule>();
  439. if (estateModule != null)
  440. estateModule.sendRegionHandshakeToAll();
  441. return true;
  442. }
  443. /// <summary>
  444. /// Load terrain data
  445. /// </summary>
  446. /// <param name="terrainPath"></param>
  447. /// <param name="data"></param>
  448. /// <returns>
  449. /// true if terrain was resolved successfully, false otherwise.
  450. /// </returns>
  451. private bool LoadTerrain(string terrainPath, byte[] data)
  452. {
  453. ITerrainModule terrainModule = m_scene.RequestModuleInterface<ITerrainModule>();
  454. MemoryStream ms = new MemoryStream(data);
  455. terrainModule.LoadFromStream(terrainPath, ms);
  456. ms.Close();
  457. m_log.DebugFormat("[ARCHIVER]: Restored terrain {0}", terrainPath);
  458. return true;
  459. }
  460. /// <summary>
  461. /// Load oar control file
  462. /// </summary>
  463. /// <param name="path"></param>
  464. /// <param name="data"></param>
  465. public void LoadControlFile(string path, byte[] data)
  466. {
  467. XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable());
  468. XmlParserContext context = new XmlParserContext(null, nsmgr, null, XmlSpace.None);
  469. XmlTextReader xtr = new XmlTextReader(Encoding.ASCII.GetString(data), XmlNodeType.Document, context);
  470. RegionSettings currentRegionSettings = m_scene.RegionInfo.RegionSettings;
  471. // Loaded metadata will empty if no information exists in the archive
  472. currentRegionSettings.LoadedCreationDateTime = 0;
  473. currentRegionSettings.LoadedCreationID = "";
  474. while (xtr.Read())
  475. {
  476. if (xtr.NodeType == XmlNodeType.Element)
  477. {
  478. if (xtr.Name.ToString() == "archive")
  479. {
  480. int majorVersion = int.Parse(xtr["major_version"]);
  481. int minorVersion = int.Parse(xtr["minor_version"]);
  482. string version = string.Format("{0}.{1}", majorVersion, minorVersion);
  483. if (majorVersion > MAX_MAJOR_VERSION)
  484. {
  485. throw new Exception(
  486. string.Format(
  487. "The OAR you are trying to load has major version number of {0} but this version of OpenSim can only load OARs with major version number {1} and below",
  488. majorVersion, MAX_MAJOR_VERSION));
  489. }
  490. m_log.InfoFormat("[ARCHIVER]: Loading OAR with version {0}", version);
  491. }
  492. if (xtr.Name.ToString() == "datetime")
  493. {
  494. int value;
  495. if (Int32.TryParse(xtr.ReadElementContentAsString(), out value))
  496. currentRegionSettings.LoadedCreationDateTime = value;
  497. }
  498. else if (xtr.Name.ToString() == "id")
  499. {
  500. currentRegionSettings.LoadedCreationID = xtr.ReadElementContentAsString();
  501. }
  502. }
  503. }
  504. currentRegionSettings.Save();
  505. ControlFileLoaded = true;
  506. }
  507. }
  508. }