Beispiel #1
0
        /// <summary>
        /// Get all the asset uuids associated with a given object.  This includes both those directly associated with
        /// it (e.g. face textures) and recursively, those of items within it's inventory (e.g. objects contained
        /// within this object).
        /// </summary>
        /// <param name="sceneObject"></param>
        /// <param name="assetUuids"></param>
        protected void GetSceneObjectAssetUuids(UUID sceneObjectUuid, IDictionary <UUID, int> assetUuids)
        {
            AssetBase objectAsset = GetAsset(sceneObjectUuid);

            if (null != objectAsset)
            {
                SceneObjectGroup sog;
                if (m_inventorySerializer.IsValidCoalesced(objectAsset.Data))
                {
                    m_log.WarnFormat("[ARCHIVER]: UUID gatherer encountered a coalesced object, asset ID {0} - skipped.", objectAsset.FullID);
                    return;
                }

                if (m_inventorySerializer.IsValidGroup(objectAsset.Data))
                {
                    sog = m_inventorySerializer.DeserializeGroupFromInventoryBytes(objectAsset.Data);
                }
                else
                {
                    string xml = Utils.BytesToString(objectAsset.Data);
                    sog = SceneObjectSerializer.FromOriginalXmlFormat(xml);
                    if (sog == null)
                    {
                        // in some case it may have been saved as XML2
                        sog = SceneObjectSerializer.FromXml2Format(xml);
                        if (sog != null)
                        {
                            m_log.InfoFormat("[ARCHIVER]: Was able to recover asset {0} as XML2 format.", objectAsset.FullID);
                        }
                    }
                }

                if (sog != null)
                {
                    GatherAssetUuids(sog, assetUuids);
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Write an assets metadata file to the given archive
        /// </summary>
        /// <param name="archive"></param>
//        protected void WriteMetadata(TarArchiveWriter archive)
//        {
//            StringWriter sw = new StringWriter();
//            XmlTextWriter xtw = new XmlTextWriter(sw);
//
//            xtw.Formatting = Formatting.Indented;
//            xtw.WriteStartDocument();
//
//            xtw.WriteStartElement("assets");
//
//            foreach (UUID uuid in m_assets.Keys)
//            {
//                AssetBase asset = m_assets[uuid];
//
//                if (asset != null)
//                {
//                    xtw.WriteStartElement("asset");
//
//                    string extension = String.Empty;
//
//                    if (ArchiveConstants.ASSET_TYPE_TO_EXTENSION.ContainsKey(asset.Type))
//                    {
//                        extension = ArchiveConstants.ASSET_TYPE_TO_EXTENSION[asset.Type];
//                    }
//
//                    xtw.WriteElementString("filename", uuid.ToString() + extension);
//
//                    xtw.WriteElementString("name", asset.Name);
//                    xtw.WriteElementString("description", asset.Description);
//                    xtw.WriteElementString("asset-type", asset.Type.ToString());
//
//                    xtw.WriteEndElement();
//                }
//            }
//
//            xtw.WriteEndElement();
//
//            xtw.WriteEndDocument();
//
//            archive.WriteFile("assets.xml", sw.ToString());
//        }

        /// <summary>
        /// Write asset data files to the given archive
        /// </summary>
        /// <param name="asset"></param>
        protected void WriteData(AssetBase asset)
        {
            // It appears that gtar, at least, doesn't need the intermediate directory entries in the tar
            //archive.AddDir("assets");

            string extension = String.Empty;

            if (ArchiveConstants.ASSET_TYPE_TO_EXTENSION.ContainsKey(asset.Type))
            {
                extension = ArchiveConstants.ASSET_TYPE_TO_EXTENSION[asset.Type];
            }
            else
            {
                m_log.ErrorFormat(
                    "[ARCHIVER]: Unrecognized asset type {0} with uuid {1}.  This asset will be saved but not reloaded",
                    asset.Type, asset.ID);
            }

            // Check for Thoosa Inventory object and decode to XML if necessary for Archive.
            string xmlData;

            if ((asset.Type == (sbyte)AssetType.Object) && (m_inventorySerializer != null) && (m_inventorySerializer.CanDeserialize(asset.Data)))
            {
                if (m_inventorySerializer.IsValidCoalesced(asset.Data))
                {
                    CoalescedObject            obj   = m_inventorySerializer.DeserializeCoalescedObjFromInventoryBytes(asset.Data);
                    List <ItemPermissionBlock> perms = new List <ItemPermissionBlock>();
                    foreach (var grp in obj.Groups)
                    {
                        perms.Add(obj.FindPermissions(grp.UUID));
                    }
                    xmlData = CoalescedSceneObjectSerializer.ToXmlFormat(obj.Groups, perms, StopScriptReason.None);
                }
                else
                if (m_inventorySerializer.IsValidGroup(asset.Data))
                {
                    SceneObjectGroup grp = m_inventorySerializer.DeserializeGroupFromInventoryBytes(asset.Data);
                    xmlData = m_serializer.SaveGroupToOriginalXml(grp);
                }
                else
                {
                    return;     // can't pass the CanDeserialize test above, but makes the compiler happy
                }
                // Now write out the XML format asset
                m_archiveWriter.WriteFile(
                    ArchiveConstants.ASSETS_PATH + asset.FullID.ToString() + extension,
                    xmlData);
            }
            else
            {
                // Now write out the same (raw) asset unchanged.
                m_archiveWriter.WriteFile(
                    ArchiveConstants.ASSETS_PATH + asset.FullID.ToString() + extension,
                    asset.Data);
            }
            m_assetsWritten++;

            if (m_assetsWritten % LOG_ASSET_LOAD_NOTIFICATION_INTERVAL == 0)
            {
                m_log.InfoFormat("[ARCHIVER]: Added {0} assets to archive", m_assetsWritten);
            }
        }