Grid Inventory feature upgrade: renaming folders should now be correct, subfolders work, moving folders works.

Tested only in MYSQL, but may work in MSSQL and sqlite.
Probably not working in standalone mode.
afrisby
Brian McBee 2007-12-15 04:57:14 +00:00
parent 53b5fa4974
commit 8a8c89a0f3
16 changed files with 281 additions and 21 deletions

View File

@ -142,5 +142,15 @@ namespace OpenSim.Framework.Communications.Cache
}
return itemList;
}
public List<InventoryFolderBase> RequestListOfFolders()
{
List<InventoryFolderBase> folderList = new List<InventoryFolderBase>();
foreach (InventoryFolderBase folder in SubFolders.Values)
{
folderList.Add(folder);
}
return folderList;
}
}
}

View File

@ -147,6 +147,23 @@ namespace OpenSim.Framework.Communications.Cache
}
}
public void HandleMoveInventoryFolder(IClientAPI remoteClient, LLUUID folderID, LLUUID parentID)
{
CachedUserInfo userProfile;
if (m_userProfiles.TryGetValue(remoteClient.AgentId, out userProfile))
{
if (userProfile.RootFolder != null)
{
InventoryFolderBase baseFolder = new InventoryFolderBase();
baseFolder.agentID = remoteClient.AgentId;
baseFolder.folderID = folderID;
baseFolder.parentID = parentID;
m_parent.InventoryService.MoveInventoryFolder(remoteClient.AgentId, baseFolder);
}
}
}
/// <summary>
/// Tell the client about the various child items and folders contained in the requested folder.
/// </summary>
@ -163,14 +180,15 @@ namespace OpenSim.Framework.Communications.Cache
if (folderID == libraryRoot.folderID)
{
remoteClient.SendInventoryFolderDetails(libraryRoot.agentID, libraryRoot.folderID,
libraryRoot.RequestListOfItems(), libraryRoot.SubFoldersCount);
libraryRoot.RequestListOfItems(), libraryRoot.RequestListOfFolders(), libraryRoot.SubFoldersCount);
return;
}
if ((fold = libraryRoot.HasSubFolder(folderID)) != null)
{
remoteClient.SendInventoryFolderDetails(libraryRoot.agentID, folderID, fold.RequestListOfItems(), fold.SubFoldersCount);
System.Console.WriteLine("fetching librarysubfolder");
remoteClient.SendInventoryFolderDetails(libraryRoot.agentID, folderID, fold.RequestListOfItems(), fold.RequestListOfFolders(), fold.SubFoldersCount);
return;
}
@ -182,19 +200,19 @@ namespace OpenSim.Framework.Communications.Cache
{
if (userProfile.RootFolder.folderID == folderID)
{
System.Console.Write("fetching root folder");
if (fetchItems)
{
remoteClient.SendInventoryFolderDetails(remoteClient.AgentId, folderID,
userProfile.RootFolder.RequestListOfItems(), userProfile.RootFolder.SubFoldersCount);
userProfile.RootFolder.RequestListOfItems(), userProfile.RootFolder.RequestListOfFolders(), userProfile.RootFolder.SubFoldersCount);
}
}
else
{
InventoryFolderImpl folder = userProfile.RootFolder.HasSubFolder(folderID);
if (fetchItems && folder != null)
if ((fold = userProfile.RootFolder.HasSubFolder(folderID)) != null)
{
remoteClient.SendInventoryFolderDetails(remoteClient.AgentId, folderID, folder.RequestListOfItems(), folder.SubFoldersCount);
remoteClient.SendInventoryFolderDetails(remoteClient.AgentId, folderID, fold.RequestListOfItems(), fold.RequestListOfFolders(), fold.SubFoldersCount);
return;
}
}
}

View File

