2008-10-09 01:55:46 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Threading;
|
2009-05-12 00:07:35 +00:00
|
|
|
|
using OpenMetaverse.Assets;
|
2008-10-09 01:55:46 +00:00
|
|
|
|
|
|
|
|
|
|
namespace OpenMetaverse.TestClient
|
|
|
|
|
|
{
|
|
|
|
|
|
public class DownloadCommand : Command
|
|
|
|
|
|
{
|
|
|
|
|
|
UUID AssetID;
|
|
|
|
|
|
AssetType assetType;
|
|
|
|
|
|
AutoResetEvent DownloadHandle = new AutoResetEvent(false);
|
|
|
|
|
|
bool Success;
|
2011-03-14 15:24:45 +00:00
|
|
|
|
string usage = "Usage: download [uuid] [assetType]";
|
2008-10-09 01:55:46 +00:00
|
|
|
|
|
|
|
|
|
|
public DownloadCommand(TestClient testClient)
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = "download";
|
|
|
|
|
|
Description = "Downloads the specified asset. Usage: download [uuid] [assetType]";
|
|
|
|
|
|
Category = CommandCategory.Inventory;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override string Execute(string[] args, UUID fromAgentID)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (args.Length != 2)
|
2011-03-14 15:24:45 +00:00
|
|
|
|
return usage;
|
2008-10-09 01:55:46 +00:00
|
|
|
|
|
|
|
|
|
|
Success = false;
|
|
|
|
|
|
AssetID = UUID.Zero;
|
|
|
|
|
|
assetType = AssetType.Unknown;
|
|
|
|
|
|
DownloadHandle.Reset();
|
|
|
|
|
|
|
2011-03-14 15:24:45 +00:00
|
|
|
|
if (!UUID.TryParse(args[0], out AssetID))
|
2011-03-14 15:27:06 +00:00
|
|
|
|
return usage;
|
2008-10-09 01:55:46 +00:00
|
|
|
|
|
2011-03-14 15:27:06 +00:00
|
|
|
|
try {
|
2011-03-17 18:34:03 +00:00
|
|
|
|
assetType = (AssetType)Enum.Parse(typeof(AssetType), args[1], true);
|
2011-03-14 15:27:06 +00:00
|
|
|
|
} catch (ArgumentException) {
|
|
|
|
|
|
return usage;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!Enum.IsDefined(typeof(AssetType), assetType))
|
|
|
|
|
|
return usage;
|
2008-10-09 01:55:46 +00:00
|
|
|
|
|
2011-03-14 15:27:06 +00:00
|
|
|
|
// Start the asset download
|
|
|
|
|
|
Client.Assets.RequestAsset(AssetID, assetType, true, Assets_OnAssetReceived);
|
2011-03-14 15:24:45 +00:00
|
|
|
|
|
2025-01-13 07:44:05 -06:00
|
|
|
|
if (DownloadHandle.WaitOne(TimeSpan.FromMinutes(2), false))
|
2011-03-14 15:27:06 +00:00
|
|
|
|
{
|
2024-07-01 12:17:07 -05:00
|
|
|
|
return Success ? $"Saved {AssetID}.{assetType.ToString().ToLower()}"
|
|
|
|
|
|
: $"Failed to download asset {AssetID}, perhaps {assetType} is the incorrect asset type?";
|
2011-03-14 15:27:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return "Timed out waiting for texture download";
|
|
|
|
|
|
}
|
2008-10-09 01:55:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void Assets_OnAssetReceived(AssetDownload transfer, Asset asset)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (transfer.AssetID == AssetID)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (transfer.Success)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2022-02-25 19:38:11 -06:00
|
|
|
|
File.WriteAllBytes($"{AssetID}.{assetType.ToString().ToLower()}", asset.AssetData);
|
2008-10-09 01:55:46 +00:00
|
|
|
|
Success = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
Logger.Log(ex.Message, Helpers.LogLevel.Error, ex);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DownloadHandle.Set();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|