Beispiel #1
0
        /// <summary>
        /// Replaces an entry within its parent's collection.
        /// </summary>
        /// <param name="document">The document being updated.</param>
        /// <param name="parent">The parent to update.</param>
        /// <param name="child">The entry to use as a replacement.</param>
        /// <param name="touchesNode">Whether to treat the swap as an "update" (vs a revert).</param>
        protected override void SwapIntoParent(KdbxDocument document, IKeePassGroup parent, IKeePassEntry child, bool touchesNode)
        {
            if (document == null)
            {
                throw new ArgumentNullException(nameof(document));
            }

            if (parent == null)
            {
                throw new ArgumentNullException(nameof(parent));
            }

            if (child == null)
            {
                throw new ArgumentNullException(nameof(child));
            }

            // Otherwise, we need to find the equivalent existing child (by UUID) and
            // update that way.
            IKeePassNode  matchedNode  = parent.Children.First(g => g.Uuid.Equals(child.Uuid));
            IKeePassEntry matchedEntry = matchedNode as IKeePassEntry;

            DebugHelper.Assert(matchedEntry != null);
            matchedEntry.SyncTo(child, touchesNode);
        }
Beispiel #2
0
        /// <summary>
        /// Attempts to locate a node in the tree given a parent from which to begin recursively searching.
        /// </summary>
        /// <param name="parent">The parent to use as a root.</param>
        /// <param name="encodedUuid">The Uuid to search for.</param>
        /// <returns>The node if found, else null.</returns>
        private static IKeePassNode FindNode(IKeePassGroup parent, string encodedUuid)
        {
            // Base case
            if (parent.Uuid.EncodedValue == encodedUuid)
            {
                return(parent);
            }

            foreach (IKeePassNode node in parent.Children)
            {
                if (node.Uuid.EncodedValue == encodedUuid)
                {
                    return(node);
                }

                // Recurse into child groups, depth first
                if (node is IKeePassGroup subGroup)
                {
                    IKeePassNode locatedNode = FindNode(subGroup, encodedUuid);
                    if (locatedNode != null)
                    {
                        return(locatedNode);
                    }
                }
            }

            return(null);
        }
Beispiel #3
0
        public bool HasDescendant(IKeePassNode node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            foreach (IKeePassEntry entry in Children)
            {
                if (entry.Uuid.Equals(node.Uuid))
                {
                    return(true);
                }
            }

            foreach (IKeePassGroup group in Children)
            {
                if (group.HasDescendant(node))
                {
                    return(true);
                }
            }

            return(false);
        }
Beispiel #4
0
        /// <summary>
        /// Replaces a group within its parent's collection.
        /// </summary>
        /// <param name="document">The document being updated.</param>
        /// <param name="parent">The parent to update.</param>
        /// <param name="child">The group to use as a replacement.</param>
        /// <param name="touchesNode">Whether to treat the swap as an "update" (vs a revert).</param>
        protected override void SwapIntoParent(KdbxDocument document, IKeePassGroup parent, IKeePassGroup child, bool touchesNode)
        {
            if (document == null)
            {
                throw new ArgumentNullException("document");
            }

            if (child == null)
            {
                throw new ArgumentNullException("child");
            }

            if (child.Parent != parent)
            {
                throw new ArgumentException("child.Parent != parent");
            }

            if (parent == null)
            {
                // If there is no parent, we are updating the root database group.
                // So, just update it.
                document.Root.DatabaseGroup.SyncTo(child, touchesNode);
            }
            else
            {
                // Otherwise, we need to find the equivalent existing child (by UUID) and
                // update that way.
                IKeePassNode  matchedNode  = parent.Children.First(node => node.Uuid.Equals(child.Uuid));
                IKeePassGroup matchedGroup = matchedNode as IKeePassGroup;
                DebugHelper.Assert(matchedGroup != null);
                matchedGroup.SyncTo(child, touchesNode);
            }
        }
Beispiel #5
0
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            IKeePassNode node = value as IKeePassNode;

            if (node != null)
            {
                FontFamily font = null;

                // Fallback based on the IconID
                switch (node.IconID)
                {
                case 3:     // Disk connected to LAN ("Network Server")
                case 5:     // Man with speech bubble ("UserCommunication")
                case 12:    // Wireless transmission thingy ("IR communication")
                case 22:    // Open notebook ("Paper New")
                case 24:    // Plug with lightning ("Energy careful")
                case 30:    // Console ("Console")
                case 42:    // RAM DIMM ("Memory")
                case 44:    // Sticky note with push pin ("Note")
                case 52:    // Square with closed padlock ("Paper locked")
                    font = new FontFamily("Segoe MDL2 Assets");
                    break;

                default:
                    font = new FontFamily("Segoe UI Symbol");
                    break;
                }

                return(font);
            }
            else
            {
                throw new ArgumentException("Value is not an IKeePassNode", nameof(value));
            }
        }
        /// <summary>
        /// Initializes the proxy.
        /// </summary>
        /// <param name="node"></param>
        /// <param name="readOnly">Whether the database is in a state that can be edited.</param>
        public DatabaseNodeViewModel(IKeePassNode node, bool readOnly = false)
        {
            Node = node ?? throw new ArgumentNullException(nameof(node));

            this.canEdit = () => !readOnly;

            RequestRenameCommand      = new ActionCommand(this.canEdit, FireRenameRequested);
            RequestEditDetailsCommand = new ActionCommand(this.canEdit, FireEditRequested);
            RequestDeleteCommand      = new ActionCommand(this.canEdit, FireDeleteRequested);
        }
