From 45e280274ca476fcad0d806f350043eb873d7eea Mon Sep 17 00:00:00 2001 From: Latif Khalifa Date: Fri, 4 Jul 2014 13:48:00 +0200 Subject: [PATCH] When uploading mesh objects with textures also create inventory items for uploaded textures. This implements: http://opensimulator.org/mantis/view.php?id=7250 --- .../Linden/Caps/BunchOfCaps/BunchOfCaps.cs | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs b/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs index 0eb15f8d43..1d7938bd80 100644 --- a/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs +++ b/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs @@ -44,6 +44,7 @@ using OpenSim.Region.Framework.Scenes; using OpenSim.Region.Framework.Scenes.Serialization; using OpenSim.Framework.Servers; using OpenSim.Framework.Servers.HttpServer; +using OpenSim.Framework.Client; using OpenSim.Services.Interfaces; using Caps = OpenSim.Framework.Capabilities.Caps; @@ -536,6 +537,39 @@ namespace OpenSim.Region.ClientStack.Linden OSDArray texture_list = (OSDArray)request["texture_list"]; SceneObjectGroup grp = null; + InventoryFolderBase textureUploadFolder = null; + + List foldersToUpdate = new List(); + List itemsToUpdate = new List(); + IClientInventory clientInv = null; + + if (texture_list.Count > 0) + { + ScenePresence avatar = null; + IClientAPI client = null; + m_Scene.TryGetScenePresence(m_HostCapsObj.AgentID, out avatar); + + if (avatar != null) + { + IClientCore core = (IClientCore)avatar.ControllingClient; + + if (core.TryGet(out clientInv)) + { + var systemTextureFolder = m_Scene.InventoryService.GetFolderForType(m_HostCapsObj.AgentID, AssetType.Texture); + textureUploadFolder = new InventoryFolderBase(UUID.Random(), assetName, m_HostCapsObj.AgentID, (short)AssetType.Unknown, systemTextureFolder.ID, 1); + if (m_Scene.InventoryService.AddFolder(textureUploadFolder)) + { + foldersToUpdate.Add(textureUploadFolder); + m_log.DebugFormat("Created new folder '{0}' ({1}) for textures uploaded with mesh object {2}", textureUploadFolder.Name, textureUploadFolder.ID, assetName); + } + else + { + textureUploadFolder = null; + } + } + } + } + List textures = new List(); for (int i = 0; i < texture_list.Count; i++) { @@ -543,6 +577,35 @@ namespace OpenSim.Region.ClientStack.Linden textureAsset.Data = texture_list[i].AsBinary(); m_assetService.Store(textureAsset); textures.Add(textureAsset.FullID); + + if (textureUploadFolder != null) + { + InventoryItemBase textureItem = new InventoryItemBase(); + textureItem.Owner = m_HostCapsObj.AgentID; + textureItem.CreatorId = m_HostCapsObj.AgentID.ToString(); + textureItem.CreatorData = String.Empty; + textureItem.ID = UUID.Random(); + textureItem.AssetID = textureAsset.FullID; + textureItem.Description = assetDescription; + textureItem.Name = assetName + " - Texture " + (i + 1).ToString(); + textureItem.AssetType = (int)AssetType.Texture; + textureItem.InvType = (int)InventoryType.Texture; + textureItem.Folder = textureUploadFolder.ID; + textureItem.CurrentPermissions + = (uint)(PermissionMask.Move | PermissionMask.Copy | PermissionMask.Modify | PermissionMask.Transfer | PermissionMask.Export); + textureItem.BasePermissions = (uint)PermissionMask.All | (uint)PermissionMask.Export; + textureItem.EveryOnePermissions = 0; + textureItem.NextPermissions = (uint)PermissionMask.All; + textureItem.CreationDate = Util.UnixTimeSinceEpoch(); + m_Scene.InventoryService.AddItem(textureItem); + itemsToUpdate.Add(textureItem); + m_log.DebugFormat("Created new inventory item '{0}' ({1}) for texture uploaded with mesh object {2}", textureItem.Name, textureItem.ID, assetName); + } + } + + if (clientInv != null && (foldersToUpdate.Count > 0 || itemsToUpdate.Count > 0)) + { + clientInv.SendBulkUpdateInventory(foldersToUpdate.ToArray(), itemsToUpdate.ToArray()); } for (int i = 0; i < mesh_list.Count; i++)