private void SrxpSearch(SearchParameters sp, PwObjectList <PwEntry> lResults,
                                IStatusLogger sl)
        {
            PwDatabase pd = new PwDatabase();

            pd.RootGroup = SrxpFilterCloneSelf(sp);

            Dictionary <PwUuid, bool> dResults = new Dictionary <PwUuid, bool>();

            XmlDocument       xd;
            XPathNodeIterator xpIt = XmlUtilEx.FindNodes(pd, sp.SearchString, sl, out xd);

            if ((sl != null) && !sl.SetProgress(98))
            {
                return;
            }

            while (xpIt.MoveNext())
            {
                if ((sl != null) && !sl.ContinueWork())
                {
                    return;
                }

                XPathNavigator xpNav = xpIt.Current.Clone();

                while (true)
                {
                    XPathNodeType nt = xpNav.NodeType;
                    if (nt == XPathNodeType.Root)
                    {
                        break;
                    }

                    if ((nt == XPathNodeType.Element) &&
                        (xpNav.Name == KdbxFile.ElemEntry))
                    {
                        SrxpAddResult(dResults, xpNav);
                        break;
                    }

                    if (!xpNav.MoveToParent())
                    {
                        Debug.Assert(false); break;
                    }
                }
            }

            EntryHandler eh = delegate(PwEntry pe)
            {
                if (dResults.ContainsKey(pe.Uuid))
                {
                    lResults.Add(pe);
                }
                return(true);
            };

            TraverseTree(TraversalMethod.PreOrder, null, eh);
            Debug.Assert(lResults.UCount == (uint)dResults.Count);
        }
Пример #2
0
        /// <summary>
        /// Finds all entries with a given group and tag (or multiple)
        /// </summary>
        /// <param name="sourceDb">Database to search for the entries.</param>
        /// <param name="groups">Groups to search for (multiple separated by ,).</param>
        /// <param name="tags">Tag to search for (multiple separated by ,).</param>
        /// <returns>A PwObjectList with all metching entries.</returns>
        private static PwObjectList <PwEntry> FindEntriesByGroupAndTag(PwDatabase sourceDb, string groups, string tags)
        {
            PwObjectList <PwEntry> entries = new PwObjectList <PwEntry>();

            // Tag and group export
            foreach (string group in groups.Split(',').Select(x => x.Trim()))
            {
                PwGroup groupToExport = sourceDb.RootGroup.GetFlatGroupList().FirstOrDefault(g => g.Name == group);

                if (groupToExport == null)
                {
                    throw new ArgumentException("No group with the name of the Group-Setting found.");
                }

                foreach (string tag in tags.Split(',').Select(x => x.Trim()))
                {
                    PwObjectList <PwEntry> tagEntries = new PwObjectList <PwEntry>();
                    groupToExport.FindEntriesByTag(tag, tagEntries, true);
                    // Prevent duplicated entries
                    IEnumerable <PwUuid> existingUuids = entries.Select(x => x.Uuid);
                    List <PwEntry>       entriesToAdd  = tagEntries.Where(x => !existingUuids.Contains(x.Uuid)).ToList();
                    entries.Add(entriesToAdd);
                }
            }

            return(entries);
        }
Пример #3
0
        private PwObjectList <PwEntry> GetRdpAccountEntries(PwGroup pwg)
        {
            // create PwObjectList and fill it with matching entries
            var rdpAccountEntries = new PwObjectList <PwEntry>();

            string re = string.Empty;

            if (_peSettings.CpIncludeDefaultRegex)
            {
                re = ".*(" + _config.CredPickerRegExPre + ").*(" + _config.CredPickerRegExPost + ").*";
            }

            foreach (string regex in _peSettings.CpRegExPatterns)
            {
                re += string.IsNullOrEmpty(re) ? string.Empty : "|";
                re += regex;
            }

            foreach (PwEntry pe in pwg.Entries)
            {
                string title  = pe.Strings.ReadSafe(PwDefs.TitleField);
                bool   ignore = Util.IsEntryIgnored(pe);

                if (!ignore && Regex.IsMatch(title, re, RegexOptions.IgnoreCase))
                {
                    rdpAccountEntries.Add(pe);
                }
            }
            return(rdpAccountEntries);
        }
