* Fix notecard loading - If the notecard name is formatted like a UUID but isn't an actual asset UUID, then try to load it like an asset id first, then try to load it as a task inventoryitem name. If the passed UUID is a string, try to load it like a task inventory item name.

avinationmerge
teravus 2013-01-21 17:30:38 -05:00
parent 777c80becb
commit 09a3e134e4
1 changed files with 35 additions and 11 deletions

View File

@ -1821,17 +1821,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
{
UUID assetID = UUID.Zero;
if (!UUID.TryParse(notecardNameOrUuid, out assetID))
bool notecardNameIsUUID = UUID.TryParse(notecardNameOrUuid, out assetID);
if (!notecardNameIsUUID)
{
m_host.TaskInventory.LockItemsForRead(true);
foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
{
if (item.Type == 7 && item.Name == notecardNameOrUuid)
{
assetID = item.AssetID;
}
}
m_host.TaskInventory.LockItemsForRead(false);
assetID = SearchTaskInventoryForAssetId(notecardNameOrUuid);
}
if (assetID == UUID.Zero)
@ -1842,7 +1836,23 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
AssetBase a = World.AssetService.Get(assetID.ToString());
if (a == null)
return UUID.Zero;
{
// Whoops, it's still possible here that the notecard name was properly
// formatted like a UUID but isn't an asset UUID so lets look it up by name after all
assetID = SearchTaskInventoryForAssetId(notecardNameOrUuid);
if (assetID == UUID.Zero)
return UUID.Zero;
if (!NotecardCache.IsCached(assetID))
{
a = World.AssetService.Get(assetID.ToString());
if (a == null)
{
return UUID.Zero;
}
}
}
string data = Encoding.UTF8.GetString(a.Data);
NotecardCache.Cache(assetID, data);
@ -1850,6 +1860,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
return assetID;
}
protected UUID SearchTaskInventoryForAssetId(string name)
{
UUID assetId = UUID.Zero;
m_host.TaskInventory.LockItemsForRead(true);
foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
{
if (item.Type == 7 && item.Name == name)
{
assetId = item.AssetID;
}
}
m_host.TaskInventory.LockItemsForRead(false);
return assetId;
}
/// <summary>
/// Directly get an entire notecard at once.