@ -40,6 +40,7 @@ namespace OpenSim.Framework.Communications
{
void RequestInventoryForUser(LLUUID userID, InventoryFolderInfo folderCallBack, InventoryItemInfo itemCallBack);
void AddNewInventoryFolder(LLUUID userID, InventoryFolderBase folder);
void MoveInventoryFolder(LLUUID userID, InventoryFolderBase folder);
void AddNewInventoryItem(LLUUID userID, InventoryItemBase item);
void DeleteInventoryItem(LLUUID userID, InventoryItemBase item);
void CreateNewUserInventory(LLUUID user);

View File

@ -127,6 +127,17 @@ namespace OpenSim.Framework.Communications
return null;
}
/// <summary>
///
/// </summary>
public void MoveInventoryFolder(LLUUID userID, InventoryFolderBase folder)
{
foreach (KeyValuePair<string, IInventoryData> plugin in m_plugins)
{
plugin.Value.moveInventoryFolder(folder);
}
}
/// <summary>
///
/// </summary>
@ -161,6 +172,14 @@ namespace OpenSim.Framework.Communications
}
}
public void MoveFolder(InventoryFolderBase folder)
{
foreach (KeyValuePair<string, IInventoryData> plugin in m_plugins)
{
plugin.Value.moveInventoryFolder(folder);
}
}
public void AddItem(InventoryItemBase item)
{
foreach (KeyValuePair<string, IInventoryData> plugin in m_plugins)
@ -251,6 +270,7 @@ namespace OpenSim.Framework.Communications
InventoryItemInfo itemCallBack);
public abstract void AddNewInventoryFolder(LLUUID userID, InventoryFolderBase folder);
public abstract void MoveExistingInventoryFolder(InventoryFolderBase folder);
public abstract void AddNewInventoryItem(LLUUID userID, InventoryItemBase item);
public abstract void DeleteInventoryItem(LLUUID userID, InventoryItemBase item);
}

View File

@ -604,6 +604,34 @@ namespace OpenSim.Framework.Data.MSSQL
}
/// <summary>
/// Updates an inventory folder
/// </summary>
/// <param name="folder">Folder to update</param>
public void moveInventoryFolder(InventoryFolderBase folder)
{
SqlCommand command = new SqlCommand("UPDATE inventoryfolders set folderID = @folderID, " +
"parentFolderID = @parentFolderID," +
"folderID = @keyFolderID;", database.getConnection());
SqlParameter param1 = new SqlParameter("@folderID", folder.folderID.ToStringHyphenated());
SqlParameter param2 = new SqlParameter("@parentFolderID", folder.parentID.ToStringHyphenated());
SqlParameter param3 = new SqlParameter("@keyFolderID", folder.folderID.ToStringHyphenated());
command.Parameters.Add(param1);
command.Parameters.Add(param2);
command.Parameters.Add(param3);
try
{
command.ExecuteNonQuery();
}
catch (Exception e)
{
MainLog.Instance.Error(e.ToString());
}
}
/// <summary>
/// Append a list of all the child folders of a parent folder

View File

@ -529,6 +529,28 @@ namespace OpenSim.Framework.Data.MySQL
addInventoryFolder(folder);
}
/// Creates a new inventory folder
/// </summary>
/// <param name="folder">Folder to create</param>
public void moveInventoryFolder(InventoryFolderBase folder)
{
string sql =
"UPDATE inventoryfolders SET parentFolderID=?parentFolderID WHERE folderID=?folderID";
MySqlCommand cmd = new MySqlCommand(sql, database.Connection);
cmd.Parameters.AddWithValue("?folderID", folder.folderID.ToStringHyphenated());
cmd.Parameters.AddWithValue("?parentFolderID", folder.parentID.ToStringHyphenated());
try
{
cmd.ExecuteNonQuery();
}
catch (Exception e)
{
MainLog.Instance.Error(e.ToString());
}
}
/// <summary>
/// Append a list of all the child folders of a parent folder

View File