Пример #4
0
        public static bool PerformGlobal(List<PwDatabase> vSources,
            ImageList ilIcons)
        {
            Debug.Assert(vSources != null); if(vSources == null) return false;

            IntPtr hWnd;
            string strWindow;

            try
            {
                hWnd = NativeMethods.GetForegroundWindow();
                strWindow = NativeMethods.GetWindowText(hWnd);
            }
            catch(Exception) { Debug.Assert(false); hWnd = IntPtr.Zero; strWindow = null; }

            if((strWindow == null) || (strWindow.Length == 0)) return false;

            PwObjectList<PwEntry> m_vList = new PwObjectList<PwEntry>();

            DateTime dtNow = DateTime.Now;

            EntryHandler eh = delegate(PwEntry pe)
            {
                // Ignore expired entries
                if(pe.Expires && (pe.ExpiryTime < dtNow)) return true;

                if(GetSequenceForWindow(pe, strWindow, true) != null)
                    m_vList.Add(pe);

                return true;
            };

            foreach(PwDatabase pwSource in vSources)
            {
                if(pwSource.IsOpen == false) continue;
                pwSource.RootGroup.TraverseTree(TraversalMethod.PreOrder, null, eh);
            }

            if(m_vList.UCount == 1)
                AutoType.PerformInternal(m_vList.GetAt(0), strWindow);
            else if(m_vList.UCount > 1)
            {
                EntryListForm elf = new EntryListForm();
                elf.InitEx(KPRes.AutoTypeEntrySelection, KPRes.AutoTypeEntrySelectionDescShort,
                    KPRes.AutoTypeEntrySelectionDescLong,
                    Properties.Resources.B48x48_KGPG_Key2, ilIcons, m_vList);
                elf.EnsureForeground = true;

                if(elf.ShowDialog() == DialogResult.OK)
                {
                    try { NativeMethods.EnsureForegroundWindow(hWnd); }
                    catch(Exception) { Debug.Assert(false); }

                    if(elf.SelectedEntry != null)
                        AutoType.PerformInternal(elf.SelectedEntry, strWindow);
                }
            }

            return true;
        }
Пример #5
0
        /// <summary>
        /// Finds all entries with a given tag (or multiple)
        /// </summary>
        /// <param name="sourceDb">Database to search for the entries.</param>
        /// <param name="tags">Tag to search for (multiple separated by ,).</param>
        /// <returns>A PwObjectList with all metching entries.</returns>
        private static PwObjectList <PwEntry> FindEntriesByTag(PwDatabase sourceDb, string tags)
        {
            PwObjectList <PwEntry> entries = new PwObjectList <PwEntry>();

            foreach (string tag in tags.Split(',').Select(x => x.Trim()))
            {
                PwObjectList <PwEntry> tagEntries = new PwObjectList <PwEntry>();
                sourceDb.RootGroup.FindEntriesByTag(tag, tagEntries, true);
                // Prevent duplicated entries
                IEnumerable <PwUuid> existingUuids = entries.Select(x => x.Uuid);
                List <PwEntry>       entriesToAdd  = tagEntries.Where(x => !existingUuids.Contains(x.Uuid)).ToList();
                entries.Add(entriesToAdd);
            }

            return(entries);
        }
        public static PwObjectList <PwEntry> GetPossibleTemplates(IPluginHost m_host)
        {
            PwObjectList <PwEntry> entries = new PwObjectList <PwEntry>();
            PwGroup group = template_group(m_host);

            if (group == null)
            {
                return(entries);
            }
            PwObjectList <PwEntry> all_entries = group.GetEntries(true);

            foreach (PwEntry entry in all_entries)
            {
                if (entry.Strings.Exists("_etm_template"))
                {
                    entries.Add(entry);
                }
            }
            return(entries);
        }
