Added more sophisticated path handling to Inventory. cd command path handling is now available to all TestClient commands. Resolved [TC-12]. Helpers.Implode replaced by String.Join.

git-svn-id: http://libopenmetaverse.googlecode.com/svn/trunk@2077 52acb1d6-8a22-11de-b505-999d5b087335
This commit is contained in:
omegaworks
2008-08-12 05:55:42 +00:00
parent 1de5be5e60
commit 82250be4f1
9 changed files with 264 additions and 165 deletions

View File

@@ -1,5 +1,6 @@
using System;
using OpenMetaverse;
using System.Collections.Generic;
namespace OpenMetaverse.TestClient
{
@@ -16,7 +17,7 @@ namespace OpenMetaverse.TestClient
public override string Execute(string[] args, UUID fromAgentID)
{
if (args.Length < 1)
return "Usage: wear [outfit name] eg: 'wear /My Outfit/Dance Party";
return "Usage: wear [outfit name] [nobake] eg: 'wear \"/Clothing/My Outfit\" [nobake]'";
string target = String.Empty;
bool bake = true;
@@ -28,12 +29,14 @@ namespace OpenMetaverse.TestClient
else
target = target + args[ct] + " ";
}
target = target.TrimEnd();
List<InventoryBase> results = Client.InventoryStore.InventoryFromPath(target, Client.CurrentDirectory, true);
if (results.Count == 0 || !(results[0] is InventoryFolder))
return "Unable to find folder at " + target;
try
{
Client.Appearance.WearOutfit(target.Split('/'), bake);
Client.Appearance.WearOutfit(results[0] as InventoryFolder, bake);
}
catch (InvalidOutfitException ex)
{

View File

@@ -21,68 +21,32 @@ namespace OpenMetaverse.TestClient.Commands.Inventory.Shell
Manager = Client.Inventory;
Inventory = Client.InventoryStore;
if (args.Length > 1)
return "Usage: cd [path-to-folder]";
string pathStr = "";
string[] path = null;
if (args.Length == 0)
{
path = new string[] { "" };
// cd without any arguments doesn't do anything.
}
else if (args.Length == 1)
{
pathStr = args[0];
path = pathStr.Split(new char[] { '/' });
// Use '/' as a path seperator.
}
InventoryFolder currentFolder = Client.CurrentDirectory;
if (pathStr.StartsWith("/"))
currentFolder = Inventory.RootFolder;
return "Current folder: " + Client.CurrentDirectory.Name;
if (currentFolder == null) // We need this to be set to something.
return "Error: Client not logged in.";
// Traverse the path, looking for the
for (int i = 0; i < path.Length; ++i)
string path = args[0];
for(int i = 1; i < args.Length; ++i)
{
string nextName = path[i];
if (string.IsNullOrEmpty(nextName) || nextName == ".")
continue; // Ignore '.' and blanks, stay in the current directory.
if (nextName == ".." && currentFolder != Inventory.RootFolder)
path += " " + args[i];
}
List<InventoryBase> results = Inventory.InventoryFromPath(path, Client.CurrentDirectory, true);
if (results.Count == 0)
return "Can not find inventory at: " + path;
InventoryFolder destFolder = null;
foreach (InventoryBase ib in results)
{
if (ib is InventoryFolder)
{
// If we encounter .., move to the parent folder.
currentFolder = currentFolder.Parent;
}
else
{
if (currentFolder.IsStale)
currentFolder.DownloadContents(TimeSpan.FromSeconds(30));
// Try and find an InventoryBase with the corresponding name.
bool found = false;
foreach (InventoryBase item in currentFolder)
{
string name = item.Name;
// Allow lookup by UUID as well as name:
if (name == nextName || item.UUID.ToString() == nextName)
{
found = true;
if (item is InventoryFolder)
{
currentFolder = item as InventoryFolder;
}
else
{
return name + " is not a folder.";
}
}
}
if (!found)
return nextName + " not found in " + currentFolder.Data.Name;
destFolder = ib as InventoryFolder;
break;
}
}
Client.CurrentDirectory = currentFolder;
return "Current folder: " + currentFolder.Data.Name;
if (destFolder == null)
return path + " is not a folder.";
Client.CurrentDirectory = destFolder;
return "Current folder: " + Client.CurrentDirectory.Name;
}
}
}

View File

@@ -27,14 +27,14 @@ namespace OpenMetaverse.TestClient
string target = String.Empty;
for (int ct = 0; ct < args.Length; ct++)
target = target + args[ct] + " ";
target = target.TrimEnd();
// initialize results list
List<InventoryBase> found = new List<InventoryBase>();
try
{
// find the folder
found = Client.InventoryStore.InventoryFromPath(target.Split('/'), Client.InventoryStore.RootFolder);
found = Client.InventoryStore.InventoryFromPath(target, Client.CurrentDirectory, true);
if (found.Count > 0)
{
InventoryBase item = found[0];

View File

@@ -31,25 +31,19 @@ namespace OpenMetaverse.TestClient.Commands.Inventory.Shell
string nl = "\n";
for (int i = 1; i < args.Length; ++i)
{
string inventoryName = args[i];
string itemPath = args[i];
if (Client.CurrentDirectory.IsStale)
List<InventoryBase> results = Inventory.InventoryFromPath(itemPath, Client.CurrentDirectory, true);
if (results.Count == 0)
{
Client.CurrentDirectory.DownloadContents(TimeSpan.FromSeconds(30));
ret += "No inventory item at " + itemPath + " found." + nl;
}
bool found = false;
foreach (InventoryBase b in Client.CurrentDirectory) {
string name = b.Name;
if (inventoryName == name || inventoryName == b.UUID.ToString())
{
found = true;
b.Give(dest, true);
ret += "Gave " + name + nl;
}
else
{
results[0].Give(dest, true);
ret += "Gave " + results[0].Name + nl;
}
if (!found)
ret += "No inventory item named " + inventoryName + " found." + nl;
}
return ret;
}

View File

@@ -17,22 +17,49 @@ namespace OpenMetaverse.TestClient.Commands.Inventory.Shell
}
public override string Execute(string[] args, UUID fromAgentID)
{
if (args.Length > 1)
return "Usage: ls [-l]";
bool longDisplay = false;
if (args.Length > 0 && args[0] == "-l")
longDisplay = true;
Manager = Client.Inventory;
Inventory = Client.InventoryStore;
if (args.Length > 1)
return "Usage: ls [-l] [directory path]";
bool longDisplay = false;
InventoryFolder directory = Client.CurrentDirectory;
if (args.Length > 0)
{
int start = 0;
if (args[0] == "-l")
{
longDisplay = true;
start = 1;
}
if (start < args.Length)
{
string path = args[start];
for (int i = start + 1; i < args.Length; ++i)
{
path += " " + args[i];
}
bool found = false;
List<InventoryBase> results = Inventory.InventoryFromPath(path, Client.CurrentDirectory, true);
foreach (InventoryBase ib in results)
{
if (ib is InventoryFolder)
{
directory = ib as InventoryFolder;
found = true;
}
}
if (!found)
return "Unable to find directory at path: " + path;
}
}
if (Client.CurrentDirectory.IsStale)
Client.CurrentDirectory.DownloadContents(TimeSpan.FromSeconds(30));
if (directory.IsStale)
directory.DownloadContents(TimeSpan.FromSeconds(30));
string displayString = "";
string nl = "\n"; // New line character
// Pretty simple, just print out the contents.
foreach (InventoryBase b in Client.CurrentDirectory)
foreach (InventoryBase b in directory)
{
if (longDisplay)
{