public static void ReorderEntriesAsInDatabase(PwObjectList <PwEntry> v, PwDatabase pd) { if ((v == null) || (pd == null)) { Debug.Assert(false); return; } 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 } }
private static void ExportDatabaseFile(EcasAction a, EcasContext ctx) { string strPath = EcasUtil.GetParamString(a.Parameters, 0, true); // if(string.IsNullOrEmpty(strPath)) return; // Allow no-file exports string strFormat = EcasUtil.GetParamString(a.Parameters, 1, true); if (string.IsNullOrEmpty(strFormat)) { return; } string strGroup = EcasUtil.GetParamString(a.Parameters, 2, true); string strTag = EcasUtil.GetParamString(a.Parameters, 3, true); PwDatabase pd = Program.MainForm.ActiveDatabase; if ((pd == null) || !pd.IsOpen) { return; } PwGroup pg = pd.RootGroup; if (!string.IsNullOrEmpty(strGroup)) { char chSep = strGroup[0]; PwGroup pgSub = pg.FindCreateSubTree(strGroup.Substring(1), new char[] { chSep }, false); pg = (pgSub ?? (new PwGroup(true, true, KPRes.Group, PwIcon.Folder))); } if (!string.IsNullOrEmpty(strTag)) { pg = pg.CloneDeep(); GroupHandler gh = delegate(PwGroup pgSub) { PwObjectList <PwEntry> l = pgSub.Entries; long n = (long)l.UCount; for (long i = n - 1; i >= 0; --i) { if (!l.GetAt((uint)i).HasTag(strTag)) { l.RemoveAt((uint)i); } } return(true); }; gh(pg); pg.TraverseTree(TraversalMethod.PreOrder, gh, null); } PwExportInfo pei = new PwExportInfo(pg, pd, true); IOConnectionInfo ioc = (!string.IsNullOrEmpty(strPath) ? IOConnectionInfo.FromPath(strPath) : null); ExportUtil.Export(pei, strFormat, ioc); }
private void RemoveOldestBackup() { DateTime dtMin = TimeUtil.SafeMaxValueUtc; uint idxRemove = uint.MaxValue; for(uint u = 0; u < m_listHistory.UCount; ++u) { PwEntry pe = m_listHistory.GetAt(u); if(TimeUtil.Compare(pe.LastModificationTime, dtMin, true) < 0) { idxRemove = u; dtMin = pe.LastModificationTime; } } if(idxRemove != uint.MaxValue) m_listHistory.RemoveAt(idxRemove); }
private void RemoveOldestBackup() { DateTime dtMin = DateTime.MaxValue; uint idxRemove = uint.MaxValue; for (uint u = 0; u < m_listHistory.UCount; ++u) { PwEntry pe = m_listHistory.GetAt(u); if (pe.LastModificationTime < dtMin) { idxRemove = u; dtMin = pe.LastModificationTime; } } if (idxRemove != uint.MaxValue) { m_listHistory.RemoveAt(idxRemove); } }
/// <summary> /// Find active configured Google Accounts /// Should only return one account /// </summary> private PwObjectList <PwEntry> FindActiveAccounts() { if (!m_host.Database.IsOpen) { return(null); } PwObjectList <PwEntry> accounts = new PwObjectList <PwEntry>(); SearchParameters sp = new SearchParameters(); sp.SearchString = Defs.ConfigActiveAccountTrue; sp.ComparisonMode = StringComparison.Ordinal; sp.RespectEntrySearchingDisabled = false; sp.SearchInGroupNames = false; sp.SearchInNotes = false; sp.SearchInOther = true; sp.SearchInPasswords = false; sp.SearchInTags = false; sp.SearchInTitles = false; sp.SearchInUrls = false; sp.SearchInUserNames = false; sp.SearchInUuids = false; m_host.Database.RootGroup.SearchEntries(sp, accounts); for (int idx = 0; idx < accounts.UCount; idx++) { PwEntry entry = accounts.GetAt((uint)idx); if (!(entry.Strings.Exists(Defs.ConfigActiveAccount) && entry.Strings.Get(Defs.ConfigActiveAccount).ReadString().Equals(Defs.ConfigActiveAccountTrue))) { accounts.RemoveAt((uint)idx--); } } return(accounts); }
private PwGroup SrxpFilterCloneSelf(SearchParameters sp) { PwGroup pgNew = CloneDeep(); pgNew.ParentGroup = null; DateTime dtNow = DateTime.UtcNow; GroupHandler gh = delegate(PwGroup pg) { if (!sp.SearchInGroupNames) { pg.Name = string.Empty; } if (!sp.SearchInTags) { pg.Tags.Clear(); } PwObjectList <PwEntry> l = pg.Entries; for (int i = (int)l.UCount - 1; i >= 0; --i) { PwEntry pe = l.GetAt((uint)i); if (sp.ExcludeExpired && pe.Expires && (pe.ExpiryTime <= dtNow)) { } else if (sp.RespectEntrySearchingDisabled && !pe.GetSearchingEnabled()) { } else { continue; } l.RemoveAt((uint)i); } return(true); }; EntryHandler eh = delegate(PwEntry pe) { SrxpClearString(!sp.SearchInTitles, pe, PwDefs.TitleField); SrxpClearString(!sp.SearchInUserNames, pe, PwDefs.UserNameField); SrxpClearString(!sp.SearchInPasswords, pe, PwDefs.PasswordField); SrxpClearString(!sp.SearchInUrls, pe, PwDefs.UrlField); SrxpClearString(!sp.SearchInNotes, pe, PwDefs.NotesField); if (!sp.SearchInOther) { List <string> lKeys = pe.Strings.GetKeys(); foreach (string strKey in lKeys) { SrxpClearString(!PwDefs.IsStandardField(strKey), pe, strKey); } } if (!sp.SearchInTags) { pe.Tags.Clear(); } if (!sp.SearchInHistory) { pe.History.Clear(); } return(true); }; gh(pgNew); pgNew.TraverseTree(TraversalMethod.PreOrder, gh, eh); return(pgNew); }