Moving examples, mapgenerator, and VisualParamGenerator to Programs folder (SVN is seriously ruined still, don't check out yet)
git-svn-id: http://libopenmetaverse.googlecode.com/svn/trunk@1961 52acb1d6-8a22-11de-b505-999d5b087335
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using OpenMetaverse;
|
||||
|
||||
namespace OpenMetaverse.TestClient.Commands.Inventory.Shell
|
||||
{
|
||||
public class ChangeDirectoryCommand : Command
|
||||
{
|
||||
private InventoryManager Manager;
|
||||
private OpenMetaverse.Inventory Inventory;
|
||||
|
||||
public ChangeDirectoryCommand(TestClient client)
|
||||
{
|
||||
Name = "cd";
|
||||
Description = "Changes the current working inventory folder.";
|
||||
}
|
||||
public override string Execute(string[] args, LLUUID fromAgentID)
|
||||
{
|
||||
Manager = Client.Inventory;
|
||||
Inventory = Client.Inventory.Store;
|
||||
|
||||
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;
|
||||
|
||||
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 nextName = path[i];
|
||||
if (string.IsNullOrEmpty(nextName) || nextName == ".")
|
||||
continue; // Ignore '.' and blanks, stay in the current directory.
|
||||
if (nextName == ".." && currentFolder != Inventory.RootFolder)
|
||||
{
|
||||
// If we encounter .., move to the parent folder.
|
||||
currentFolder = Inventory[currentFolder.ParentUUID] as InventoryFolder;
|
||||
}
|
||||
else
|
||||
{
|
||||
List<InventoryBase> currentContents = Inventory.GetContents(currentFolder);
|
||||
// Try and find an InventoryBase with the corresponding name.
|
||||
bool found = false;
|
||||
foreach (InventoryBase item in currentContents)
|
||||
{
|
||||
// Allow lookup by UUID as well as name:
|
||||
if (item.Name == nextName || item.UUID.ToString() == nextName)
|
||||
{
|
||||
found = true;
|
||||
if (item is InventoryFolder)
|
||||
{
|
||||
currentFolder = item as InventoryFolder;
|
||||
}
|
||||
else
|
||||
{
|
||||
return item.Name + " is not a folder.";
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
return nextName + " not found in " + currentFolder.Name;
|
||||
}
|
||||
}
|
||||
Client.CurrentDirectory = currentFolder;
|
||||
return "Current folder: " + currentFolder.Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user