2008-04-22 23:32:15 +00:00
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Threading;
|
2008-07-21 21:12:59 +00:00
|
|
|
using OpenMetaverse;
|
2008-04-22 23:32:15 +00:00
|
|
|
|
2008-07-21 21:12:59 +00:00
|
|
|
namespace OpenMetaverse.TestClient
|
2008-04-22 23:32:15 +00:00
|
|
|
{
|
|
|
|
|
public class DownloadTextureCommand : Command
|
|
|
|
|
{
|
2008-07-25 05:15:05 +00:00
|
|
|
UUID TextureID;
|
2008-04-22 23:32:15 +00:00
|
|
|
AutoResetEvent DownloadHandle = new AutoResetEvent(false);
|
|
|
|
|
AssetTexture Asset;
|
2009-05-07 16:10:52 +00:00
|
|
|
TextureRequestState resultState;
|
2008-04-22 23:32:15 +00:00
|
|
|
|
|
|
|
|
public DownloadTextureCommand(TestClient testClient)
|
|
|
|
|
{
|
|
|
|
|
Name = "downloadtexture";
|
|
|
|
|
Description = "Downloads the specified texture. " +
|
2008-10-09 01:55:46 +00:00
|
|
|
"Usage: downloadtexture [texture-uuid] [discardlevel]";
|
2008-07-25 08:55:36 +00:00
|
|
|
Category = CommandCategory.Inventory;
|
2008-04-22 23:32:15 +00:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-25 05:15:05 +00:00
|
|
|
public override string Execute(string[] args, UUID fromAgentID)
|
2008-04-22 23:32:15 +00:00
|
|
|
{
|
2008-09-29 13:58:08 +00:00
|
|
|
if (args.Length != 1 && args.Length != 2)
|
|
|
|
|
return "Usage: downloadtexture [texture-uuid] [discardlevel]";
|
2008-04-22 23:32:15 +00:00
|
|
|
|
2008-07-25 05:15:05 +00:00
|
|
|
TextureID = UUID.Zero;
|
2008-04-22 23:32:15 +00:00
|
|
|
DownloadHandle.Reset();
|
|
|
|
|
Asset = null;
|
|
|
|
|
|
2008-07-25 05:15:05 +00:00
|
|
|
if (UUID.TryParse(args[0], out TextureID))
|
2008-04-22 23:32:15 +00:00
|
|
|
{
|
2008-09-29 13:58:08 +00:00
|
|
|
int discardLevel = 0;
|
|
|
|
|
|
|
|
|
|
if (args.Length > 1)
|
|
|
|
|
{
|
|
|
|
|
if (!Int32.TryParse(args[1], out discardLevel))
|
|
|
|
|
return "Usage: downloadtexture [texture-uuid] [discardlevel]";
|
|
|
|
|
}
|
|
|
|
|
|
2009-05-07 16:10:52 +00:00
|
|
|
Client.Assets.RequestImage(TextureID, ImageType.Normal, Assets_OnImageReceived);
|
2008-09-29 13:58:08 +00:00
|
|
|
|
2008-04-22 23:32:15 +00:00
|
|
|
if (DownloadHandle.WaitOne(120 * 1000, false))
|
|
|
|
|
{
|
2009-05-07 16:10:52 +00:00
|
|
|
if (resultState == TextureRequestState.Finished)
|
2008-04-22 23:32:15 +00:00
|
|
|
{
|
|
|
|
|
if (Asset != null && Asset.Decode())
|
|
|
|
|
{
|
2009-05-07 16:10:52 +00:00
|
|
|
try { File.WriteAllBytes(Asset.AssetID + ".jp2", Asset.AssetData); }
|
2008-05-06 23:57:26 +00:00
|
|
|
catch (Exception ex) { Logger.Log(ex.Message, Helpers.LogLevel.Error, Client, ex); }
|
2008-04-22 23:32:15 +00:00
|
|
|
|
2009-05-07 16:10:52 +00:00
|
|
|
return String.Format("Saved {0}.jp2 ({1}x{2})", Asset.AssetID, Asset.Image.Width, Asset.Image.Height);
|
2008-04-22 23:32:15 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return "Failed to decode texture " + TextureID.ToString();
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-05-07 16:10:52 +00:00
|
|
|
else if (resultState == TextureRequestState.NotFound)
|
2008-04-22 23:32:15 +00:00
|
|
|
{
|
|
|
|
|
return "Simulator reported texture not found: " + TextureID.ToString();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2009-05-07 16:10:52 +00:00
|
|
|
return "Download failed for texture " + TextureID + " " + resultState;
|
2008-04-22 23:32:15 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return "Timed out waiting for texture download";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return "Usage: downloadtexture [texture-uuid]";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-05-07 16:10:52 +00:00
|
|
|
private void Assets_OnImageReceived(TextureRequestState state, AssetTexture asset)
|
2008-04-22 23:32:15 +00:00
|
|
|
{
|
2009-05-07 16:10:52 +00:00
|
|
|
resultState = state;
|
2008-04-22 23:32:15 +00:00
|
|
|
Asset = asset;
|
|
|
|
|
|
|
|
|
|
DownloadHandle.Set();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|