Пример #7
0
        private void OnEntryDuplicate(object sender, EventArgs e)
        {
            PwDatabase pd = m_docMgr.ActiveDatabase;
            PwGroup pgSelected = GetSelectedGroup();

            PwEntry[] vSelected = GetSelectedEntries();
            if((vSelected == null) || (vSelected.Length == 0)) return;

            DuplicationForm dlg = new DuplicationForm();
            if(UIUtil.ShowDialogAndDestroy(dlg) != DialogResult.OK) return;

            PwObjectList<PwEntry> vNewEntries = new PwObjectList<PwEntry>();
            foreach(PwEntry pe in vSelected)
            {
                PwEntry peNew = pe.CloneDeep();
                peNew.SetUuid(new PwUuid(true), true); // Create new UUID

                if(dlg.AppendCopyToTitles && (pd != null))
                {
                    string strTitle = peNew.Strings.ReadSafe(PwDefs.TitleField);
                    peNew.Strings.Set(PwDefs.TitleField, new ProtectedString(
                        pd.MemoryProtection.ProtectTitle, strTitle + " - " +
                        KPRes.CopyOfItem));
                }

                if(dlg.ReplaceDataByFieldRefs && (pd != null))
                {
                    string strUser = @"{REF:U@I:" + pe.Uuid.ToHexString() + @"}";
                    peNew.Strings.Set(PwDefs.UserNameField, new ProtectedString(
                        pd.MemoryProtection.ProtectUserName, strUser));

                    string strPw = @"{REF:P@I:" + pe.Uuid.ToHexString() + @"}";
                    peNew.Strings.Set(PwDefs.PasswordField, new ProtectedString(
                        pd.MemoryProtection.ProtectPassword, strPw));
                }

                Debug.Assert(pe.ParentGroup == peNew.ParentGroup);
                PwGroup pg = (pe.ParentGroup ?? pgSelected);
                if((pg == null) && (pd != null)) pg = pd.RootGroup;
                if(pg == null) continue;

                pg.AddEntry(peNew, true, true);
                vNewEntries.Add(peNew);
            }

            AddEntriesToList(vNewEntries);
            SelectEntries(vNewEntries, true, false);

            if(!m_lvEntries.ShowGroups && (m_lvEntries.Items.Count >= 1))
                m_lvEntries.EnsureVisible(m_lvEntries.Items.Count - 1);
            else EnsureVisibleSelected(true);

            UpdateUIState(true, m_lvEntries);
        }
