2006-11-30 03:35:36 +00:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Xml;
|
2006-12-21 08:53:08 +00:00
|
|
|
using System.Threading;
|
2006-11-30 03:35:36 +00:00
|
|
|
using libsecondlife;
|
|
|
|
|
using libsecondlife.Packets;
|
|
|
|
|
|
|
|
|
|
namespace libsecondlife.TestClient
|
|
|
|
|
{
|
|
|
|
|
public class ExportCommand : Command
|
|
|
|
|
{
|
2006-12-21 08:53:08 +00:00
|
|
|
ManualResetEvent GotPermissionsEvent = new ManualResetEvent(false);
|
2007-01-29 22:20:12 +00:00
|
|
|
LLObject.ObjectPropertiesFamily Properties;
|
2006-12-21 08:53:08 +00:00
|
|
|
bool GotPermissions = false;
|
|
|
|
|
|
|
|
|
|
public ExportCommand(TestClient testClient)
|
2006-11-30 03:35:36 +00:00
|
|
|
{
|
2007-01-29 22:20:12 +00:00
|
|
|
testClient.Objects.OnObjectPropertiesFamily += new ObjectManager.ObjectPropertiesFamilyCallback(Objects_OnObjectProperties);
|
2006-12-21 08:53:08 +00:00
|
|
|
|
2006-11-30 03:35:36 +00:00
|
|
|
Name = "export";
|
|
|
|
|
Description = "Exports an object to an xml file. Usage: export uuid outputfile.xml";
|
|
|
|
|
}
|
|
|
|
|
|
2006-12-21 08:53:08 +00:00
|
|
|
public override string Execute(string[] args, LLUUID fromAgentID)
|
2006-11-30 03:35:36 +00:00
|
|
|
{
|
|
|
|
|
if (args.Length != 2)
|
|
|
|
|
return "Usage: export uuid outputfile.xml";
|
|
|
|
|
|
|
|
|
|
LLUUID id;
|
2006-12-01 00:28:53 +00:00
|
|
|
uint localid = 0;
|
|
|
|
|
int count = 0;
|
2006-11-30 03:35:36 +00:00
|
|
|
string file = args[1];
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
id = new LLUUID(args[0]);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
|
|
|
|
return "Usage: export uuid outputfile.xml";
|
|
|
|
|
}
|
2006-12-03 20:00:34 +00:00
|
|
|
|
2007-01-04 05:41:23 +00:00
|
|
|
lock (Client.SimPrims)
|
2006-11-30 03:35:36 +00:00
|
|
|
{
|
2007-01-04 05:41:23 +00:00
|
|
|
if (Client.SimPrims.ContainsKey(Client.Network.CurrentSim))
|
2006-11-30 03:35:36 +00:00
|
|
|
{
|
2007-01-29 22:20:12 +00:00
|
|
|
foreach (Primitive prim in Client.SimPrims[Client.Network.CurrentSim].Values)
|
2006-11-30 03:35:36 +00:00
|
|
|
{
|
2006-12-13 21:15:49 +00:00
|
|
|
if (prim.ID == id)
|
2006-12-01 23:32:12 +00:00
|
|
|
{
|
2006-12-13 21:15:49 +00:00
|
|
|
if (prim.ParentID != 0)
|
|
|
|
|
{
|
|
|
|
|
localid = prim.ParentID;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
localid = prim.LocalID;
|
|
|
|
|
}
|
2006-12-01 00:28:53 +00:00
|
|
|
|
2006-12-13 21:15:49 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2006-12-01 23:32:12 +00:00
|
|
|
}
|
2006-12-01 00:28:53 +00:00
|
|
|
}
|
|
|
|
|
}
|
2006-12-03 20:00:34 +00:00
|
|
|
|
2006-12-01 00:28:53 +00:00
|
|
|
if (localid != 0)
|
|
|
|
|
{
|
2006-12-21 08:53:08 +00:00
|
|
|
// Check for export permission first
|
|
|
|
|
Client.Objects.RequestObjectPropertiesFamily(Client.Network.CurrentSim, id);
|
|
|
|
|
GotPermissionsEvent.WaitOne(5000, false);
|
|
|
|
|
|
|
|
|
|
if (!GotPermissions)
|
|
|
|
|
{
|
|
|
|
|
return "Couldn't fetch permissions for the requested object, try again";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
GotPermissions = false;
|
|
|
|
|
|
|
|
|
|
if (Properties.OwnerID != Client.Network.AgentID)
|
|
|
|
|
{
|
|
|
|
|
// We need a MasterID field, those exports should be allowed as well
|
|
|
|
|
return "That object is owned by " + Properties.OwnerID + ", we don't have permission " +
|
|
|
|
|
"to export it";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-12-01 00:28:53 +00:00
|
|
|
try
|
|
|
|
|
{
|
2006-12-16 09:07:28 +00:00
|
|
|
XmlWriterSettings settings = new XmlWriterSettings();
|
|
|
|
|
settings.Indent = true;
|
|
|
|
|
XmlWriter writer = XmlWriter.Create(file, settings);
|
2006-12-22 15:28:33 +00:00
|
|
|
|
2006-12-16 09:07:28 +00:00
|
|
|
try
|
|
|
|
|
{
|
2007-01-29 22:20:12 +00:00
|
|
|
List<Primitive> prims = new List<Primitive>();
|
2006-12-13 21:15:49 +00:00
|
|
|
|
2007-01-04 05:41:23 +00:00
|
|
|
lock (Client.SimPrims)
|
2006-12-16 09:07:28 +00:00
|
|
|
{
|
2007-01-04 05:41:23 +00:00
|
|
|
if (Client.SimPrims.ContainsKey(Client.Network.CurrentSim))
|
2006-12-16 09:07:28 +00:00
|
|
|
{
|
2007-01-29 22:20:12 +00:00
|
|
|
foreach (Primitive prim in Client.SimPrims[Client.Network.CurrentSim].Values)
|
2006-12-16 09:07:28 +00:00
|
|
|
{
|
|
|
|
|
if (prim.LocalID == localid || prim.ParentID == localid)
|
|
|
|
|
{
|
|
|
|
|
prims.Add(prim);
|
|
|
|
|
count++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//Serialize it!
|
|
|
|
|
Helpers.PrimListToXml(prims, writer);
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
writer.Close();
|
|
|
|
|
}
|
2006-12-01 00:28:53 +00:00
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
string ret = "Failed to write to " + file + ":" + e.ToString();
|
|
|
|
|
if (ret.Length > 1000)
|
|
|
|
|
{
|
|
|
|
|
ret = ret.Remove(1000);
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
2006-11-30 03:35:36 +00:00
|
|
|
}
|
|
|
|
|
|
2006-12-01 00:28:53 +00:00
|
|
|
return "Exported " + count + " prims to " + file;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2006-12-13 21:15:49 +00:00
|
|
|
return "Couldn't find UUID " + id.ToString() + " in the " +
|
2007-01-04 05:41:23 +00:00
|
|
|
Client.SimPrims[Client.Network.CurrentSim].Count +
|
2006-12-13 21:15:49 +00:00
|
|
|
"objects currently indexed in the current simulator";
|
2006-12-01 00:28:53 +00:00
|
|
|
}
|
2006-11-30 03:35:36 +00:00
|
|
|
}
|
2006-12-21 08:53:08 +00:00
|
|
|
|
2007-01-29 22:20:12 +00:00
|
|
|
void Objects_OnObjectProperties(Simulator simulator, LLObject.ObjectPropertiesFamily properties)
|
2006-12-21 08:53:08 +00:00
|
|
|
{
|
|
|
|
|
Properties = properties;
|
|
|
|
|
GotPermissions = true;
|
|
|
|
|
GotPermissionsEvent.Set();
|
|
|
|
|
}
|
2006-11-30 03:35:36 +00:00
|
|
|
}
|
|
|
|
|
}
|