/// <summary> /// This function creates the correct structured database which will be used /// to create the delta container. /// </summary> /// <param name="sharedFolders">All PwGroups that should be placed in the delta /// container. Usually that are the PwGroups that are shared with the specified user.</param> /// <returns>A PwDatabae that conatins the hierarchically correct structured database /// which could be used to create a delta container.</returns> public PwDatabase CreateDeltaDb(PwDatabase database, PwObjectList <PwGroup> sharedFolders) { PwDatabase deltaDB = new PwDatabase(); deltaDB.RootGroup = new PwGroup(true, true) { //Uuid = database.RootGroup.Uuid // We set the root group to the same Uuid to identify the source database (does not work for cycles with more hops) }; foreach (PwGroup group in sharedFolders) { foreach (PwEntry entry in group.Entries) { PwEntry copyEntry = null; //do we handle a normal pwentry if (entry.IsNormalPwEntry()) { //we dont want to share a PwEntry more than once! if (null != deltaDB.RootGroup.FindEntry(entry.Uuid, true)) { continue; } // check if our origParent was a normal folder or some KeeShare specific Folder ("Users" / "Groups" / "SyncGroup") if (IsKeeShareFolder(database, group)) { entry.SetParent(deltaDB.RootGroup); copyEntry = entry; } else //the entry was located in a normal PwGroup { copyEntry = database.DuplicateEntryTo(entry, deltaDB); } } //or a pwproxy if (database.IsPasswordProxy(entry)) { //we only add the rootNode to the copy, because all proxies are only information for KeeShare PwEntry entryRoot = database.GetProxyTargetFor(entry); //we dont want to share a PwEntry more than once! if (null != deltaDB.RootGroup.FindEntry(entryRoot.Uuid, true)) { continue; } copyEntry = database.DuplicateEntryTo(entryRoot, deltaDB); } if (copyEntry != null) { copyEntry.AddExportSource(database.RootGroup.Uuid.ToHexString()); } //everything else (UserProxy and UserRootNodes) we have to ignore! //Debug.Assert(!copyDB.HasDuplicateUuids()); } } return(deltaDB); }