aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services/HypergridService
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Services/HypergridService')
-rw-r--r--OpenSim/Services/HypergridService/HGSuitcaseInventoryService.cs594
1 files changed, 0 insertions, 594 deletions
diff --git a/OpenSim/Services/HypergridService/HGSuitcaseInventoryService.cs b/OpenSim/Services/HypergridService/HGSuitcaseInventoryService.cs
index e65ad17..b6ec558 100644
--- a/OpenSim/Services/HypergridService/HGSuitcaseInventoryService.cs
+++ b/OpenSim/Services/HypergridService/HGSuitcaseInventoryService.cs
@@ -48,600 +48,6 @@ namespace OpenSim.Services.HypergridService
48 /// and it responds to GetRootFolder requests with the ID of the 48 /// and it responds to GetRootFolder requests with the ID of the
49 /// Suitcase folder, not the actual "My Inventory" folder. 49 /// Suitcase folder, not the actual "My Inventory" folder.
50 /// </summary> 50 /// </summary>
51 public class HGSuitcaseInventoryService1 : XInventoryService, IInventoryService
52 {
53 private static readonly ILog m_log =
54 LogManager.GetLogger(
55 MethodBase.GetCurrentMethod().DeclaringType);
56
57 private string m_HomeURL;
58 private IUserAccountService m_UserAccountService;
59
60 private UserAccountCache m_Cache;
61
62 private ExpiringCache<UUID, List<XInventoryFolder>> m_SuitcaseTrees = new ExpiringCache<UUID,List<XInventoryFolder>>();
63
64 public HGSuitcaseInventoryService1(IConfigSource config, string configName)
65 : base(config, configName)
66 {
67 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Starting with config name {0}", configName);
68 if (configName != string.Empty)
69 m_ConfigName = configName;
70
71 if (m_Database == null)
72 m_log.WarnFormat("[XXX]: m_Database is null!");
73
74 //
75 // Try reading the [InventoryService] section, if it exists
76 //
77 IConfig invConfig = config.Configs[m_ConfigName];
78 if (invConfig != null)
79 {
80 // realm = authConfig.GetString("Realm", realm);
81 string userAccountsDll = invConfig.GetString("UserAccountsService", string.Empty);
82 if (userAccountsDll == string.Empty)
83 throw new Exception("Please specify UserAccountsService in HGInventoryService configuration");
84
85 Object[] args = new Object[] { config };
86 m_UserAccountService = ServerUtils.LoadPlugin<IUserAccountService>(userAccountsDll, args);
87 if (m_UserAccountService == null)
88 throw new Exception(String.Format("Unable to create UserAccountService from {0}", userAccountsDll));
89
90 // legacy configuration [obsolete]
91 m_HomeURL = invConfig.GetString("ProfileServerURI", string.Empty);
92 // Preferred
93 m_HomeURL = invConfig.GetString("HomeURI", m_HomeURL);
94
95 m_Cache = UserAccountCache.CreateUserAccountCache(m_UserAccountService);
96 }
97
98 m_log.Debug("[HG SUITCASE INVENTORY SERVICE]: Starting...");
99 }
100
101 public override bool CreateUserInventory(UUID principalID)
102 {
103 // NOGO
104 return false;
105 }
106
107 public override List<InventoryFolderBase> GetInventorySkeleton(UUID principalID)
108 {
109 XInventoryFolder suitcase = GetSuitcaseXFolder(principalID);
110 XInventoryFolder root = GetRootXFolder(principalID);
111
112 List<XInventoryFolder> tree = GetFolderTree(suitcase.folderID);
113 if (tree == null || (tree != null && tree.Count == 0))
114 return null;
115
116 List<InventoryFolderBase> folders = new List<InventoryFolderBase>();
117 foreach (XInventoryFolder x in tree)
118 {
119 if (x.parentFolderID == suitcase.folderID)
120 x.parentFolderID = root.folderID;
121
122 folders.Add(ConvertToOpenSim(x));
123 }
124
125 SetAsRootFolder(suitcase, root);
126 folders.Add(ConvertToOpenSim(suitcase));
127
128 return folders;
129 }
130
131 public override InventoryCollection GetUserInventory(UUID userID)
132 {
133 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Get Suitcase inventory for user {0}", userID);
134 InventoryCollection userInventory = new InventoryCollection();
135 userInventory.UserID = userID;
136 userInventory.Folders = new List<InventoryFolderBase>();
137 userInventory.Items = new List<InventoryItemBase>();
138
139 XInventoryFolder suitcase = GetSuitcaseXFolder(userID);
140 XInventoryFolder root = GetRootXFolder(userID);
141
142 List<XInventoryFolder> tree = GetFolderTree(suitcase.folderID);
143 if (tree == null || (tree != null && tree.Count == 0))
144 {
145 SetAsRootFolder(suitcase, root);
146 userInventory.Folders.Add(ConvertToOpenSim(suitcase));
147 return userInventory;
148 }
149
150 List<InventoryItemBase> items;
151 foreach (XInventoryFolder f in tree)
152 {
153 // Add the items of this subfolder
154 items = GetFolderItems(userID, f.folderID);
155 if (items != null && items.Count > 0)
156 {
157 userInventory.Items.AddRange(items);
158 }
159
160 // Add the folder itself
161 if (f.parentFolderID == suitcase.folderID)
162 f.parentFolderID = root.folderID;
163 userInventory.Folders.Add(ConvertToOpenSim(f));
164 }
165
166 items = GetFolderItems(userID, suitcase.folderID);
167 if (items != null && items.Count > 0)
168 {
169 foreach (InventoryItemBase i in items)
170 i.Folder = root.folderID;
171 userInventory.Items.AddRange(items);
172 }
173
174 SetAsRootFolder(suitcase, root);
175 userInventory.Folders.Add(ConvertToOpenSim(suitcase));
176
177 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: GetUserInventory for user {0} returning {1} folders and {2} items",
178 userID, userInventory.Folders.Count, userInventory.Items.Count);
179 return userInventory;
180 }
181
182 public override InventoryFolderBase GetRootFolder(UUID principalID)
183 {
184 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: GetRootFolder for {0}", principalID);
185 if (m_Database == null)
186 m_log.ErrorFormat("[XXX]: m_Database is NULL!");
187
188 // Let's find out the local root folder
189 XInventoryFolder root = GetRootXFolder(principalID); ;
190 if (root == null)
191 {
192 m_log.WarnFormat("[HG SUITCASE INVENTORY SERVICE]: Unable to retrieve local root folder for user {0}", principalID);
193 }
194
195 // Warp! Root folder for travelers is the suitcase folder
196 XInventoryFolder suitcase = GetSuitcaseXFolder(principalID);
197
198 if (suitcase == null)
199 {
200 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: User {0} does not have a Suitcase folder. Creating it...", principalID);
201 // make one, and let's add it to the user's inventory as a direct child of the root folder
202 // In the DB we tag it as type 100, but we use -1 (Unknown) outside
203 suitcase = CreateFolder(principalID, root.folderID, 100, "My Suitcase");
204 if (suitcase == null)
205 m_log.ErrorFormat("[HG SUITCASE INVENTORY SERVICE]: Unable to create suitcase folder");
206 suitcase.version = root.version;
207 m_Database.StoreFolder(suitcase);
208
209 // Create System folders
210 CreateSystemFolders(principalID, suitcase.folderID);
211 }
212 else if (suitcase.version < root.version)
213 {
214 suitcase.version = root.version;
215 m_Database.StoreFolder(suitcase);
216 }
217
218 // Now let's change the folder ID to match that of the real root folder
219 SetAsRootFolder(suitcase, root);
220
221 return ConvertToOpenSim(suitcase);
222 }
223
224 protected void CreateSystemFolders(UUID principalID, UUID rootID)
225 {
226 m_log.Debug("[HG SUITCASE INVENTORY SERVICE]: Creating System folders under Suitcase...");
227 XInventoryFolder[] sysFolders = GetSystemFolders(principalID, rootID);
228
229 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Animation) return true; return false; }))
230 CreateFolder(principalID, rootID, (int)AssetType.Animation, "Animations");
231 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Bodypart) return true; return false; }))
232 CreateFolder(principalID, rootID, (int)AssetType.Bodypart, "Body Parts");
233 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.CallingCard) return true; return false; }))
234 CreateFolder(principalID, rootID, (int)AssetType.CallingCard, "Calling Cards");
235 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Clothing) return true; return false; }))
236 CreateFolder(principalID, rootID, (int)AssetType.Clothing, "Clothing");
237 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Gesture) return true; return false; }))
238 CreateFolder(principalID, rootID, (int)AssetType.Gesture, "Gestures");
239 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Landmark) return true; return false; }))
240 CreateFolder(principalID, rootID, (int)AssetType.Landmark, "Landmarks");
241 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.LostAndFoundFolder) return true; return false; }))
242 CreateFolder(principalID, rootID, (int)AssetType.LostAndFoundFolder, "Lost And Found");
243 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Notecard) return true; return false; }))
244 CreateFolder(principalID, rootID, (int)AssetType.Notecard, "Notecards");
245 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Object) return true; return false; }))
246 CreateFolder(principalID, rootID, (int)AssetType.Object, "Objects");
247 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.SnapshotFolder) return true; return false; }))
248 CreateFolder(principalID, rootID, (int)AssetType.SnapshotFolder, "Photo Album");
249 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.LSLText) return true; return false; }))
250 CreateFolder(principalID, rootID, (int)AssetType.LSLText, "Scripts");
251 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Sound) return true; return false; }))
252 CreateFolder(principalID, rootID, (int)AssetType.Sound, "Sounds");
253 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Texture) return true; return false; }))
254 CreateFolder(principalID, rootID, (int)AssetType.Texture, "Textures");
255 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.TrashFolder) return true; return false; }))
256 CreateFolder(principalID, rootID, (int)AssetType.TrashFolder, "Trash");
257 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.FavoriteFolder) return true; return false; }))
258 CreateFolder(principalID, rootID, (int)AssetType.FavoriteFolder, "Favorites");
259 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.CurrentOutfitFolder) return true; return false; }))
260 CreateFolder(principalID, rootID, (int)AssetType.CurrentOutfitFolder, "Current Outfit");
261
262 }
263
264 public override InventoryFolderBase GetFolderForType(UUID principalID, AssetType type)
265 {
266 //m_log.DebugFormat("[HG INVENTORY SERVICE]: GetFolderForType for {0} {0}", principalID, type);
267 XInventoryFolder suitcase = GetSuitcaseXFolder(principalID);
268 XInventoryFolder[] folders = m_Database.GetFolders(
269 new string[] { "agentID", "type", "parentFolderID"},
270 new string[] { principalID.ToString(), ((int)type).ToString(), suitcase.folderID.ToString() });
271
272 if (folders.Length == 0)
273 {
274 m_log.WarnFormat("[HG SUITCASE INVENTORY SERVICE]: Found no folder for type {0} for user {1}", type, principalID);
275 return null;
276 }
277
278 m_log.DebugFormat(
279 "[HG SUITCASE INVENTORY SERVICE]: Found folder {0} {1} for type {2} for user {3}",
280 folders[0].folderName, folders[0].folderID, type, principalID);
281
282 return ConvertToOpenSim(folders[0]);
283 }
284
285 public override InventoryCollection GetFolderContent(UUID principalID, UUID folderID)
286 {
287 InventoryCollection coll = null;
288 XInventoryFolder suitcase = GetSuitcaseXFolder(principalID);
289 XInventoryFolder root = GetRootXFolder(principalID);
290
291 if (!IsWithinSuitcaseTree(folderID, root, suitcase))
292 return new InventoryCollection();
293
294 if (folderID == root.folderID) // someone's asking for the root folder, we'll give them the suitcase
295 {
296 if (suitcase != null)
297 {
298 coll = base.GetFolderContent(principalID, suitcase.folderID);
299 foreach (InventoryFolderBase f in coll.Folders)
300 f.ParentID = root.folderID;
301 foreach (InventoryItemBase i in coll.Items)
302 i.Folder = root.folderID;
303 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: GetFolderContent for root folder returned content for suitcase folder");
304 }
305 }
306 else
307 {
308 coll = base.GetFolderContent(principalID, folderID);
309 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: GetFolderContent for non-root folder {0}", folderID);
310 }
311 if (coll == null)
312 {
313 m_log.WarnFormat("[HG SUITCASE INVENTORY SERVICE]: Something wrong with user {0}'s suitcase folder", principalID);
314 coll = new InventoryCollection();
315 }
316 return coll;
317 }
318
319 public override List<InventoryItemBase> GetFolderItems(UUID principalID, UUID folderID)
320 {
321 // Let's do a bit of sanity checking, more than the base service does
322 // make sure the given folder exists under the suitcase tree of this user
323 XInventoryFolder root = GetRootXFolder(principalID);
324 XInventoryFolder suitcase = GetSuitcaseXFolder(principalID);
325
326 if (!IsWithinSuitcaseTree(folderID, root, suitcase))
327 return new List<InventoryItemBase>();
328
329 return base.GetFolderItems(principalID, folderID);
330 }
331
332 public override bool AddFolder(InventoryFolderBase folder)
333 {
334 m_log.WarnFormat("[HG SUITCASE INVENTORY SERVICE]: AddFolder {0} {1}", folder.Name, folder.ParentID);
335 // Let's do a bit of sanity checking, more than the base service does
336 // make sure the given folder's parent folder exists under the suitcase tree of this user
337 XInventoryFolder root = GetRootXFolder(folder.Owner);
338 XInventoryFolder suitcase = GetSuitcaseXFolder(folder.Owner);
339
340 if (!IsWithinSuitcaseTree(folder.ParentID, root, suitcase))
341 return false;
342
343 // OK, it's legit
344 // Check if it's under the Root folder directly
345 if (folder.ParentID == root.folderID)
346 {
347 // someone's trying to add a subfolder of the root folder, we'll add it to the suitcase instead
348 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: AddFolder for root folder for user {0}. Adding in suitcase instead", folder.Owner);
349 folder.ParentID = suitcase.folderID;
350 }
351
352 return base.AddFolder(folder);
353 }
354
355 public override bool UpdateFolder(InventoryFolderBase folder)
356 {
357 XInventoryFolder root = GetRootXFolder(folder.Owner);
358 XInventoryFolder suitcase = GetSuitcaseXFolder(folder.Owner);
359
360 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Update folder {0}, version {1}", folder.ID, folder.Version);
361 if (!IsWithinSuitcaseTree(folder.ID, root, suitcase))
362 {
363 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: folder {0} not within Suitcase tree", folder.Name);
364 return false;
365 }
366
367 if (folder.ID == root.folderID)
368 {
369 if (folder.Version <= suitcase.version)
370 {
371 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: version {0} <= suitcase version {1}. Ignoring.", folder.Version, suitcase.version);
372 return false;
373 }
374 if (folder.Version <= root.version)
375 {
376 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: version {0} <= root version {1}. Ignoring.", folder.Version, suitcase.version);
377 return false;
378 }
379 suitcase.version = root.version = folder.Version;
380 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Storing {0} type {1} version {2}", suitcase.folderName, suitcase.type, suitcase.version);
381 m_Database.StoreFolder(suitcase);
382 m_Database.StoreFolder(root);
383 }
384
385 // For all others
386 return base.UpdateFolder(folder);
387 }
388
389 public override bool MoveFolder(InventoryFolderBase folder)
390 {
391 XInventoryFolder root = GetRootXFolder(folder.Owner);
392 XInventoryFolder suitcase = GetSuitcaseXFolder(folder.Owner);
393
394 if (!IsWithinSuitcaseTree(folder.ID, root, suitcase) || !IsWithinSuitcaseTree(folder.ParentID, root, suitcase))
395 return false;
396
397 if (folder.ParentID == root.folderID)
398 {
399 // someone's trying to add a subfolder of the root folder, we'll add it to the suitcase instead
400 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: MoveFolder to root folder for user {0}. Moving it to suitcase instead", folder.Owner);
401 folder.ParentID = suitcase.folderID;
402 }
403
404 return base.MoveFolder(folder);
405 }
406
407 public override bool DeleteFolders(UUID principalID, List<UUID> folderIDs)
408 {
409 // NOGO
410 return false;
411 }
412
413 public override bool PurgeFolder(InventoryFolderBase folder)
414 {
415 // NOGO
416 return false;
417 }
418
419 public override bool AddItem(InventoryItemBase item)
420 {
421 // Let's do a bit of sanity checking, more than the base service does
422 // make sure the given folder's parent folder exists under the suitcase tree of this user
423 XInventoryFolder root = GetRootXFolder(item.Owner);
424 XInventoryFolder suitcase = GetSuitcaseXFolder(item.Owner);
425
426 if (!IsWithinSuitcaseTree(item.Folder, root, suitcase))
427 return false;
428
429 // OK, it's legit
430 // Check if it's under the Root folder directly
431 if (item.Folder == root.folderID)
432 {
433 // someone's trying to add a subfolder of the root folder, we'll add it to the suitcase instead
434 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: AddItem for root folder for user {0}. Adding in suitcase instead", item.Owner);
435 item.Folder = suitcase.folderID;
436 }
437
438 return base.AddItem(item);
439
440 }
441
442 public override bool UpdateItem(InventoryItemBase item)
443 {
444 XInventoryFolder root = GetRootXFolder(item.Owner);
445 XInventoryFolder suitcase = GetSuitcaseXFolder(item.Owner);
446
447 if (!IsWithinSuitcaseTree(item.Folder, root, suitcase))
448 return false;
449
450 return base.UpdateItem(item);
451 }
452
453 public override bool MoveItems(UUID principalID, List<InventoryItemBase> items)
454 {
455 // Principal is b0rked. *sigh*
456
457 XInventoryFolder root = GetRootXFolder(items[0].Owner);
458 XInventoryFolder suitcase = GetSuitcaseXFolder(items[0].Owner);
459
460 foreach (InventoryItemBase it in items)
461 if (it.Folder == root.folderID)
462 {
463 // someone's trying to add a subfolder of the root folder, we'll add it to the suitcase instead
464 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: MoveItem to root folder for user {0}. Moving it to suitcase instead", it.Owner);
465 it.Folder = suitcase.folderID;
466 }
467
468 if (!IsWithinSuitcaseTree(items[0].Folder, root, suitcase))
469 return false;
470
471 return base.MoveItems(principalID, items);
472
473 }
474
475 // Let these pass. Use inherited methods.
476 public override bool DeleteItems(UUID principalID, List<UUID> itemIDs)
477 {
478 return false;
479 }
480
481 public new InventoryItemBase GetItem(InventoryItemBase item)
482 {
483 InventoryItemBase it = base.GetItem(item);
484 if (it == null)
485 {
486 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Unable to retrieve item {0} ({1}) in folder {2}",
487 item.Name, item.ID, item.Folder);
488 return null;
489 }
490 XInventoryFolder root = GetRootXFolder(it.Owner);
491 XInventoryFolder suitcase = GetSuitcaseXFolder(it.Owner);
492 if (root == null || suitcase == null)
493 {
494 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Root or Suitcase are null for user {0}",
495 it.Owner);
496 return null;
497 }
498
499 if (it.Folder == suitcase.folderID)
500 it.Folder = root.folderID;
501
502 if (!IsWithinSuitcaseTree(it.Folder, root, suitcase))
503 {
504 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Item {0} (folder {1}) is not within Suitcase",
505 it.Name, it.Folder);
506 return null;
507 }
508
509 // UserAccount user = m_Cache.GetUser(it.CreatorId);
510
511 // // Adjust the creator data
512 // if (user != null && it != null && (it.CreatorData == null || it.CreatorData == string.Empty))
513 // it.CreatorData = m_HomeURL + ";" + user.FirstName + " " + user.LastName;
514 //}
515
516 return it;
517 }
518
519 public new InventoryFolderBase GetFolder(InventoryFolderBase folder)
520 {
521 InventoryFolderBase f = base.GetFolder(folder);
522
523 if (f != null)
524 {
525 XInventoryFolder root = GetRootXFolder(f.Owner);
526 XInventoryFolder suitcase = GetSuitcaseXFolder(f.Owner);
527 if (f.ParentID == suitcase.folderID)
528 f.ParentID = root.folderID;
529
530 if (!IsWithinSuitcaseTree(f.ID, root, suitcase))
531 return null;
532 }
533
534 return f;
535 }
536
537 //public List<InventoryItemBase> GetActiveGestures(UUID principalID)
538 //{
539 //}
540
541 //public int GetAssetPermissions(UUID principalID, UUID assetID)
542 //{
543 //}
544
545 #region Auxiliary functions
546 private XInventoryFolder GetXFolder(UUID userID, UUID folderID)
547 {
548 XInventoryFolder[] folders = m_Database.GetFolders(
549 new string[] { "agentID", "folderID" },
550 new string[] { userID.ToString(), folderID.ToString() });
551
552 if (folders.Length == 0)
553 return null;
554
555 return folders[0];
556 }
557
558 private XInventoryFolder GetRootXFolder(UUID principalID)
559 {
560 XInventoryFolder[] folders = m_Database.GetFolders(
561 new string[] { "agentID", "folderName", "type" },
562 new string[] { principalID.ToString(), "My Inventory", ((int)AssetType.RootFolder).ToString() });
563
564 if (folders != null && folders.Length > 0)
565 return folders[0];
566 return null;
567 }
568
569 private XInventoryFolder GetSuitcaseXFolder(UUID principalID)
570 {
571 // Warp! Root folder for travelers
572 XInventoryFolder[] folders = m_Database.GetFolders(
573 new string[] { "agentID", "type" },
574 new string[] { principalID.ToString(), "100" }); // This is a special folder type...
575
576 if (folders != null && folders.Length > 0)
577 return folders[0];
578 return null;
579 }
580
581 private void SetAsRootFolder(XInventoryFolder suitcase, XInventoryFolder root)
582 {
583 suitcase.version = root.version;
584 suitcase.folderID = root.folderID;
585 suitcase.parentFolderID = UUID.Zero;
586 suitcase.type = (short)AssetType.Folder;
587 }
588
589 private List<XInventoryFolder> GetFolderTree(UUID folder)
590 {
591 List<XInventoryFolder> t = null;
592 if (m_SuitcaseTrees.TryGetValue(folder, out t))
593 return t;
594
595 t = GetFolderTreeRecursive(folder);
596 m_SuitcaseTrees.AddOrUpdate(folder, t, 120);
597 return t;
598 }
599
600 private List<XInventoryFolder> GetFolderTreeRecursive(UUID root)
601 {
602 List<XInventoryFolder> tree = new List<XInventoryFolder>();
603 XInventoryFolder[] folders = m_Database.GetFolders(
604 new string[] { "parentFolderID" },
605 new string[] { root.ToString() });
606
607 if (folders == null || (folders != null && folders.Length == 0))
608 return tree; // empty tree
609 else
610 {
611 foreach (XInventoryFolder f in folders)
612 {
613 tree.Add(f);
614 tree.AddRange(GetFolderTreeRecursive(f.folderID));
615 }
616 return tree;
617 }
618
619 }
620
621 /// <summary>
622 /// Return true if the folderID is a subfolder of the Suitcase or the root folder ID itself
623 /// </summary>
624 /// <param name="folderID"></param>
625 /// <param name="root"></param>
626 /// <param name="suitcase"></param>
627 /// <returns></returns>
628 private bool IsWithinSuitcaseTree(UUID folderID, XInventoryFolder root, XInventoryFolder suitcase)
629 {
630 List<XInventoryFolder> tree = new List<XInventoryFolder>();
631 tree.Add(root); // Warp! the tree is the real root folder plus the children of the suitcase folder
632 tree.AddRange(GetFolderTree(suitcase.folderID));
633 XInventoryFolder f = tree.Find(delegate(XInventoryFolder fl)
634 {
635 if (fl.folderID == folderID) return true;
636 else return false;
637 });
638
639 if (f == null) return false;
640 else return true;
641 }
642 #endregion
643 }
644
645 public class HGSuitcaseInventoryService : XInventoryService, IInventoryService 51 public class HGSuitcaseInventoryService : XInventoryService, IInventoryService
646 { 52 {
647 private static readonly ILog m_log = 53 private static readonly ILog m_log =