public void PasteTo(TreeNode pasteNode) { if (clipNode == null) return; InventoryBase pasteio = (InventoryBase)pasteNode.Tag; if (clipItem is InventoryFolder) { InventoryFolder folder = (InventoryFolder)clipItem; if (cut) { if (pasteio is InventoryFolder) { client.Inventory.MoveFolder(folder.UUID, pasteio.UUID); pasteNode.Nodes.Add(clipNode); } else if (pasteio is InventoryItem) { client.Inventory.MoveFolder(folder.UUID, pasteio.ParentUUID); pasteNode.Parent.Nodes.Add(clipNode); } clipNode.EnsureVisible(); clipNode = null; clipItem = null; } else { //TODO: handle copying } } else if (clipItem is InventoryItem) { InventoryItem item = (InventoryItem)clipItem; if (cut) { if (pasteio is InventoryFolder) { client.Inventory.MoveItem(item.UUID, pasteio.UUID); pasteNode.Nodes.Add(clipNode); } else if (pasteio is InventoryItem) { client.Inventory.MoveItem(item.UUID, pasteio.ParentUUID); pasteNode.Parent.Nodes.Add(clipNode); } clipNode.EnsureVisible(); clipNode = null; clipItem = null; } else { //TODO: handle copying } } }
public InventoryNode(InventoryBase data, InventoryNode parent) { this.data = data; this.parent = parent; if (parent != null) { // Add this node to the collection of parent nodes lock (parent.Nodes.SyncRoot) parent.Nodes.Add(data.UUID, this); } }
public int CompareNodes(InventoryBase x, InventoryBase y, TreeNode nodeX, TreeNode nodeY) { int returnVal = 0; if ((x is InventoryItem && y is InventoryItem) || (x is InventoryFolder && y is InventoryFolder)) { returnVal = nodeX.Text.CompareTo(nodeY.Text); } else if (x is InventoryFolder && y is InventoryItem) returnVal = -1; else if (x is InventoryItem && y is InventoryFolder) returnVal = 1; return returnVal; }
public int CompareNodes(InventoryBase x, InventoryBase y, TreeNode nodeX, TreeNode nodeY) { int returnVal = 0; if (x is InventoryItem && y is InventoryItem) { InventoryItem itemX = (InventoryItem)x; InventoryItem itemY = (InventoryItem)y; returnVal = -itemX.CreationDate.CompareTo(itemY.CreationDate); } else if (x is InventoryFolder && y is InventoryFolder) returnVal = nodeX.Text.CompareTo(nodeY.Text); else if (x is InventoryFolder && y is InventoryItem) returnVal = -1; else if (x is InventoryItem && y is InventoryFolder) returnVal = 1; return returnVal; }
/// <summary> /// /// </summary> /// <param name="data"></param> public InventoryNode(InventoryBase data) { this.data = data; }
protected void FireOnInventoryObjectRemoved(InventoryBase obj) { if (OnInventoryObjectRemoved != null) { try { OnInventoryObjectRemoved(obj); } catch (Exception e) { Client.Log(e.ToString(), Helpers.LogLevel.Error); } } }
protected void FireOnInventoryObjectUpdated(InventoryBase oldObject, InventoryBase newObject) { if (OnInventoryObjectUpdated != null) { try { OnInventoryObjectUpdated(oldObject, newObject); } catch (Exception e) { Client.Log(e.ToString(), Helpers.LogLevel.Error); } } }
public bool Contains(InventoryBase obj) { return Contains(obj.UUID); }
public void SetClipboardNode(TreeNode itemNode, bool cut) { clipNode = itemNode; clipItem = (InventoryBase)itemNode.Tag; this.cut = cut; if (cut) { if (clipNode.Parent.Nodes.Count == 1) clipNode.Parent.Collapse(); clipNode.Remove(); } }
public override bool Equals(InventoryBase o) { InventoryFolder folder = o as InventoryFolder; return folder != null && Equals(folder); }
/// <summary> /// Take an object /// </summary> /// <param name="io">InventoryBase</param> private void DownloadInventoryBase(InventoryBase io) { if (io is InventoryFolder) { InventoryFolder folder = (InventoryFolder)io; List<InventoryBase> folderContents = client.Inventory.Store.GetContents(folder); if (folderContents.Count > 0) { CurrentPath.Add(MIUtils.CleanForWriteandRead(folder.Name));//We found a new folder with something in it, keep a record of it foreach (InventoryBase subfolderObj in folderContents) { if (client.Network.Connected) DownloadInventoryBase(subfolderObj); else { //Let's make sure the user does not get froozen if we have sl network problems client.Log("[SLMIV] ERROR: Connection lost to grid; Aborting backup", Helpers.LogLevel.Error); return; } } //We are now out of this folder, so remove the last foldername from the treebranch CurrentPath.RemoveAt(CurrentPath.Count - 1); } treeView1.EndUpdate(); } else if (io is InventoryItem) { InventoryItem Iitem = (InventoryItem)io;//"lsl""snapshot""texture" //Now create the backup file in that dir if (Iitem.InventoryType == InventoryType.Notecard && chkNotecards.Checked == true) { DirectoryInfo dinfo = Directory.CreateDirectory(Common.backupRootFolder + "\\" + client.Self.Name + "\\" + CurrentPathToString()); RequestInventoryItem(Iitem); client.Log("[SLMIV] Received UUID: " + Iitem.UUID.ToStringHyphenated(), Helpers.LogLevel.Info); FileStream fs = File.Create(dinfo.FullName + "\\" + MIUtils.CleanForWriteandRead(Iitem.Name) + ".txt"); fs.Close(); File.WriteAllText(dinfo.FullName + "\\" + MIUtils.CleanForWriteandRead(Iitem.Name) + ".txt", Convert.ToString(notecardContent)); lbStatus.Text = "Created: " + dinfo.FullName + "\\" + MIUtils.CleanForWriteandRead(Iitem.Name) + ".txt"; AppendLineStatusBox(lbStatus.Text); //Write item's key and the image's file path into log file... Logs.ImageLogEntry(Iitem.UUID.ToStringHyphenated() + "," + (dinfo.FullName + "\\" + MIUtils.CleanForWriteandRead(Iitem.Name) + ".txt") + " # " + Iitem.Name, File.AppendText(Common.ImageLog)); } else if (Iitem.InventoryType == InventoryType.LSL && chkScripts.Checked == true) { DirectoryInfo dinfo = Directory.CreateDirectory(Common.backupRootFolder + "\\" + client.Self.Name + "\\" + CurrentPathToString()); RequestInventoryItem(Iitem); client.Log("[SLMIV] Received UUID: " + Iitem.UUID.ToStringHyphenated(), Helpers.LogLevel.Info); FileStream fs = File.Create(dinfo.FullName + "\\" + MIUtils.CleanForWriteandRead(Iitem.Name) + ".lsl"); fs.Close(); File.WriteAllText(dinfo.FullName + "\\" + MIUtils.CleanForWriteandRead(Iitem.Name) + ".lsl", Convert.ToString(notecardContent)); lbStatus.Text = "Created: " + dinfo.FullName + "\\" + MIUtils.CleanForWriteandRead(Iitem.Name) + ".lsl"; AppendLineStatusBox(lbStatus.Text); //Write item's key and the image's file path into log file... Logs.ImageLogEntry(Iitem.UUID.ToStringHyphenated() + "," + (dinfo.FullName + "\\" + MIUtils.CleanForWriteandRead(Iitem.Name) + ".lsl") + " # " + Iitem.Name, File.AppendText(Common.ImageLog)); } else if ((Iitem.InventoryType == InventoryType.Snapshot && chkPhotoAlbum.Checked == true) || (Iitem.InventoryType == InventoryType.Texture && chkPhotoAlbum.Checked == true)) { if (Iitem.ParentUUID == PhotoAlbumUUID) { DirectoryInfo dinfo = Directory.CreateDirectory(Common.backupRootFolder + "\\" + client.Self.Name + "\\My Inventory\\Photo Album"); string newfilepath = dinfo.FullName + "\\" + MIUtils.CleanForWriteandRead(Iitem.Name) + ".jpg"; Console.WriteLine("[SLMIV]:DownloadInventoryBase: Queued Snapshot {0}", Iitem.Name);//Debug lbStatus.Text = ("Queued Snapshot: " + Iitem.Name); AppendLineStatusBox(lbStatus.Text); //Don't add duplicates, RequestImage() does not like it QueuedDownloadInfo imageQDI = new QueuedDownloadInfo(newfilepath, Iitem); if (!PendingImageDownloads.Contains(imageQDI)) PendingImageDownloads.Enqueue(imageQDI); //Write item's key and the image's file path into log file... Logs.ImageLogEntry(Iitem.UUID.ToStringHyphenated() + "," + (newfilepath) + " # " + Iitem.Name, File.AppendText(Common.ImageLog)); } } if (Iitem.InventoryType == InventoryType.Texture && chkTextures.Checked == true) { //Do not duplicate Photo Album images if (Iitem.ParentUUID != PhotoAlbumUUID) { DirectoryInfo dinfo = Directory.CreateDirectory(Common.backupRootFolder + "\\" + client.Self.Name + "\\" + CurrentPathToString()); string newfilepath = dinfo.FullName + "\\" + MIUtils.CleanForWriteandRead(Iitem.Name) + ".jpg"; Console.WriteLine("[SLMIV]:DownloadInventoryBase: Queued Texture {0}", Iitem.Name);//Debug lbStatus.Text = ("Queued Texture: " + Iitem.Name); AppendLineStatusBox(lbStatus.Text); //Don't add duplicates, RequestImage() does not like it QueuedDownloadInfo imageQDI = new QueuedDownloadInfo(newfilepath, Iitem); if (!PendingImageDownloads.Contains(imageQDI)) PendingImageDownloads.Enqueue(imageQDI); //Write item's key and the image's file path into log file... Logs.ImageLogEntry(Iitem.UUID.ToStringHyphenated() + "," + (newfilepath) + " # " + Iitem.Name, File.AppendText(Common.ImageLog)); } } lbStatus.Update(); } }
/// <summary> /// Occurs when treeView1_AfterExpand is called. /// Processes an InventoryBase object into the treeView1 /// </summary> /// <param name="io"></param> private void ProcessIncomingObject(InventoryBase io) { if (io is InventoryFolder) { InventoryFolder folder = (InventoryFolder)io; TreeNode node = treeLookup[folder.UUID]; treeView1.BeginUpdate(); node.Nodes.Clear(); List<InventoryBase> folderContents = client.Inventory.Store.GetContents(folder); if (folderContents.Count > 0) { ProcessInventoryItems(folderContents, node); //treeView1.Sort(); if (!node.IsVisible) { node.LastNode.EnsureVisible(); node.EnsureVisible(); } } treeView1.EndUpdate(); } else if (io is InventoryItem) { InventoryItem item = (InventoryItem)io; TreeNode node = treeLookup[item.ParentUUID]; treeView1.BeginUpdate(); TreeNode itemNode = AddTreeItem(item, node); //treeView1.Sort(); if (!itemNode.IsVisible) { if (node.IsExpanded) { node.LastNode.EnsureVisible(); itemNode.EnsureVisible(); } } treeView1.EndUpdate(); } }
protected void FireOnInventoryObjectAdded(InventoryBase obj) { if (OnInventoryObjectAdded != null) { try { OnInventoryObjectAdded(obj); } catch (Exception e) { Logger.Log(e.Message, Helpers.LogLevel.Error, Client, e); } } }
protected void FireOnInventoryObjectUpdated(InventoryBase oldObject, InventoryBase newObject) { if (OnInventoryObjectUpdated != null) { try { OnInventoryObjectUpdated(oldObject, newObject); } catch (Exception e) { Logger.Log(e.Message, Helpers.LogLevel.Error, Client, e); } } }
public virtual bool Equals(InventoryBase o) { return o.UUID == UUID && o.ParentUUID == ParentUUID && o.Name == Name && o.OwnerID == OwnerID; }
public override bool Equals(InventoryBase o) { InventoryItem item = o as InventoryItem; return item != null && Equals(item); }
/// <summary> /// Updates the state of the InventoryNode and inventory data structure that /// is responsible for the InventoryObject. If the item was previously not added to inventory, /// it adds the item, and updates structure accordingly. If it was, it updates the /// InventoryNode, changing the parent node if <code>item.parentUUID</code> does /// not match <code>node.Parent.Data.UUID</code>. /// /// You can not set the inventory root folder using this method /// </summary> /// <param name="item">The InventoryObject to store</param> public void UpdateNodeFor(InventoryBase item) { lock (Items) { InventoryNode itemParent = null; if (item.ParentUUID != LLUUID.Zero && !Items.TryGetValue(item.ParentUUID, out itemParent)) { // OK, we have no data on the parent, let's create a fake one. InventoryFolder fakeParent = new InventoryFolder(item.ParentUUID); fakeParent.DescendentCount = 1; // Dear god, please forgive me. itemParent = new InventoryNode(fakeParent); Items[item.ParentUUID] = itemParent; // Unfortunately, this breaks the nice unified tree // while we're waiting for the parent's data to come in. // As soon as we get the parent, the tree repairs itself. Client.DebugLog("Attempting to update inventory child of " + item.ParentUUID.ToString() + " when we have no local reference to that folder"); if (Client.Settings.FETCH_MISSING_INVENTORY) { // Fetch the parent List<LLUUID> fetchreq = new List<LLUUID>(1); fetchreq.Add(item.ParentUUID); //Manager.FetchInventory(fetchreq); // we cant fetch folder data! :-O } } InventoryNode itemNode; if (Items.TryGetValue(item.UUID, out itemNode)) // We're updating. { InventoryNode oldParent = itemNode.Parent; // Handle parent change if (oldParent == null || itemParent == null || itemParent.Data.UUID != oldParent.Data.UUID) { if (oldParent != null) { lock (oldParent.Nodes.SyncRoot) oldParent.Nodes.Remove(item.UUID); } if (itemParent != null) { lock (itemParent.Nodes.SyncRoot) itemParent.Nodes[item.UUID] = itemNode; } } itemNode.Parent = itemParent; if (item != itemNode.Data) FireOnInventoryObjectUpdated(itemNode.Data, item); itemNode.Data = item; } else // We're adding. { itemNode = new InventoryNode(item, itemParent); Items.Add(item.UUID, itemNode); } } }
public void Move(InventoryBase item, InventoryFolder newParent) { if (item is InventoryFolder) MoveFolder(item.UUID, newParent.UUID); else MoveItem(item.UUID, newParent.UUID); }
/// <summary> /// Removes the InventoryObject and all related node data from Inventory. /// </summary> /// <param name="item">The InventoryObject to remove.</param> public void RemoveNodeFor(InventoryBase item) { lock (Items) { InventoryNode node; if (Items.TryGetValue(item.UUID, out node)) { if (node.Parent != null) lock (node.Parent.Nodes.SyncRoot) node.Parent.Nodes.Remove(item.UUID); Items.Remove(item.UUID); FireOnInventoryObjectRemoved(item); } // In case there's a new parent: InventoryNode newParent; if (Items.TryGetValue(item.ParentUUID, out newParent)) { lock (newParent.Nodes.SyncRoot) newParent.Nodes.Remove(item.UUID); } } }