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);
|
|
|
|
|
ImageDownload Image;
|
|
|
|
|
AssetTexture Asset;
|
|
|
|
|
|
|
|
|
|
public DownloadTextureCommand(TestClient testClient)
|
|
|
|
|
{
|
|
|
|
|
Name = "downloadtexture";
|
|
|
|
|
Description = "Downloads the specified texture. " +
|
|
|
|
|
"Usage: downloadtexture [texture-uuid]";
|
|
|
|
|
|
|
|
|
|
testClient.Assets.OnImageReceiveProgress += new AssetManager.ImageReceiveProgressCallback(Assets_OnImageReceiveProgress);
|
|
|
|
|
testClient.Assets.OnImageReceived += new AssetManager.ImageReceivedCallback(Assets_OnImageReceived);
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-25 05:15:05 +00:00
|
|
|
public override string Execute(string[] args, UUID fromAgentID)
|
2008-04-22 23:32:15 +00:00
|
|
|
{
|
|
|
|
|
if (args.Length != 1)
|
|
|
|
|
return "Usage: downloadtexture [texture-uuid]";
|
|
|
|
|
|
2008-07-25 05:15:05 +00:00
|
|
|
TextureID = UUID.Zero;
|
2008-04-22 23:32:15 +00:00
|
|
|
DownloadHandle.Reset();
|
|
|
|
|
Image = null;
|
|
|
|
|
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
|
|
|
{
|
|
|
|
|
Client.Assets.RequestImage(TextureID, ImageType.Normal);
|
|
|
|
|
if (DownloadHandle.WaitOne(120 * 1000, false))
|
|
|
|
|
{
|
|
|
|
|
if (Image != null && Image.Success)
|
|
|
|
|
{
|
|
|
|
|
if (Asset != null && Asset.Decode())
|
|
|
|
|
{
|
|
|
|
|
try { File.WriteAllBytes(Image.ID.ToString() + ".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
|
|
|
|
|
|
|
|
return String.Format("Saved {0}.jp2 ({1}x{2})", Image.ID, Asset.Image.Width, Asset.Image.Height);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return "Failed to decode texture " + TextureID.ToString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (Image != null && Image.NotFound)
|
|
|
|
|
{
|
|
|
|
|
return "Simulator reported texture not found: " + TextureID.ToString();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return "Download failed for texture " + TextureID.ToString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return "Timed out waiting for texture download";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return "Usage: downloadtexture [texture-uuid]";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Assets_OnImageReceived(ImageDownload image, AssetTexture asset)
|
|
|
|
|
{
|
|
|
|
|
Image = image;
|
|
|
|
|
Asset = asset;
|
|
|
|
|
|
|
|
|
|
DownloadHandle.Set();
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-25 05:15:05 +00:00
|
|
|
private void Assets_OnImageReceiveProgress(UUID image, int recieved, int total)
|
2008-04-22 23:32:15 +00:00
|
|
|
{
|
|
|
|
|
Console.WriteLine(String.Format("Texture {0}: Received {1} / {2}", image, recieved, total));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|