* refactor: do a tiny bit of cleanup

0.6.0-stable
Justin Clarke Casey 2008-09-26 15:15:19 +00:00
parent 24628928c3
commit 1278563482
1 changed files with 46 additions and 40 deletions

View File

@ -41,9 +41,8 @@ namespace OpenSim.Region.Environment.Modules.Agent.AssetTransaction
{ {
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public bool AddToInventory; private AssetBase m_asset;
public AssetBase Asset; private UUID InventFolder = UUID.Zero;
public UUID InventFolder = UUID.Zero;
private sbyte invType = 0; private sbyte invType = 0;
private bool m_createItem = false; private bool m_createItem = false;
private string m_description = String.Empty; private string m_description = String.Empty;
@ -54,9 +53,9 @@ namespace OpenSim.Region.Environment.Modules.Agent.AssetTransaction
private AgentAssetTransactions m_userTransactions; private AgentAssetTransactions m_userTransactions;
private uint nextPerm = 0; private uint nextPerm = 0;
private IClientAPI ourClient; private IClientAPI ourClient;
public UUID TransactionID = UUID.Zero; private UUID TransactionID = UUID.Zero;
private sbyte type = 0; private sbyte type = 0;
public bool UploadComplete; private bool UploadComplete;
private byte wearableType = 0; private byte wearableType = 0;
public ulong XferID; public ulong XferID;
@ -77,18 +76,18 @@ namespace OpenSim.Region.Environment.Modules.Agent.AssetTransaction
{ {
if (XferID == xferID) if (XferID == xferID)
{ {
if (Asset.Data.Length > 1) if (m_asset.Data.Length > 1)
{ {
byte[] destinationArray = new byte[Asset.Data.Length + data.Length]; byte[] destinationArray = new byte[m_asset.Data.Length + data.Length];
Array.Copy(Asset.Data, 0, destinationArray, 0, Asset.Data.Length); Array.Copy(m_asset.Data, 0, destinationArray, 0, m_asset.Data.Length);
Array.Copy(data, 0, destinationArray, Asset.Data.Length, data.Length); Array.Copy(data, 0, destinationArray, m_asset.Data.Length, data.Length);
Asset.Data = destinationArray; m_asset.Data = destinationArray;
} }
else else
{ {
byte[] buffer2 = new byte[data.Length - 4]; byte[] buffer2 = new byte[data.Length - 4];
Array.Copy(data, 4, buffer2, 0, data.Length - 4); Array.Copy(data, 4, buffer2, 0, data.Length - 4);
Asset.Data = buffer2; m_asset.Data = buffer2;
} }
ourClient.SendConfirmXfer(xferID, packetID); ourClient.SendConfirmXfer(xferID, packetID);
@ -114,19 +113,19 @@ namespace OpenSim.Region.Environment.Modules.Agent.AssetTransaction
bool storeLocal, bool tempFile) bool storeLocal, bool tempFile)
{ {
ourClient = remoteClient; ourClient = remoteClient;
Asset = new AssetBase(); m_asset = new AssetBase();
Asset.FullID = assetID; m_asset.FullID = assetID;
Asset.Type = type; m_asset.Type = type;
Asset.Data = data; m_asset.Data = data;
Asset.Name = "blank"; m_asset.Name = "blank";
Asset.Description = "empty"; m_asset.Description = "empty";
Asset.Local = storeLocal; m_asset.Local = storeLocal;
Asset.Temporary = tempFile; m_asset.Temporary = tempFile;
TransactionID = transaction; TransactionID = transaction;
m_storeLocal = storeLocal; m_storeLocal = storeLocal;
if (Asset.Data.Length > 2) if (m_asset.Data.Length > 2)
{ {
SendCompleteMessage(); SendCompleteMessage();
return true; return true;
@ -143,14 +142,14 @@ namespace OpenSim.Region.Environment.Modules.Agent.AssetTransaction
{ {
UploadComplete = false; UploadComplete = false;
XferID = Util.GetNextXferID(); XferID = Util.GetNextXferID();
ourClient.SendXferRequest(XferID, Asset.Type, Asset.FullID, 0, new byte[0]); ourClient.SendXferRequest(XferID, m_asset.Type, m_asset.FullID, 0, new byte[0]);
} }
protected void SendCompleteMessage() protected void SendCompleteMessage()
{ {
UploadComplete = true; UploadComplete = true;
ourClient.SendAssetUploadCompleteMessage(Asset.Type, true, Asset.FullID); ourClient.SendAssetUploadCompleteMessage(m_asset.Type, true, m_asset.FullID);
m_finished = true; m_finished = true;
if (m_createItem) if (m_createItem)
@ -159,7 +158,7 @@ namespace OpenSim.Region.Environment.Modules.Agent.AssetTransaction
} }
else if (m_storeLocal) else if (m_storeLocal)
{ {
m_userTransactions.Manager.MyScene.CommsManager.AssetCache.AddAsset(Asset); m_userTransactions.Manager.MyScene.CommsManager.AssetCache.AddAsset(m_asset);
} }
m_log.DebugFormat("[ASSET TRANSACTIONS]: Uploaded asset data for transaction {0}", TransactionID); m_log.DebugFormat("[ASSET TRANSACTIONS]: Uploaded asset data for transaction {0}", TransactionID);
@ -169,8 +168,8 @@ namespace OpenSim.Region.Environment.Modules.Agent.AssetTransaction
DateTime now = DateTime.Now; DateTime now = DateTime.Now;
string filename = string filename =
String.Format("{6}_{7}_{0:d2}{1:d2}{2:d2}_{3:d2}{4:d2}{5:d2}.dat", now.Year, now.Month, now.Day, String.Format("{6}_{7}_{0:d2}{1:d2}{2:d2}_{3:d2}{4:d2}{5:d2}.dat", now.Year, now.Month, now.Day,
now.Hour, now.Minute, now.Second, Asset.Name, Asset.Type); now.Hour, now.Minute, now.Second, m_asset.Name, m_asset.Type);
SaveAssetToFile(filename, Asset.Data); SaveAssetToFile(filename, m_asset.Data);
} }
} }
@ -201,9 +200,9 @@ namespace OpenSim.Region.Environment.Modules.Agent.AssetTransaction
this.invType = invType; this.invType = invType;
this.wearableType = wearableType; this.wearableType = wearableType;
nextPerm = nextOwnerMask; nextPerm = nextOwnerMask;
Asset.Name = name; m_asset.Name = name;
Asset.Description = description; m_asset.Description = description;
Asset.Type = type; m_asset.Type = type;
m_createItem = true; m_createItem = true;
if (m_finished) if (m_finished)
@ -244,7 +243,7 @@ namespace OpenSim.Region.Environment.Modules.Agent.AssetTransaction
asset.Type = (sbyte) item.AssetType; asset.Type = (sbyte) item.AssetType;
item.AssetID = asset.FullID; item.AssetID = asset.FullID;
m_userTransactions.Manager.MyScene.CommsManager.AssetCache.AddAsset(Asset); m_userTransactions.Manager.MyScene.CommsManager.AssetCache.AddAsset(m_asset);
} }
userInfo.UpdateItem(item); userInfo.UpdateItem(item);
@ -259,12 +258,12 @@ namespace OpenSim.Region.Environment.Modules.Agent.AssetTransaction
"[ASSET TRANSACTIONS]: Updating task item {0} in {1} with asset in transaction {2}", "[ASSET TRANSACTIONS]: Updating task item {0} in {1} with asset in transaction {2}",
item.Name, part.Name, transactionID); item.Name, part.Name, transactionID);
Asset.Name = item.Name; m_asset.Name = item.Name;
Asset.Description = item.Description; m_asset.Description = item.Description;
Asset.Type = (sbyte) item.Type; m_asset.Type = (sbyte) item.Type;
item.AssetID = Asset.FullID; item.AssetID = m_asset.FullID;
m_userTransactions.Manager.MyScene.CommsManager.AssetCache.AddAsset(Asset); m_userTransactions.Manager.MyScene.CommsManager.AssetCache.AddAsset(m_asset);
if (part.UpdateInventoryItem(item)) if (part.UpdateInventoryItem(item))
part.GetProperties(remoteClient); part.GetProperties(remoteClient);
@ -273,16 +272,18 @@ namespace OpenSim.Region.Environment.Modules.Agent.AssetTransaction
private void DoCreateItem() private void DoCreateItem()
{ {
//really need to fix this call, if lbsa71 saw this he would die. //really need to fix this call, if lbsa71 saw this he would die.
m_userTransactions.Manager.MyScene.CommsManager.AssetCache.AddAsset(Asset); m_userTransactions.Manager.MyScene.CommsManager.AssetCache.AddAsset(m_asset);
CachedUserInfo userInfo = CachedUserInfo userInfo =
m_userTransactions.Manager.MyScene.CommsManager.UserProfileCacheService.GetUserDetails(ourClient.AgentId); m_userTransactions.Manager.MyScene.CommsManager.UserProfileCacheService.GetUserDetails(
ourClient.AgentId);
if (userInfo != null) if (userInfo != null)
{ {
InventoryItemBase item = new InventoryItemBase(); InventoryItemBase item = new InventoryItemBase();
item.Owner = ourClient.AgentId; item.Owner = ourClient.AgentId;
item.Creator = ourClient.AgentId; item.Creator = ourClient.AgentId;
item.ID = UUID.Random(); item.ID = UUID.Random();
item.AssetID = Asset.FullID; item.AssetID = m_asset.FullID;
item.Description = m_description; item.Description = m_description;
item.Name = m_name; item.Name = m_name;
item.AssetType = type; item.AssetType = type;
@ -299,12 +300,17 @@ namespace OpenSim.Region.Environment.Modules.Agent.AssetTransaction
} }
} }
/// <summary>
/// Get the asset data uploaded in this transfer.
/// </summary>
/// <returns>null if the asset has not finished uploading</returns>
public AssetBase GetAssetData() public AssetBase GetAssetData()
{ {
if (m_finished) if (m_finished)
{ {
return Asset; return m_asset;
} }
return null; return null;
} }
} }