private static PwGroup FilterCloneGroup(PwGroup pg, Dictionary <PwUuid, bool> dUuids) { PwGroup pgNew = new PwGroup(); pgNew.Uuid = pg.Uuid; pgNew.AssignProperties(pg, false, true); Debug.Assert(pgNew.EqualsGroup(pg, (PwCompareOptions.IgnoreParentGroup | PwCompareOptions.PropertiesOnly), MemProtCmpMode.Full)); foreach (PwEntry pe in pg.Entries) { if (dUuids.ContainsKey(pe.Uuid)) { pgNew.AddEntry(pe.CloneDeep(), true, false); } } foreach (PwGroup pgSub in pg.Groups) { if (dUuids.ContainsKey(pgSub.Uuid)) { pgNew.AddGroup(FilterCloneGroup(pgSub, dUuids), true, false); } } return(pgNew); }
private static void PrepareModDbForMerge(PwDatabase pd, PwDatabase pdOrg) { PwGroup pgRootOrg = pdOrg.RootGroup; PwGroup pgRootNew = pd.RootGroup; if (pgRootNew == null) { Debug.Assert(false); return; } PwCompareOptions pwCmp = (PwCompareOptions.IgnoreParentGroup | PwCompareOptions.NullEmptyEquivStd); DateTime dtNow = DateTime.UtcNow; GroupHandler ghOrg = delegate(PwGroup pg) { PwGroup pgNew = pgRootNew.FindGroup(pg.Uuid, true); if (pgNew == null) { AddDeletedObject(pd, pg.Uuid); return(true); } if (!pgNew.EqualsGroup(pg, (pwCmp | PwCompareOptions.PropertiesOnly), MemProtCmpMode.Full)) { pgNew.Touch(true, false); } PwGroup pgParentA = pg.ParentGroup; PwGroup pgParentB = pgNew.ParentGroup; if ((pgParentA != null) && (pgParentB != null)) { if (!pgParentA.Uuid.Equals(pgParentB.Uuid)) { pgNew.LocationChanged = dtNow; } } else if ((pgParentA == null) && (pgParentB == null)) { } else { pgNew.LocationChanged = dtNow; } return(true); }; EntryHandler ehOrg = delegate(PwEntry pe) { PwEntry peNew = pgRootNew.FindEntry(pe.Uuid, true); if (peNew == null) { AddDeletedObject(pd, pe.Uuid); return(true); } if (!peNew.EqualsEntry(pe, pwCmp, MemProtCmpMode.Full)) { peNew.Touch(true, false); bool bRestoreHistory = false; if (peNew.History.UCount != pe.History.UCount) { bRestoreHistory = true; } else { for (uint u = 0; u < pe.History.UCount; ++u) { if (!peNew.History.GetAt(u).EqualsEntry( pe.History.GetAt(u), pwCmp, MemProtCmpMode.CustomOnly)) { bRestoreHistory = true; break; } } } if (bRestoreHistory) { peNew.History = pe.History.CloneDeep(); foreach (PwEntry peHistNew in peNew.History) { peHistNew.ParentGroup = peNew.ParentGroup; } } } PwGroup pgParentA = pe.ParentGroup; PwGroup pgParentB = peNew.ParentGroup; if ((pgParentA != null) && (pgParentB != null)) { if (!pgParentA.Uuid.Equals(pgParentB.Uuid)) { peNew.LocationChanged = dtNow; } } else if ((pgParentA == null) && (pgParentB == null)) { } else { peNew.LocationChanged = dtNow; } return(true); }; pgRootOrg.TraverseTree(TraversalMethod.PreOrder, ghOrg, ehOrg); }
private static void PrepareModDbForMerge(PwDatabase pd, PwDatabase pdOrg) { PwGroup pgRootOrg = pdOrg.RootGroup; PwGroup pgRootNew = pd.RootGroup; if (pgRootNew == null) { Debug.Assert(false); return; } const PwCompareOptions cmpOpt = (PwCompareOptions.IgnoreParentGroup | PwCompareOptions.IgnoreHistory | PwCompareOptions.NullEmptyEquivStd); const MemProtCmpMode cmpMem = MemProtCmpMode.CustomOnly; DateTime dtNow = DateTime.UtcNow; GroupHandler ghOrg = delegate(PwGroup pg) { PwGroup pgNew = pgRootNew.FindGroup(pg.Uuid, true); if (pgNew == null) { AddDeletedObject(pd, pg.Uuid); return(true); } if (!pgNew.EqualsGroup(pg, (cmpOpt | PwCompareOptions.PropertiesOnly), cmpMem)) { pgNew.Touch(true, false); } PwGroup pgParentA = pg.ParentGroup; PwGroup pgParentB = pgNew.ParentGroup; if ((pgParentA != null) && (pgParentB != null)) { if (!pgParentA.Uuid.Equals(pgParentB.Uuid)) { pgNew.LocationChanged = dtNow; } } else if ((pgParentA == null) && (pgParentB == null)) { } else { pgNew.LocationChanged = dtNow; } return(true); }; EntryHandler ehOrg = delegate(PwEntry pe) { PwEntry peNew = pgRootNew.FindEntry(pe.Uuid, true); if (peNew == null) { AddDeletedObject(pd, pe.Uuid); return(true); } // Restore history entries peNew.History = pe.History.CloneDeep(); foreach (PwEntry peHistNew in peNew.History) { peHistNew.ParentGroup = peNew.ParentGroup; } if (!peNew.EqualsEntry(pe, cmpOpt, cmpMem)) { peNew.Touch(true, false); } PwGroup pgParentA = pe.ParentGroup; PwGroup pgParentB = peNew.ParentGroup; if ((pgParentA != null) && (pgParentB != null)) { if (!pgParentA.Uuid.Equals(pgParentB.Uuid)) { peNew.LocationChanged = dtNow; } } else if ((pgParentA == null) && (pgParentB == null)) { } else { peNew.LocationChanged = dtNow; } return(true); }; pgRootOrg.TraverseTree(TraversalMethod.PreOrder, ghOrg, ehOrg); }