Пример #8
0
        private void OnEntryAdd(object sender, EventArgs e)
        {
            PwGroup pg = GetSelectedGroup();
            Debug.Assert(pg != null); if(pg == null) return;

            if(pg.IsVirtual)
            {
                MessageService.ShowWarning(KPRes.GroupCannotStoreEntries,
                    KPRes.SelectDifferentGroup);
                return;
            }

            PwDatabase pwDb = m_docMgr.ActiveDatabase;
            PwEntry pwe = new PwEntry(true, true);
            pwe.Strings.Set(PwDefs.UserNameField, new ProtectedString(
                pwDb.MemoryProtection.ProtectUserName,
                pwDb.DefaultUserName));

            ProtectedString psAutoGen = new ProtectedString(
                pwDb.MemoryProtection.ProtectPassword);
            PwGenerator.Generate(psAutoGen, Program.Config.PasswordGenerator.AutoGeneratedPasswordsProfile,
                null, Program.PwGeneratorPool);
            pwe.Strings.Set(PwDefs.PasswordField, psAutoGen);

            int nExpireDays = Program.Config.Defaults.NewEntryExpiresInDays;
            if(nExpireDays >= 0)
            {
                pwe.Expires = true;
                pwe.ExpiryTime = DateTime.Now.AddDays(nExpireDays);
            }

            if((pg.IconId != PwIcon.Folder) && (pg.IconId != PwIcon.FolderOpen) &&
                (pg.IconId != PwIcon.FolderPackage))
            {
                pwe.IconId = pg.IconId; // Inherit icon from group
            }
            pwe.CustomIconUuid = pg.CustomIconUuid;

            // Temporarily assume that the entry is in pg; required for retrieving
            // the default auto-type sequence
            pwe.ParentGroup = pg;

            PwEntryForm pForm = new PwEntryForm();
            pForm.InitEx(pwe, PwEditMode.AddNewEntry, pwDb, m_ilCurrentIcons,
                false, false);
            if(UIUtil.ShowDialogAndDestroy(pForm) == DialogResult.OK)
            {
                pg.AddEntry(pwe, true);
                UpdateUI(false, null, pwDb.UINeedsIconUpdate, null, true,
                    null, true, m_lvEntries);

                PwObjectList<PwEntry> vSelect = new PwObjectList<PwEntry>();
                vSelect.Add(pwe);
                SelectEntries(vSelect, true, true);

                EnsureVisibleEntry(pwe.Uuid);
            }
            else UpdateUI(false, null, pwDb.UINeedsIconUpdate, null,
                pwDb.UINeedsIconUpdate, null, false);
        }
Пример #9
0
        private void OnEntryDuplicate(object sender, EventArgs e)
        {
            PwDatabase pd = m_docMgr.ActiveDatabase;
            PwGroup pgSelected = GetSelectedGroup();

            PwEntry[] vSelected = GetSelectedEntries();
            if((vSelected == null) || (vSelected.Length == 0)) return;

            DuplicationForm dlg = new DuplicationForm();
            if(UIUtil.ShowDialogAndDestroy(dlg) != DialogResult.OK) return;

            PwObjectList<PwEntry> vNewEntries = new PwObjectList<PwEntry>();
            foreach(PwEntry pe in vSelected)
            {
                PwEntry peNew = pe.CloneDeep();
                peNew.SetUuid(new PwUuid(true), true); // Create new UUID

                dlg.ApplyTo(peNew, pe, pd);

                Debug.Assert(pe.ParentGroup == peNew.ParentGroup);
                PwGroup pg = (pe.ParentGroup ?? pgSelected);
                if((pg == null) && (pd != null)) pg = pd.RootGroup;
                if(pg == null) continue;

                pg.AddEntry(peNew, true, true);
                vNewEntries.Add(peNew);
            }

            AddEntriesToList(vNewEntries);
            SelectEntries(vNewEntries, true, true);

            // if(!m_lvEntries.ShowGroups && (m_lvEntries.Items.Count >= 1))
            //	m_lvEntries.EnsureVisible(m_lvEntries.Items.Count - 1);
            // else EnsureVisibleSelected(true);
            EnsureVisibleSelected(true); // Show all copies if possible
            EnsureVisibleSelected(false); // Ensure showing the first

            UpdateUIState(true, m_lvEntries);
        }
Пример #10
0
        private void OnToolsPwGenerator(object sender, EventArgs e)
        {
            PwDatabase pwDb = m_docMgr.ActiveDatabase;

            PwGeneratorForm pgf = new PwGeneratorForm();
            pgf.InitEx(null, pwDb.IsOpen, IsTrayed());

            if(pgf.ShowDialog() == DialogResult.OK)
            {
                if(pwDb.IsOpen)
                {
                    PwGroup pg = GetSelectedGroup();
                    if(pg == null) pg = pwDb.RootGroup;

                    PwEntry pe = new PwEntry(true, true);
                    pg.AddEntry(pe, true);

                    byte[] pbAdditionalEntropy = EntropyForm.CollectEntropyIfEnabled(
                        pgf.SelectedProfile);
                    ProtectedString psNew;
                    PwGenerator.Generate(out psNew, pgf.SelectedProfile,
                        pbAdditionalEntropy, Program.PwGeneratorPool);
                    psNew = psNew.WithProtection(pwDb.MemoryProtection.ProtectPassword);
                    pe.Strings.Set(PwDefs.PasswordField, psNew);

                    UpdateUI(false, null, false, null, true, null, true, m_lvEntries);

                    PwObjectList<PwEntry> l = new PwObjectList<PwEntry>();
                    l.Add(pe);
                    SelectEntries(l, true, true);
                    EnsureVisibleSelected(false);
                }
            }
            UIUtil.DestroyForm(pgf);
        }
