protected internal void ReceivedAllAssets(
            ICollection <UUID> assetsFoundUuids, ICollection <UUID> assetsNotFoundUuids)
        {
            foreach (UUID uuid in assetsNotFoundUuids)
            {
                m_log.DebugFormat("[ARCHIVER]: Could not find asset {0}", uuid);
            }

            m_log.InfoFormat(
                "[ARCHIVER]: Received {0} of {1} assets requested",
                assetsFoundUuids.Count, assetsFoundUuids.Count + assetsNotFoundUuids.Count);

            // Write out region settings
            string settingsPath
                = String.Format("{0}{1}.xml", ArchiveConstants.SETTINGS_PATH, m_scene.RegionInfo.RegionName);

            m_archiveWriter.WriteFile(settingsPath, RegionSettingsSerializer.Serialize(m_scene.RegionInfo.RegionSettings));

            m_log.InfoFormat("[ARCHIVER]: Added region settings to archive.");

            // Write out terrain
            string terrainPath
                = String.Format("{0}{1}.r32", ArchiveConstants.TERRAINS_PATH, m_scene.RegionInfo.RegionName);

            MemoryStream ms = new MemoryStream();

            m_terrainModule.SaveToStream(terrainPath, ms);
            m_archiveWriter.WriteFile(terrainPath, ms.ToArray());
            ms.Close();

            m_log.InfoFormat("[ARCHIVER]: Added terrain information to archive.");

            // Write out scene object metadata
            foreach (SceneObjectGroup sceneObject in m_sceneObjects)
            {
                //m_log.DebugFormat("[ARCHIVER]: Saving {0} {1}, {2}", entity.Name, entity.UUID, entity.GetType());

                Vector3 position = sceneObject.AbsolutePosition;

                string serializedObject = m_serializer.SaveGroupToOriginalXml(sceneObject);
                string filename
                    = string.Format(
                          "{0}{1}_{2:000}-{3:000}-{4:000}__{5}.xml",
                          ArchiveConstants.OBJECTS_PATH, sceneObject.Name,
                          Math.Round(position.X), Math.Round(position.Y), Math.Round(position.Z),
                          sceneObject.UUID);

                m_archiveWriter.WriteFile(filename, serializedObject);
            }

            m_log.InfoFormat("[ARCHIVER]: Added scene objects to archive.");

            m_archiveWriter.Close();

            m_log.InfoFormat("[ARCHIVER]: Wrote out Halcyon archive for {0}", m_scene.RegionInfo.RegionName);

            m_scene.EventManager.TriggerOarFileSaved(m_requestId, String.Empty);
        }
Exemple #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);
            }
        }