コード例 #1
0
        /// <summary>
        /// Load an asset
        /// </summary>
        /// <param name="assetFilename"></param>
        /// <param name="data"></param>
        /// <returns>true if asset was successfully loaded, false otherwise</returns>
        private bool LoadAsset(string assetPath, byte[] data)
        {
            //IRegionSerialiser serialiser = scene.RequestModuleInterface<IRegionSerialiser>();
            // Right now we're nastily obtaining the UUID from the filename
            string filename = assetPath.Remove(0, ArchiveConstants.ASSETS_PATH.Length);
            int    i        = filename.LastIndexOf(ArchiveConstants.ASSET_EXTENSION_SEPARATOR);

            if (i == -1)
            {
                m_log.ErrorFormat(
                    "[INVENTORY ARCHIVER]: Could not find extension information in asset path {0} since it's missing the separator {1}.  Skipping",
                    assetPath, ArchiveConstants.ASSET_EXTENSION_SEPARATOR);

                return(false);
            }

            string extension = filename.Substring(i);
            string rawUuid   = filename.Remove(filename.Length - extension.Length);
            UUID   assetId   = new UUID(rawUuid);

            if (!ArchiveConstants.EXTENSION_TO_ASSET_TYPE.ContainsKey(extension))
            {
                m_log.ErrorFormat(
                    "[INVENTORY ARCHIVER]: Tried to dearchive data with path {0} with an unknown type extension {1}",
                    assetPath, extension);
                return(false);
            }

            sbyte assetType = ArchiveConstants.EXTENSION_TO_ASSET_TYPE[extension];

            if (assetType == (sbyte)AssetType.Unknown)
            {
                m_log.WarnFormat("[INVENTORY ARCHIVER]: Importing {0} byte asset {1} with unknown type", data.Length, assetId);
                return(false);
            }

            if (assetType == (sbyte)AssetType.Object)
            {
                UUID owner       = m_userInfo.PrincipalID;
                bool doCreatorID = m_creatorIdForAssetId.ContainsKey(assetId);

                data = SceneObjectSerializer.ModifySerializedObject(assetId, data,
                                                                    sog =>
                {
                    foreach (SceneObjectPart sop in sog.Parts)
                    {
                        sop.OwnerID = owner;
                        if (doCreatorID && string.IsNullOrEmpty(sop.CreatorData))
                        {
                            sop.CreatorID = m_creatorIdForAssetId[assetId];
                        }

                        foreach (TaskInventoryItem it in sop.Inventory.GetInventoryItems())
                        {
                            it.OwnerID = owner;
                            if (string.IsNullOrEmpty(it.CreatorData) && m_creatorIdForAssetId.ContainsKey(it.AssetID))
                            {
                                it.CreatorID = m_creatorIdForAssetId[it.AssetID];
                            }
                        }
                    }
                    return(true);
                });

                if (data == null)
                {
                    return(false);
                }
            }

            //m_log.DebugFormat("[INVENTORY ARCHIVER]: Importing asset {0}, type {1}", uuid, assetType);

            AssetBase asset = new AssetBase(assetId, "From IAR", assetType, UUID.Zero.ToString());

            asset.Data = data;

            m_AssetService.Store(asset);

            return(true);
        }
コード例 #2
0
        /// Load an asset
        /// </summary>
        /// <param name="assetFilename"></param>
        /// <param name="data"></param>
        /// <returns>true if asset was successfully loaded, false otherwise</returns>
        private bool LoadAsset(string assetPath, byte[] data)
        {
            // Right now we're nastily obtaining the UUID from the filename
            string filename = assetPath.Remove(0, ArchiveConstants.ASSETS_PATH.Length);
            int    i        = filename.LastIndexOf(ArchiveConstants.ASSET_EXTENSION_SEPARATOR);

            if (i == -1)
            {
                m_log.ErrorFormat(
                    "[ARCHIVER]: Could not find extension information in asset path {0} since it's missing the separator {1}.  Skipping",
                    assetPath, ArchiveConstants.ASSET_EXTENSION_SEPARATOR);

                return(false);
            }

            string extension = filename.Substring(i);
            string uuid      = filename.Remove(filename.Length - extension.Length);

            if (m_assetService.GetMetadata(uuid) != null)
            {
                // m_log.DebugFormat("[ARCHIVER]: found existing asset {0}",uuid);
                return(true);
            }

            if (ArchiveConstants.EXTENSION_TO_ASSET_TYPE.ContainsKey(extension))
            {
                sbyte assetType = ArchiveConstants.EXTENSION_TO_ASSET_TYPE[extension];

                if (assetType == (sbyte)AssetType.Unknown)
                {
                    m_log.WarnFormat("[ARCHIVER]: Importing {0} byte asset {1} with unknown type", data.Length, uuid);
                }
                else if (assetType == (sbyte)AssetType.Object)
                {
                    data = SceneObjectSerializer.ModifySerializedObject(UUID.Parse(uuid), data,
                                                                        sog =>
                    {
                        ModifySceneObject(m_rootScene, sog);
                        return(true);
                    });

                    if (data == null)
                    {
                        return(false);
                    }
                }

                //m_log.DebugFormat("[ARCHIVER]: Importing asset {0}, type {1}", uuid, assetType);

                AssetBase asset = new AssetBase(new UUID(uuid), String.Empty, assetType, UUID.Zero.ToString());
                asset.Data = data;

                // We're relying on the asset service to do the sensible thing and not store the asset if it already
                // exists.
                m_assetService.Store(asset);

                /**
                 * Create layers on decode for image assets.  This is likely to significantly increase the time to load archives so
                 * it might be best done when dearchive takes place on a separate thread
                 * if (asset.Type=AssetType.Texture)
                 * {
                 *  IJ2KDecoder cacheLayerDecode = scene.RequestModuleInterface<IJ2KDecoder>();
                 *  if (cacheLayerDecode != null)
                 *      cacheLayerDecode.syncdecode(asset.FullID, asset.Data);
                 * }
                 */

                return(true);
            }
            else
            {
                m_log.ErrorFormat(
                    "[ARCHIVER]: Tried to dearchive data with path {0} with an unknown type extension {1}",
                    assetPath, extension);

                return(false);
            }
        }