private Dictionary <UInt32, PwGroup> ReadGroups(KdbManager 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 = KdbManager.GetNeverExpireTime(); for (uint uGroup = 0; uGroup < uGroupCount; ++uGroup) { KdbGroup 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)KdbGroupFlags.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, KdbManager mgr, bool bForceLevel0) { if (pg == pgRoot) { return; } KdbGroup grp = new KdbGroup(); 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)KdbGroupFlags.Expanded; } if (!mgr.AddGroup(ref grp)) { Debug.Assert(false); throw new InvalidOperationException(); } ++uGroupIndex; }