Пример #11
0
        private void OnToolsGeneratePasswordList(object sender, EventArgs e)
        {
            PwDatabase pwDb = m_docMgr.ActiveDatabase;
            if(!pwDb.IsOpen) return;

            PwGeneratorForm pgf = new PwGeneratorForm();
            pgf.InitEx(null, true, IsTrayed());

            if(pgf.ShowDialog() == DialogResult.OK)
            {
                PwGroup pg = GetSelectedGroup();
                if(pg == null) pg = pwDb.RootGroup;

                SingleLineEditForm dlgCount = new SingleLineEditForm();
                dlgCount.InitEx(KPRes.GenerateCount, KPRes.GenerateCountDesc,
                    KPRes.GenerateCountLongDesc, Properties.Resources.B48x48_KGPG_Gen,
                    string.Empty, null);
                if(dlgCount.ShowDialog() == DialogResult.OK)
                {
                    uint uCount;
                    if(!uint.TryParse(dlgCount.ResultString, out uCount))
                        uCount = 1;

                    byte[] pbAdditionalEntropy = EntropyForm.CollectEntropyIfEnabled(
                        pgf.SelectedProfile);

                    PwObjectList<PwEntry> l = new PwObjectList<PwEntry>();
                    for(uint i = 0; i < uCount; ++i)
                    {
                        PwEntry pe = new PwEntry(true, true);
                        pg.AddEntry(pe, true);

                        ProtectedString psNew;
                        PwGenerator.Generate(out psNew, pgf.SelectedProfile,
                            pbAdditionalEntropy, Program.PwGeneratorPool);
                        psNew = psNew.WithProtection(pwDb.MemoryProtection.ProtectPassword);
                        pe.Strings.Set(PwDefs.PasswordField, psNew);

                        l.Add(pe);
                    }

                    UpdateUI(false, null, false, null, true, null, true, m_lvEntries);

                    SelectEntries(l, true, true);
                    EnsureVisibleSelected(false);
                }
                UIUtil.DestroyForm(dlgCount);
            }
            UIUtil.DestroyForm(pgf);
        }
 /// <summary>
 /// Finds all UserRootNodes, which means the returned list contains all users.
 /// </summary>
 /// <returns>A list which contains all UserRootNodes of the actual database.</returns>
 public static PwObjectList<PwEntry> GetAllUserNodes(this PwDatabase database)
 {
     PwObjectList<PwEntry> allEntries = database.RootGroup.GetEntries(true);
     PwObjectList<PwEntry> rootList = new PwObjectList<PwEntry>();
     foreach (PwEntry pe in allEntries)
     {
         if (pe.IsUserRootNode())
         {
             rootList.Add(pe);
         }
     }
     return rootList;
 }
Пример #13
0
        public static void ReorderEntriesAsInDatabase(PwObjectList<PwEntry> v,
            PwDatabase pd)
        {
            if((v == null) || (pd == null)) { Debug.Assert(false); return; }
            if(pd.RootGroup == null) { Debug.Assert(false); return; } // DB must be open

            PwObjectList<PwEntry> vRem = v.CloneShallow();
            v.Clear();

            EntryHandler eh = delegate(PwEntry pe)
            {
                int p = vRem.IndexOf(pe);
                if(p >= 0)
                {
                    v.Add(pe);
                    vRem.RemoveAt((uint)p);
                }

                return true;
            };

            pd.RootGroup.TraverseTree(TraversalMethod.PreOrder, null, eh);

            foreach(PwEntry peRem in vRem) v.Add(peRem); // Entries not found
        }
