2006-11-30 03:35:36 +00:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Xml;
|
|
|
|
|
using libsecondlife;
|
|
|
|
|
using libsecondlife.Packets;
|
|
|
|
|
|
|
|
|
|
namespace libsecondlife.TestClient
|
|
|
|
|
{
|
|
|
|
|
public class ExportCommand : Command
|
|
|
|
|
{
|
|
|
|
|
public ExportCommand()
|
|
|
|
|
{
|
|
|
|
|
Name = "export";
|
|
|
|
|
Description = "Exports an object to an xml file. Usage: export uuid outputfile.xml";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string Execute(SecondLife Client, string[] args, LLUUID fromAgentID)
|
|
|
|
|
{
|
|
|
|
|
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-01 23:32:12 +00:00
|
|
|
lock (TestClient.Prims)
|
2006-11-30 03:35:36 +00:00
|
|
|
{
|
2006-12-01 23:32:12 +00:00
|
|
|
foreach (PrimObject prim in TestClient.Prims.Values)
|
2006-11-30 03:35:36 +00:00
|
|
|
{
|
2006-12-01 23:32:12 +00:00
|
|
|
if (prim.ID == id)
|
2006-11-30 03:35:36 +00:00
|
|
|
{
|
2006-12-01 23:32:12 +00:00
|
|
|
if (prim.ParentID != 0)
|
|
|
|
|
{
|
|
|
|
|
localid = prim.ParentID;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
localid = prim.LocalID;
|
|
|
|
|
}
|
2006-12-01 00:28:53 +00:00
|
|
|
|
2006-12-01 23:32:12 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2006-12-01 00:28:53 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (localid != 0)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
XmlWriter writer = XmlWriter.Create(file);
|
|
|
|
|
writer.WriteStartElement("primitives");
|
|
|
|
|
|
2006-12-01 23:32:12 +00:00
|
|
|
lock (TestClient.Prims)
|
2006-12-01 00:28:53 +00:00
|
|
|
{
|
2006-12-01 23:32:12 +00:00
|
|
|
foreach (PrimObject prim in TestClient.Prims.Values)
|
2006-11-30 03:35:36 +00:00
|
|
|
{
|
2006-12-01 23:32:12 +00:00
|
|
|
if (prim.LocalID == localid || prim.ParentID == localid)
|
|
|
|
|
{
|
|
|
|
|
prim.ToXml(writer);
|
|
|
|
|
count++;
|
|
|
|
|
}
|
2006-11-30 03:35:36 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-12-01 00:28:53 +00:00
|
|
|
writer.WriteEndElement();
|
|
|
|
|
writer.Close();
|
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
{
|
|
|
|
|
return "Couldn't find UUID " + id.ToString() + " in the " + TestClient.Prims.Count +
|
|
|
|
|
"objects currently indexed";
|
|
|
|
|
}
|
2006-11-30 03:35:36 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|