@ -141,6 +141,24 @@ namespace OpenSim.Framework.Data.SQLite
invFoldersDa.Update(ds, "inventoryfolders");
}
private void moveFolder(InventoryFolderBase folder)
{
DataTable inventoryFolderTable = ds.Tables["inventoryfolders"];
DataRow inventoryRow = inventoryFolderTable.Rows.Find(folder.folderID);
if (inventoryRow == null)
{
inventoryRow = inventoryFolderTable.NewRow();
fillFolderRow(inventoryRow, folder);
inventoryFolderTable.Rows.Add(inventoryRow);
}
else
{
moveFolderRow(inventoryRow, folder);
}
invFoldersDa.Update(ds, "inventoryfolders");
}
private void addItem(InventoryItemBase item)
{
DataTable inventoryItemTable = ds.Tables["inventoryitems"];
@ -403,6 +421,15 @@ namespace OpenSim.Framework.Data.SQLite
addFolder(folder);
}
/// <summary>
/// Moves a folder based on its ID with folder
/// </summary>
/// <param name="folder">The inventory folder</param>
public void moveInventoryFolder(InventoryFolderBase folder)
{
moveFolder(folder);
}
/// <summary>
/// Delete a folder
/// </summary>
@ -534,6 +561,11 @@ namespace OpenSim.Framework.Data.SQLite
row["version"] = folder.version;
}
private void moveFolderRow(DataRow row, InventoryFolderBase folder)
{
row["UUID"] = folder.folderID;
row["parentID"] = folder.parentID;
}
/***********************************************************************
*

View File

@ -330,6 +330,9 @@ namespace OpenSim.Framework
public delegate void UpdateInventoryFolder(
IClientAPI remoteClient, LLUUID folderID, ushort type, string name, LLUUID parentID);
public delegate void MoveInventoryFolder(
IClientAPI remoteClient, LLUUID folderID, LLUUID parentID);
public delegate void CreateNewInventoryItem(
IClientAPI remoteClient, LLUUID transActionID, LLUUID folderID, uint callbackID, string description, string name,
sbyte invType, sbyte type, byte wearableType, uint nextOwnerMask);
@ -432,6 +435,7 @@ namespace OpenSim.Framework
event CreateNewInventoryItem OnCreateNewInventoryItem;
event CreateInventoryFolder OnCreateNewInventoryFolder;
event UpdateInventoryFolder OnUpdateInventoryFolder;
event MoveInventoryFolder OnMoveInventoryFolder;
event FetchInventoryDescendents OnFetchInventoryDescendents;
event PurgeInventoryDescendents OnPurgeInventoryDescendents;
event FetchInventory OnFetchInventory;
@ -522,7 +526,7 @@ namespace OpenSim.Framework
void SendPrimTerseUpdate(ulong regionHandle, ushort timeDilation, uint localID, LLVector3 position,
LLQuaternion rotation, LLVector3 velocity, LLVector3 rotationalvelocity);
void SendInventoryFolderDetails(LLUUID ownerID, LLUUID folderID, List<InventoryItemBase> items, int subFoldersCount);
void SendInventoryFolderDetails(LLUUID ownerID, LLUUID folderID, List<InventoryItemBase> items, List<InventoryFolderBase> folders, int subFoldersCount);
void SendInventoryItemDetails(LLUUID ownerID, InventoryItemBase item);
/// <summary>

View File

@ -238,6 +238,12 @@ namespace OpenSim.Framework
/// <param name="folder">The inventory folder</param>
void updateInventoryFolder(InventoryFolderBase folder);
/// <summary>
/// Updates a folder based on its ID with folder
/// </summary>
/// <param name="folder">The inventory folder</param>
void moveInventoryFolder(InventoryFolderBase folder);
/// <summary>
/// Deletes a folder based on its ID with folder
/// </summary>

View File

@ -45,22 +45,33 @@ namespace OpenSim.Grid.InventoryServer
private bool TryGetUsersInventory(LLUUID userID, out List<InventoryFolderBase> folderList, out List<InventoryItemBase> itemsList)
{
List<InventoryFolderBase> folders = RequestFirstLevelFolders(userID);
List<InventoryFolderBase> rootFolders = RequestFirstLevelFolders(userID);
List<InventoryItemBase> allItems = new List<InventoryItemBase>();
List<InventoryFolderBase> allFolders = new List<InventoryFolderBase>();
if (folders != null)
if (rootFolders != null)
{
foreach (InventoryFolderBase folder in folders)
allFolders.InsertRange(0, rootFolders);
foreach (InventoryFolderBase subfolder in rootFolders)
{
List<InventoryItemBase> items = RequestFolderItems(folder.folderID);
if (items != null)
List<InventoryFolderBase> subFolders = GetAllFolders(subfolder.folderID);
if (subFolders != null)
{
allItems.InsertRange(0, items);
allFolders.InsertRange(0, subFolders);
}
}
}
folderList = folders;
foreach (InventoryFolderBase folder in allFolders)
{
List<InventoryItemBase> items = RequestFolderItems(folder.folderID);
if (items != null)
{
allItems.InsertRange(0, items);
}
}
folderList = allFolders;
itemsList = allItems;
if (folderList != null)
{
@ -72,6 +83,26 @@ namespace OpenSim.Grid.InventoryServer
}
}
private List<InventoryFolderBase> GetAllFolders(LLUUID folder)
{
List<InventoryFolderBase> allFolders = new List<InventoryFolderBase>();
List<InventoryFolderBase> folders = RequestSubFolders(folder);
if (folders != null)
{
allFolders.InsertRange(0, folders);
foreach (InventoryFolderBase subfolder in folders)
{
List<InventoryFolderBase> subFolders = GetAllFolders(subfolder.folderID);
if (subFolders != null)
{
allFolders.InsertRange(0, subFolders);
}
}
}
return allFolders;
}
public InventoryCollection GetUserInventory(Guid rawUserID)
{
Console.WriteLine("Request for Inventory for " + rawUserID.ToString());
@ -104,6 +135,11 @@ namespace OpenSim.Grid.InventoryServer
AddFolder(folder);
}
public override void MoveExistingInventoryFolder(InventoryFolderBase folder)
{
MoveFolder(folder);
}
public override void AddNewInventoryItem(LLUUID userID, InventoryItemBase item)
{
AddItem(item);
@ -111,11 +147,16 @@ namespace OpenSim.Grid.InventoryServer
public bool AddInventoryFolder( InventoryFolderBase folder)
{
Console.WriteLine("creating new folder for " + folder.agentID.ToString());
AddNewInventoryFolder(folder.agentID, folder);
return true;
}
public bool MoveInventoryFolder(InventoryFolderBase folder)
{
MoveExistingInventoryFolder(folder);
return true;
}
public bool AddInventoryItem( InventoryItemBase item)
{
Console.WriteLine("creating new item for " + item.avatarID.ToString());

View File

@ -87,6 +87,10 @@ namespace OpenSim.Grid.InventoryServer
new RestDeserialisehandler<InventoryFolderBase, bool>("POST", "/NewFolder/",
m_inventoryService.AddInventoryFolder));
httpServer.AddStreamHandler(
new RestDeserialisehandler<InventoryFolderBase, bool>("POST", "/MoveFolder/",
m_inventoryService.MoveInventoryFolder));
httpServer.AddStreamHandler(
new RestDeserialisehandler<InventoryItemBase, bool>("POST", "/NewItem/",
m_inventoryService.AddInventoryItem));

View File

@ -502,6 +502,7 @@ namespace OpenSim.Region.ClientStack
public event CreateNewInventoryItem OnCreateNewInventoryItem;
public event CreateInventoryFolder OnCreateNewInventoryFolder;
public event UpdateInventoryFolder OnUpdateInventoryFolder;
public event MoveInventoryFolder OnMoveInventoryFolder;
public event FetchInventoryDescendents OnFetchInventoryDescendents;
public event PurgeInventoryDescendents OnPurgeInventoryDescendents;
public event FetchInventory OnFetchInventory;
@ -892,7 +893,7 @@ namespace OpenSim.Region.ClientStack
/// <param name="subFoldersCount">The number of subfolders contained in the given folder. This is necessary since
/// the client is expecting inventory packets which incorporate this number into the descendents field, even though
/// we send back no details of the folders themselves (only the items).</param>
public void SendInventoryFolderDetails(LLUUID ownerID, LLUUID folderID, List<InventoryItemBase> items, int subFoldersCount)
public void SendInventoryFolderDetails(LLUUID ownerID, LLUUID folderID, List<InventoryItemBase> items, List<InventoryFolderBase> folders, int subFoldersCount)
{
Encoding enc = Encoding.ASCII;
uint FULL_MASK_PERMISSIONS = 2147483647;
@ -931,14 +932,14 @@ namespace OpenSim.Region.ClientStack
descend.ItemData[i].FolderID = item.parentFolderID;
descend.ItemData[i].GroupID = new LLUUID("00000000-0000-0000-0000-000000000000");
descend.ItemData[i].GroupMask = 0;
descend.ItemData[i].InvType = (sbyte) item.invType;
descend.ItemData[i].InvType = (sbyte)item.invType;
descend.ItemData[i].Name = Helpers.StringToField(item.inventoryName);
descend.ItemData[i].NextOwnerMask = item.inventoryNextPermissions;
descend.ItemData[i].OwnerID = item.avatarID;
descend.ItemData[i].OwnerMask = item.inventoryCurrentPermissions;
descend.ItemData[i].SalePrice = 0;
descend.ItemData[i].SaleType = 0;
descend.ItemData[i].Type = (sbyte) item.assetType;
descend.ItemData[i].Type = (sbyte)item.assetType;
descend.ItemData[i].CRC =
Helpers.InventoryCRC(descend.ItemData[i].CreationDate, descend.ItemData[i].SaleType,
@ -976,6 +977,47 @@ namespace OpenSim.Region.ClientStack
{
OutPacket(descend, ThrottleOutPacketType.Asset);
}
//send subfolders
descend = CreateInventoryDescendentsPacket(ownerID, folderID);
descend.FolderData = new InventoryDescendentsPacket.FolderDataBlock[folders.Count];
i = 0;
count = 0;
foreach (InventoryFolderBase folder in folders)
{
descend.FolderData[i] = new InventoryDescendentsPacket.FolderDataBlock();
descend.FolderData[i].FolderID = folder.folderID;
descend.FolderData[i].Name = Helpers.StringToField(folder.name);
descend.FolderData[i].ParentID = folder.parentID;
descend.FolderData[i].Type = (sbyte)folder.type;
i++;
count++;
if (i == 40)
{
OutPacket(descend, ThrottleOutPacketType.Asset);
if ((folders.Count - count) > 0)
{
descend = CreateInventoryDescendentsPacket(ownerID, folderID);
if ((folders.Count - count) < 40)
{
descend.FolderData = new InventoryDescendentsPacket.FolderDataBlock[items.Count - count];
descend.AgentData.Descendents = folders.Count - count;
}
else
{
descend.FolderData = new InventoryDescendentsPacket.FolderDataBlock[40];
descend.AgentData.Descendents = 40;
}
i = 0;
}
}
}
if (i < 40)
{
OutPacket(descend, ThrottleOutPacketType.Asset);
}
}
private InventoryDescendentsPacket CreateInventoryDescendentsPacket(LLUUID ownerID, LLUUID folderID)
@ -2821,6 +2863,17 @@ namespace OpenSim.Region.ClientStack
}
}
break;
case PacketType.MoveInventoryFolder:
if (OnMoveInventoryFolder != null)
{
MoveInventoryFolderPacket invFolder = (MoveInventoryFolderPacket)Pack;
for (int i = 0; i < invFolder.InventoryData.Length; i++)
{
OnMoveInventoryFolder(this, invFolder.InventoryData[i].FolderID,
invFolder.InventoryData[i].ParentID);
}
}
break;
case PacketType.CreateInventoryItem:
CreateInventoryItemPacket createItem = (CreateInventoryItemPacket) Pack;
if (OnCreateNewInventoryItem != null)
@ -3267,6 +3320,10 @@ namespace OpenSim.Region.ClientStack
// TODO: handle this packet
MainLog.Instance.Warn("CLIENT", "unhandled RequestRegionInfo packet");
break;
case PacketType.InventoryDescendents:
// TODO: handle this packet
MainLog.Instance.Warn("CLIENT", "unhandled InventoryDescent packet");
break;
default:
MainLog.Instance.Warn("CLIENT", "unhandled packet " + Pack.ToString());
break;

View File

@ -68,6 +68,11 @@ namespace OpenSim.Region.Communications.Local
AddFolder(folder);
}
public override void MoveExistingInventoryFolder(InventoryFolderBase folder)
{
MoveFolder(folder);
}
public override void AddNewInventoryItem(LLUUID userID, InventoryItemBase item)
{
AddItem(item);

View File

@ -126,6 +126,16 @@ namespace OpenSim.Region.Communications.OGS1
}
}
public void MoveInventoryFolder(LLUUID userID, InventoryFolderBase folder)
{
try
{
RestObjectPoster.BeginPostObject<InventoryFolderBase>(_inventoryServerUrl + "/MoveFolder/", folder);
}
catch (Exception)
{
}
}
public void AddNewInventoryItem(LLUUID userID, InventoryItemBase item)
{
try

View File

@ -1102,6 +1102,7 @@ namespace OpenSim.Region.Environment.Scenes
client.OnCreateNewInventoryItem += CreateNewInventoryItem;
client.OnCreateNewInventoryFolder += CommsManager.UserProfileCacheService.HandleCreateInventoryFolder;
client.OnUpdateInventoryFolder += CommsManager.UserProfileCacheService.HandleUpdateInventoryFolder;
client.OnMoveInventoryFolder += CommsManager.UserProfileCacheService.HandleMoveInventoryFolder;
client.OnFetchInventoryDescendents += CommsManager.UserProfileCacheService.HandleFetchInventoryDescendents;
client.OnPurgeInventoryDescendents += CommsManager.UserProfileCacheService.HandlePurgeInventoryDescendents;
client.OnRequestTaskInventory += RequestTaskInventory;

View File

@ -108,6 +108,7 @@ namespace SimpleApp
public event CreateNewInventoryItem OnCreateNewInventoryItem;
public event CreateInventoryFolder OnCreateNewInventoryFolder;
public event UpdateInventoryFolder OnUpdateInventoryFolder;
public event MoveInventoryFolder OnMoveInventoryFolder;
public event FetchInventoryDescendents OnFetchInventoryDescendents;
public event PurgeInventoryDescendents OnPurgeInventoryDescendents;
public event FetchInventory OnFetchInventory;
@ -317,7 +318,7 @@ namespace SimpleApp
{
}
public virtual void SendInventoryFolderDetails(LLUUID ownerID, LLUUID folderID, List<InventoryItemBase> items, int subFoldersCount)
public virtual void SendInventoryFolderDetails(LLUUID ownerID, LLUUID folderID, List<InventoryItemBase> items, List<InventoryFolderBase> folders, int subFoldersCount)
{
}