Пример #14
0
        public static bool PerformGlobal(List<PwDatabase> vSources,
            ImageList ilIcons)
        {
            Debug.Assert(vSources != null); if(vSources == null) return false;

            if(KeePassLib.Native.NativeLib.IsUnix())
            {
                if(!NativeMethods.TryXDoTool(true))
                {
                    MessageService.ShowWarning(KPRes.AutoTypeXDoToolRequiredGlobalVer);
                    return false;
                }
            }

            IntPtr hWnd;
            string strWindow;
            try
            {
                // hWnd = NativeMethods.GetForegroundWindowHandle();
                // strWindow = NativeMethods.GetWindowText(hWnd);
                NativeMethods.GetForegroundWindowInfo(out hWnd, out strWindow, true);
            }
            catch(Exception) { Debug.Assert(false); hWnd = IntPtr.Zero; strWindow = null; }

            if(string.IsNullOrEmpty(strWindow)) return false;
            if(!IsValidAutoTypeWindow(hWnd, true)) return false;

            PwObjectList<PwEntry> vList = new PwObjectList<PwEntry>();
            DateTime dtNow = DateTime.Now;

            EntryHandler eh = delegate(PwEntry pe)
            {
                // Ignore expired entries
                if(pe.Expires && (pe.ExpiryTime < dtNow)) return true;

                if(GetSequenceForWindow(pe, strWindow, true) != null)
                    vList.Add(pe);

                return true;
            };

            foreach(PwDatabase pwSource in vSources)
            {
                if(pwSource.IsOpen == false) continue;
                pwSource.RootGroup.TraverseTree(TraversalMethod.PreOrder, null, eh);
            }

            if(vList.UCount == 1)
                AutoType.PerformInternal(vList.GetAt(0), strWindow);
            else if(vList.UCount > 1)
            {
                EntryListForm elf = new EntryListForm();
                elf.InitEx(KPRes.AutoTypeEntrySelection, KPRes.AutoTypeEntrySelectionDescShort,
                    KPRes.AutoTypeEntrySelectionDescLong,
                    Properties.Resources.B48x48_KGPG_Key2, ilIcons, vList);
                elf.EnsureForeground = true;

                if(elf.ShowDialog() == DialogResult.OK)
                {
                    try { NativeMethods.EnsureForegroundWindow(hWnd); }
                    catch(Exception) { Debug.Assert(false); }

                    if(elf.SelectedEntry != null)
                        AutoType.PerformInternal(elf.SelectedEntry, strWindow);
                }
                UIUtil.DestroyForm(elf);
            }

            return true;
        }
