private static Dictionary <PwGroup, UInt32> WriteGroups(Kdb3Manager mgr, PwGroup pgRoot) { Dictionary <PwGroup, UInt32> dictGroups = new Dictionary <PwGroup, uint>(); uint uGroupIndex = 1; DateTime dtNeverExpire = Kdb3Manager.GetNeverExpireTime(); GroupHandler gh = delegate(PwGroup pg) { if (pg == pgRoot) { return(true); } Kdb3Group grp = new Kdb3Group(); grp.GroupId = uGroupIndex; dictGroups[pg] = grp.GroupId; grp.ImageId = (uint)pg.IconId; grp.Name = pg.Name; grp.CreationTime.Set(pg.CreationTime); grp.LastModificationTime.Set(pg.LastModificationTime); grp.LastAccessTime.Set(pg.LastAccessTime); if (pg.Expires) { grp.ExpirationTime.Set(pg.ExpiryTime); } else { grp.ExpirationTime.Set(dtNeverExpire); } grp.Level = (ushort)(pg.GetLevel() - 1); if (pg.IsExpanded) { grp.Flags |= (uint)Kdb3GroupFlags.Expanded; } if (!mgr.AddGroup(ref grp)) { Debug.Assert(false); throw new InvalidOperationException(); } ++uGroupIndex; return(true); }; pgRoot.TraverseTree(TraversalMethod.PreOrder, gh, null); Debug.Assert(dictGroups.Count == (int)(uGroupIndex - 1)); return(dictGroups); }
private Dictionary <UInt32, PwGroup> ReadGroups(Kdb3Manager mgr) { uint uGroupCount = mgr.GroupCount; Dictionary <UInt32, PwGroup> dictGroups = new Dictionary <uint, PwGroup>(); Stack <PwGroup> vGroupStack = new Stack <PwGroup>(); vGroupStack.Push(m_pwDatabase.RootGroup); DateTime dtNeverExpire = Kdb3Manager.GetNeverExpireTime(); for (uint uGroup = 0; uGroup < uGroupCount; ++uGroup) { Kdb3Group g = mgr.GetGroup(uGroup); PwGroup pg = new PwGroup(true, false); pg.Name = g.Name; pg.IconId = (g.ImageId < (uint)PwIcon.Count) ? (PwIcon)g.ImageId : PwIcon.Folder; pg.CreationTime = g.CreationTime.ToDateTime(); pg.LastModificationTime = g.LastModificationTime.ToDateTime(); pg.LastAccessTime = g.LastAccessTime.ToDateTime(); pg.ExpiryTime = g.ExpirationTime.ToDateTime(); pg.Expires = (pg.ExpiryTime != dtNeverExpire); pg.IsExpanded = ((g.Flags & (uint)Kdb3GroupFlags.Expanded) != 0); while (g.Level < (vGroupStack.Count - 1)) { vGroupStack.Pop(); } vGroupStack.Peek().AddGroup(pg, true); dictGroups[g.GroupId] = pg; if (g.Level == (uint)(vGroupStack.Count - 1)) { vGroupStack.Push(pg); } } return(dictGroups); }
private static void WriteGroup(PwGroup pg, PwGroup pgRoot, ref uint uGroupIndex, Dictionary <PwGroup, UInt32> dictGroups, DateTime dtNeverExpire, Kdb3Manager mgr, bool bForceLevel0) { if (pg == pgRoot) { return; } Kdb3Group grp = new Kdb3Group(); grp.GroupId = uGroupIndex; dictGroups[pg] = grp.GroupId; grp.ImageId = (uint)pg.IconId; grp.Name = pg.Name; grp.CreationTime.Set(pg.CreationTime); grp.LastModificationTime.Set(pg.LastModificationTime); grp.LastAccessTime.Set(pg.LastAccessTime); if (pg.Expires) { grp.ExpirationTime.Set(pg.ExpiryTime); } else { grp.ExpirationTime.Set(dtNeverExpire); } grp.Level = (bForceLevel0 ? (ushort)0 : (ushort)(pg.GetLevel() - 1)); if (pg.IsExpanded) { grp.Flags |= (uint)Kdb3GroupFlags.Expanded; } if (!mgr.AddGroup(ref grp)) { Debug.Assert(false); throw new InvalidOperationException(); } ++uGroupIndex; }