Beispiel #7
0
        /// <summary>
        /// Attempts to locate the given node in the tree, and adopts it if possible.
        /// </summary>
        /// <param name="encodedUuid">The encoded Uuid of the node to adopt.</param>
        /// <returns>Whether adoption was successful.</returns>
        public bool TryAdopt(string encodedUuid)
        {
            if (!CanAdopt(encodedUuid))
            {
                throw new InvalidOperationException("A group cannot adopt itself or its ancestors.");
            }

            IKeePassNode adoptee = FindNode(FindRoot(), encodedUuid);

            if (adoptee == null)
            {
                return(false);
            }

            adoptee.Reparent(this);
            return(true);
        }
Beispiel #8
0
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            IKeePassNode node = value as IKeePassNode;

            if (node != null)
            {
                string icon = null;

                // Fallback based on the IconID
                switch (node.IconID)
                {
                case 0:     // Key ("Key")
                    icon = "\uE192";
                    break;

                case 1:     // Globe ("World")
                    icon = "\uE128";
                    break;

                case 2:     // Triangular hazard/warning ("Warning")
                    icon = "\u26A0";
                    break;

                case 3:              // Disk connected to LAN ("Network Server")
                    icon = "\uE968"; // MDL2 Assets
                    break;

                case 4:     // Folder with pinned note ("MarkedDirectory")
                    goto default;

                case 5:              // Man with speech bubble ("UserCommunication")
                    icon = "\uE939"; // MDL2 Assets
                    break;

                case 6:              // Three blocks (red green orange) in a triangle ("Parts")
                    icon = "\uE152"; // Three squares
                    break;

                case 7:                  // Notepad and pencil ("Notepad")
                    icon = "\U0001F4DD"; // 📝
                    break;

                case 8:          // Globe with red plug thing ("World Socket")
                    goto case 1; // Just a globe

                case 9:          // Contact card ("Identity")
                    icon = "\uE136";
                    break;

                case 10:     // Clipboard with green star ("Paper ready")
                    goto default;

                case 11:     // Camera ("Digicam")
                    icon = "\uE114";
                    break;

                case 12:             // Wireless transmission thingy ("IR communication")
                    icon = "\uE704"; // Tower broadcasting signal - MDL2 Assets
                    break;

                case 13:                 // Keychain ("Multikeys")
                    icon = "\U0001F510"; // 🔐
                    break;

                case 14:             // Power plug ("Energy")
                    icon = "\uE83E"; // Plugged in battery icon
                    break;

                case 15:     // Scanner
                    icon = "\uE8FE";
                    break;

                case 16:                 // Globe with red star ("World star")
                    goto case 1;         // Just a globe

                case 17:                 // Optical disc ("CDRom")
                    icon = "\U0001F5B8"; // 🖸
                    break;

                case 18:                 // Display/monitor ("Monitor")
                    icon = "\U0001F4FA"; // Television 📺
                    break;

                case 19:                 // Open envelope ("Email")
                    icon = "\U0001F4E7"; // 📧
                    break;

                case 20:     // Cog/gear ("Configuration")
                    icon = "\uE115";
                    break;

                case 21:             // Clipboard with checkmark ("Clipboard ready")
                    icon = "\uE133"; // List of checkmarks
                    break;

                case 22:             // Open notebook ("Paper New")
                    icon = "\uE8F4"; // Page with pencil and + - MDL2 Assets
                    break;

                case 23:             // Desktop ("Screen")
                    icon = "\uE1E4"; // Monitor with start screen tiles
                    break;

                case 24:             // Plug with lightning ("Energy careful")
                    icon = "\uE945"; // Lightning bolt - MDL2 Assets
                    break;

                case 25:                 // Folder with envelope ("EmailBox")
                    icon = "\U0001F4EC"; // 📬
                    break;

                case 26:     // Floppy disk ("Disk")
                    icon = "\uE105";
                    break;

                case 27:     // Device connected to LAN ("Drive")
                    icon = "\uE17B";
                    break;

                case 28:             // Quicktime logo ("PaperQ")
                    icon = "\uE173"; // Video icon
                    break;

                case 29:             // Green screen w/key ("Terminal encrypted")
                    icon = "\uE1A7"; // Rectangle with admin shield
                    break;

                case 30:             // Console ("Console")
                    icon = "\uE756"; // MDL2 Assets
                    break;

                case 31:     // Printer ("Printer")
                    icon = "\uE2F6";
                    break;

                case 32:     // Colored squares ("Program icons")
                    icon = "\uE138";
                    break;

                case 33:     // Red/white checkered flag ("Run")
                    goto default;

                case 34:     // Wrench ("Settings")
                    icon = "\uE15E";
                    break;

                case 35:     // PC with globe ("World computer")
                    goto default;

                case 36:     // WinZip icon ("Archive")
                    goto default;

                case 37:     // % sign ("Homebanking")
                    icon = "%";
                    break;

                case 38:             // Drive with Windows logo ("Drive windows")
                    icon = "\uE1E4"; // Monitor with start screen tiles
                    break;

                case 39:     // Clock ("Clock")
                    icon = "\uE2AD";
                    break;

                case 40:             // Envelope with magnifying glass ("Email search")
                    icon = "\uE721"; // Magnifying glass
                    break;

                case 41:     // Weird white square with red thing ("Paper flag")
                    goto default;

                case 42:             // RAM DIMM ("Memory")
                    icon = "\uE88E"; // Flash drive - MDL2 Assets
                    break;

                case 43:     // Recycling bin / trash can ("Trash bin")
                    icon = "\uE107";
                    break;

                case 44:             // Sticky note with push pin ("Note")
                    icon = "\uE840"; // Push pin
                    break;

                case 45:     // Red X ("Expired")
                    icon = "\uE10A";
                    break;

                case 46:             // Circled question mark (blue) ("Info")
                    icon = "\uE11B"; // Stylized question mark
                    break;

                case 47:                 // Box ("Package")
                    icon = "\U0001F4E6"; // 📦
                    break;

                case 48:                 // Closed folder ("Folder")
                    icon = "\U0001F4C1"; // 📁
                    break;

                case 49:                 // Open folder ("Folder open")
                    icon = "\U0001F4C2"; // 📂
                    break;

                case 50:     // Folder with yellow box ("Folder package")
                    goto default;

                case 51:     // Open padlock ("Lock open")
                    icon = "\uE1F7";
                    break;

                case 52:             // Square with closed padlock ("Paper locked")
                    icon = "\uE755"; // Closed padlock on document - MDL2 Assets
                    break;

                case 53:     // Green checkmark ("Checked")
                    icon = "\uE10B";
                    break;

                case 54:                 // Fountain pen ("Pen")
                    icon = "\U0001F58B"; // 🖋
                    break;

                case 55:                 // Photograph ("Thumbnail")
                    icon = "\U0001F5BB"; // 🖻
                    break;

                case 56:                 // Open book ("Book")
                    icon = "\U0001F4D6"; // 📖
                    break;

                case 57:     // List of details ("List")
                    icon = "\uE179";
                    break;

                case 58:     // Man with key ("User key")
                    goto default;

                case 59:                 // Hammer ("Tool")
                    icon = "\U0001F528"; // 🔨
                    break;

                case 60:                 // House ("Home")
                    icon = "\U0001F3E0"; // 🏠
                    break;

                case 61:     // Yellow star ("Star")
                    icon = "\uE208";
                    break;

                case 62:                 // Penguin ("Tux")
                    icon = "\U0001F427"; // 🐧
                    break;

                case 63:     // Feather ("Feather")
                    goto default;

                case 64:                 // Apple ("Apple")
                    icon = "\U0001F34E"; // 🍎
                    break;

                case 65:     // Wikipedia logo ("Wiki")
                    icon = "W";
                    break;

                case 66:                 // $ sign ("Money")
                    icon = "\U0001F4B2"; // 💲
                    break;

                case 67:                 // Certificate ("Certificate")
                    icon = "\U0001F4DC"; // 📜 (scroll)
                    break;

                case 68:                 // Cellphone ("BlackBerry")
                    icon = "\U0001F4F1"; // 📱
                    break;

                default:
                    if (value is IKeePassEntry)
                    {
                        goto case KdbxEntry.DefaultIconId;
                    }
                    else if (value is IKeePassGroup)
                    {
                        goto case KdbxGroup.DefaultIconId;
                    }
                    break;
                }

                return(icon);
            }
            else
            {
                throw new ArgumentException("Value is not an IKeePassNode", nameof(value));
            }
        }
Beispiel #9
0
 public bool HasDescendant(IKeePassNode node)
 {
     throw new NotImplementedException();
 }
Beispiel #10
0
 public void RenameNodeAndSave(IKeePassNode node, string newName)
 {
     throw new NotImplementedException();
 }
Beispiel #11
0
 public void DeleteNodeAndSave(IKeePassNode node)
 {
     throw new NotImplementedException();
 }