Пример #15
0
        private void OnEntryViewLinkClicked(object sender, LinkClickedEventArgs e)
        {
            string strLink = e.LinkText;
            if(string.IsNullOrEmpty(strLink)) { Debug.Assert(false); return; }

            PwEntry pe = GetSelectedEntry(false);
            ProtectedBinary pb = ((pe != null) ? pe.Binaries.Get(strLink) : null);

            string strEntryUrl = string.Empty;
            if(pe != null)
                strEntryUrl = SprEngine.Compile(pe.Strings.ReadSafe(PwDefs.UrlField),
                    GetEntryListSprContext(pe, m_docMgr.SafeFindContainerOf(pe)));

            if((pe != null) && (pe.ParentGroup != null) &&
                (pe.ParentGroup.Name == strLink))
            {
                UpdateUI(false, null, true, pe.ParentGroup, true, null, false);
                EnsureVisibleSelected(false);
                ResetDefaultFocus(m_lvEntries);
            }
            else if(strEntryUrl == strLink)
                PerformDefaultUrlAction(null, false);
            else if(pb != null)
                ExecuteBinaryEditView(strLink, pb);
            else if(strLink.StartsWith(SprEngine.StrRefStart, StrUtil.CaseIgnoreCmp) &&
                strLink.EndsWith(SprEngine.StrRefEnd, StrUtil.CaseIgnoreCmp))
            {
                // If multiple references are amalgamated, only use first one
                string strFirstRef = strLink;
                int iEnd = strLink.IndexOf(SprEngine.StrRefEnd, StrUtil.CaseIgnoreCmp);
                if(iEnd != (strLink.Length - SprEngine.StrRefEnd.Length))
                    strFirstRef = strLink.Substring(0, iEnd + 1);

                char chScan, chWanted;
                PwEntry peRef = SprEngine.FindRefTarget(strFirstRef, GetEntryListSprContext(
                    pe, m_docMgr.SafeFindContainerOf(pe)), out chScan, out chWanted);
                if(peRef != null)
                {
                    UpdateUI(false, null, true, peRef.ParentGroup, true, null,
                        false, m_lvEntries);
                    PwObjectList<PwEntry> lSel = new PwObjectList<PwEntry>();
                    lSel.Add(peRef);
                    SelectEntries(lSel, true, true);
                    EnsureVisibleSelected(false);
                    ShowEntryDetails(peRef);
                }
            }
            else WinUtil.OpenUrl(strLink, pe);
        }
Пример #16
0
        private void OnEntryDuplicate(object sender, EventArgs e)
        {
            PwGroup pgSelected = GetSelectedGroup();

            PwEntry[] vSelected = GetSelectedEntries();
            if((vSelected == null) || (vSelected.Length == 0)) return;

            PwObjectList<PwEntry> vNewEntries = new PwObjectList<PwEntry>();
            foreach(PwEntry pe in vSelected)
            {
                PwEntry peNew = pe.CloneDeep();
                peNew.Uuid = new PwUuid(true); // Create new UUID

                ProtectedString psTitle = peNew.Strings.Get(PwDefs.TitleField);
                if(psTitle != null)
                    peNew.Strings.Set(PwDefs.TitleField, new ProtectedString(
                        psTitle.IsProtected, psTitle.ReadString() + " - " +
                        KPRes.CopyOfItem));

                Debug.Assert(pe.ParentGroup == peNew.ParentGroup);
                PwGroup pg = (pe.ParentGroup ?? pgSelected);
                if((pg == null) && (m_docMgr.ActiveDocument != null))
                    pg = m_docMgr.ActiveDatabase.RootGroup;
                if(pg == null) continue;

                pg.AddEntry(peNew, true, true);
                vNewEntries.Add(peNew);
            }

            AddEntriesToList(vNewEntries);
            SelectEntries(vNewEntries, true);

            if((m_lvEntries.ShowGroups == false) && (m_lvEntries.Items.Count >= 1))
                m_lvEntries.EnsureVisible(m_lvEntries.Items.Count - 1);
            else EnsureVisibleSelected(true);

            UpdateUIState(true);
        }
