From 5fd94111434c2faa742d4eb7357d7a6b02253988 Mon Sep 17 00:00:00 2001 From: Oren Hurvitz Date: Mon, 18 Nov 2013 12:48:23 +0200 Subject: [PATCH] Refactored Load IAR: created a generic mechanism to modify the SOG's as they are being loaded Resolves http://opensimulator.org/mantis/view.php?id=6942 --- .../Archiver/InventoryArchiveReadRequest.cs | 66 ++++++------------ .../Serialization/SceneObjectSerializer.cs | 67 +++++++++++++++++++ 2 files changed, 86 insertions(+), 47 deletions(-) diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs index f7057fef2b..9963521a4f 100644 --- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs +++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs @@ -483,52 +483,24 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver { if (m_creatorIdForAssetId.ContainsKey(assetId)) { - string xmlData = Utils.BytesToString(data); - List sceneObjects = new List(); + data = SceneObjectSerializer.ModifySerializedObject(assetId, data, + sog => { + bool modified = false; + + foreach (SceneObjectPart sop in sog.Parts) + { + if (string.IsNullOrEmpty(sop.CreatorData)) + { + sop.CreatorID = m_creatorIdForAssetId[assetId]; + modified = true; + } + } + + return modified; + }); - CoalescedSceneObjects coa = null; - if (CoalescedSceneObjectsSerializer.TryFromXml(xmlData, out coa)) - { -// m_log.DebugFormat( -// "[INVENTORY ARCHIVER]: Loaded coalescence {0} has {1} objects", assetId, coa.Count); - - if (coa.Objects.Count == 0) - { - m_log.WarnFormat( - "[INVENTORY ARCHIVE READ REQUEST]: Aborting load of coalesced object from asset {0} as it has zero loaded components", - assetId); - return false; - } - - sceneObjects.AddRange(coa.Objects); - } - else - { - SceneObjectGroup deserializedObject = SceneObjectSerializer.FromOriginalXmlFormat(xmlData); - - if (deserializedObject != null) - { - sceneObjects.Add(deserializedObject); - } - else - { - m_log.WarnFormat( - "[INVENTORY ARCHIVE READ REQUEST]: Aborting load of object from asset {0} as deserialization failed", - assetId); - - return false; - } - } - - foreach (SceneObjectGroup sog in sceneObjects) - foreach (SceneObjectPart sop in sog.Parts) - if (string.IsNullOrEmpty(sop.CreatorData)) - sop.CreatorID = m_creatorIdForAssetId[assetId]; - - if (coa != null) - data = Utils.StringToBytes(CoalescedSceneObjectsSerializer.ToXml(coa)); - else - data = Utils.StringToBytes(SceneObjectSerializer.ToOriginalXmlFormat(sceneObjects[0])); + if (data == null) + return false; } } @@ -550,7 +522,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver return false; } } - + /// /// Load control file /// @@ -656,4 +628,4 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver m_assetsLoaded = true; } } -} \ No newline at end of file +} diff --git a/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs b/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs index 4deca006f2..a93f3c8a85 100644 --- a/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs +++ b/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs @@ -299,6 +299,73 @@ namespace OpenSim.Region.Framework.Scenes.Serialization } } + + /// + /// Modifies a SceneObjectGroup. + /// + /// The object + /// Whether the object was actually modified + public delegate bool SceneObjectModifier(SceneObjectGroup sog); + + /// + /// Modifies an object by deserializing it; applying 'modifier' to each SceneObjectGroup; and reserializing. + /// + /// The object's UUID + /// Serialized data + /// The function to run on each SceneObjectGroup + /// The new serialized object's data, or null if an error occurred + public static byte[] ModifySerializedObject(UUID assetId, byte[] data, SceneObjectModifier modifier) + { + List sceneObjects = new List(); + CoalescedSceneObjects coa = null; + + string xmlData = Utils.BytesToString(data); + + if (CoalescedSceneObjectsSerializer.TryFromXml(xmlData, out coa)) + { + // m_log.DebugFormat("[SERIALIZER]: Loaded coalescence {0} has {1} objects", assetId, coa.Count); + + if (coa.Objects.Count == 0) + { + m_log.WarnFormat("[SERIALIZER]: Aborting load of coalesced object from asset {0} as it has zero loaded components", assetId); + return null; + } + + sceneObjects.AddRange(coa.Objects); + } + else + { + SceneObjectGroup deserializedObject = FromOriginalXmlFormat(xmlData); + + if (deserializedObject != null) + { + sceneObjects.Add(deserializedObject); + } + else + { + m_log.WarnFormat("[SERIALIZER]: Aborting load of object from asset {0} as deserialization failed", assetId); + return null; + } + } + + bool modified = false; + foreach (SceneObjectGroup sog in sceneObjects) + { + if (modifier(sog)) + modified = true; + } + + if (modified) + { + if (coa != null) + data = Utils.StringToBytes(CoalescedSceneObjectsSerializer.ToXml(coa)); + else + data = Utils.StringToBytes(ToOriginalXmlFormat(sceneObjects[0])); + } + + return data; + } + #region manual serialization