29 using System.Collections.Generic;
30 using System.Reflection;
34 using OpenSim.Framework;
35 using OpenSim.Services.Interfaces;
37 namespace OpenSim.
Region.CoreModules.
Avatar.Inventory.Archiver
42 public static class InventoryArchiveUtils
47 public static readonly
char ESCAPE_CHARACTER =
'\\';
50 public static readonly
char PATH_DELIMITER =
'/';
77 List<InventoryFolderBase> folders = FindFoldersByPath(inventoryService, userId, path);
79 if (folders.Count == 0)
110 if (null == startFolder)
113 List<InventoryFolderBase> folders = FindFoldersByPath(inventoryService, startFolder, path);
115 if (folders.Count == 0)
142 public static List<InventoryFolderBase> FindFoldersByPath(
147 if (null == rootFolder)
148 return new List<InventoryFolderBase>();
150 return FindFoldersByPath(inventoryService, rootFolder, path);
174 public static List<InventoryFolderBase> FindFoldersByPath(
177 List<InventoryFolderBase> foundFolders =
new List<InventoryFolderBase>();
179 if (path ==
string.Empty)
181 foundFolders.Add(startFolder);
187 if (path == PATH_DELIMITER.ToString())
189 foundFolders.Add(startFolder);
194 path = path.TrimStart(
new char[] { PATH_DELIMITER });
198 string[] components = SplitEscapedPath(path);
199 components[0] = UnescapePath(components[0]);
203 InventoryCollection contents = inventoryService.GetFolderContent(startFolder.Owner, startFolder.ID);
210 if (folder.
Name == components[0])
212 if (components.Length > 1)
213 foundFolders.AddRange(FindFoldersByPath(inventoryService, folder, components[1]));
215 foundFolders.Add(folder);
249 if (null == rootFolder)
252 return FindItemByPath(inventoryService, rootFolder, path);
274 List<InventoryItemBase> foundItems = FindItemsByPath(inventoryService, startFolder, path);
276 if (foundItems.Count != 0)
277 return foundItems[0];
282 public static List<InventoryItemBase> FindItemsByPath(
287 if (null == rootFolder)
288 return new List<InventoryItemBase>();
290 return FindItemsByPath(inventoryService, rootFolder, path);
309 public static List<InventoryItemBase> FindItemsByPath(
312 List<InventoryItemBase> foundItems =
new List<InventoryItemBase>();
315 path = path.TrimStart(
new char[] { PATH_DELIMITER });
317 string[] components = SplitEscapedPath(path);
318 components[0] = UnescapePath(components[0]);
322 if (components.Length == 1)
328 List<InventoryItemBase> items = inventoryService.GetFolderItems(startFolder.Owner, startFolder.ID);
336 if (item.
Name == components[0])
337 foundItems.Add(item);
344 InventoryCollection contents = inventoryService.GetFolderContent(startFolder.Owner, startFolder.ID);
348 if (folder.
Name == components[0])
349 foundItems.AddRange(FindItemsByPath(inventoryService, folder, components[1]));
365 public static string[] SplitEscapedPath(
string path)
369 bool singleEscapeChar =
false;
371 for (
int i = 0; i < path.Length; i++)
373 if (path[i] == ESCAPE_CHARACTER && !singleEscapeChar)
375 singleEscapeChar =
true;
379 if (PATH_DELIMITER == path[i] && !singleEscapeChar)
380 return new string[2] { path.Remove(i), path.Substring(i + 1) };
382 singleEscapeChar =
false;
387 return new string[1] { path };
395 public static string UnescapePath(
string path)
399 StringBuilder sb =
new StringBuilder();
401 bool singleEscapeChar =
false;
402 for (
int i = 0; i < path.Length; i++)
404 if (path[i] == ESCAPE_CHARACTER && !singleEscapeChar)
405 singleEscapeChar =
true;
407 singleEscapeChar =
false;
409 if (singleEscapeChar)
411 if (PATH_DELIMITER == path[i])
412 sb.Append(PATH_DELIMITER);
422 return sb.ToString();
432 public static string EscapeArchivePath(
string path)
435 return path.Replace(
"&",
"&").Replace(
"/",
"/");
443 public static string UnescapeArchivePath(
string path)
445 return path.Replace(
"/",
"/").Replace(
"&",
"&");
Inventory Item - contains all the properties associated with an individual inventory piece...
virtual string Name
The name of the node (64 characters or less)
List< InventoryFolderBase > Folders
Used to serialize a whole inventory for transfer over the network.