Пример #17
0
        /*
        private void ReadDeletedObjects(XmlNode xmlNode, PwObjectList<PwDeletedObject> list)
        {
            ProcessNode(xmlNode);

            foreach(XmlNode xmlChild in xmlNode.ChildNodes)
            {
                if(xmlChild.Name == ElemDeletedObject)
                    list.Add(ReadDeletedObject(xmlChild));
                else ReadUnknown(xmlChild);
            }
        }

        private PwDeletedObject ReadDeletedObject(XmlNode xmlNode)
        {
            ProcessNode(xmlNode);

            PwDeletedObject pdo = new PwDeletedObject();
            foreach(XmlNode xmlChild in xmlNode.ChildNodes)
            {
                if(xmlChild.Name == ElemUuid)
                    pdo.Uuid = ReadUuid(xmlChild);
                else if(xmlChild.Name == ElemDeletionTime)
                    pdo.DeletionTime = ReadTime(xmlChild);
                else ReadUnknown(xmlChild);
            }

            return pdo;
        }
        */
        private void ReadHistory(XmlNode xmlNode, PwObjectList<PwEntry> plStorage)
        {
            ProcessNode(xmlNode);

            foreach(XmlNode xmlChild in xmlNode.ChildNodes)
            {
                if(xmlChild.Name == ElemEntry)
                {
                    plStorage.Add(ReadEntry(xmlChild));
                }
                else ReadUnknown(xmlChild);
            }
        }
 public static PwObjectList<PwEntry> GetPossibleTemplates(IPluginHost m_host)
 {
     PwObjectList<PwEntry> entries = new PwObjectList<PwEntry>();
     PwGroup group = template_group(m_host);
     if (group == null)
         return entries;
     PwObjectList<PwEntry> all_entries = group.GetEntries(true);
     foreach (PwEntry entry in all_entries) {
         if (entry.Strings.Exists("_etm_template"))
             entries.Add(entry);
     }
     return entries;
 }
Пример #19
0
        private static void CreateEntry(PwEntry peTemplate)
        {
            if(peTemplate == null) { Debug.Assert(false); return; }

            PwDatabase pd = Program.MainForm.ActiveDatabase;
            if(pd == null) { Debug.Assert(false); return; }
            if(pd.IsOpen == false) { Debug.Assert(false); return; }

            PwGroup pgContainer = Program.MainForm.GetSelectedGroup();
            if(pgContainer == null) pgContainer = pd.RootGroup;

            PwEntry pe = peTemplate.Duplicate();

            if(EntryTemplates.EntryCreating != null)
                EntryTemplates.EntryCreating(null, new TemplateEntryEventArgs(
                    peTemplate.CloneDeep(), pe));

            PwEntryForm pef = new PwEntryForm();
            pef.InitEx(pe, PwEditMode.AddNewEntry, pd, Program.MainForm.ClientIcons,
                false, true);

            if(UIUtil.ShowDialogAndDestroy(pef) == DialogResult.OK)
            {
                pgContainer.AddEntry(pe, true, true);

                MainForm mf = Program.MainForm;
                if(mf != null)
                {
                    mf.UpdateUI(false, null, pd.UINeedsIconUpdate, null,
                        true, null, true);

                    PwObjectList<PwEntry> vSelect = new PwObjectList<PwEntry>();
                    vSelect.Add(pe);
                    mf.SelectEntries(vSelect, true, true);

                    mf.EnsureVisibleEntry(pe.Uuid);
                    mf.UpdateUI(false, null, false, null, false, null, false);
                }
                else { Debug.Assert(false); }

                if(EntryTemplates.EntryCreated != null)
                    EntryTemplates.EntryCreated(null, new TemplateEntryEventArgs(
                        peTemplate.CloneDeep(), pe));
            }
            else Program.MainForm.UpdateUI(false, null, pd.UINeedsIconUpdate, null,
                pd.UINeedsIconUpdate, null, false);
        }
 /// <summary>
 /// Finds all Proxynodes in the database. That means all PwEntries with a 
 /// StringFieldUidLink which points to another PwEntry
 /// </summary>
 /// <returns>A <c>PwObjectList<PwEntry></c> which contains all proxy nodes of the actual DB.</returns>
 public static PwObjectList<PwEntry> GetAllProxyNodes(this PwDatabase database)
 {
     PwObjectList<PwEntry> allEntries = database.RootGroup.GetEntries(true);
     PwObjectList<PwEntry> proxyList = new PwObjectList<PwEntry>();
     foreach (PwEntry entry in allEntries)
     {
         if (entry.IsProxyNode())
         {
             proxyList.Add(entry);
         }
     }
     return proxyList;
 }