/// <summary> /// The function tries to merge possible updates from the deltaDB into /// the actual database. If there was made changes to the actualDB, then /// the function fires a event, which cause the KeePass UI to update and /// show the "save"-button. /// </summary> public void Import(object sender, SyncSource source) { Debug.Assert(source.DestinationDB != null && source.DestinationDB.RootGroup != null); //merge all updates in PwDatabase deltaDB = new PwDatabase(); try { deltaDB.Open(IOConnectionInfo.FromPath(source.Location), source.Key, null); } catch (InvalidCompositeKeyException e) { Debug.WriteLine("Wrong key! exception was: " + e.Message); //brand this entry as a false one => red bg-color and "X" as group icon ShowErrorHighlight(source.DestinationDB, source.Uuid); if (Imported != null) { Imported.Invoke(this, source.DestinationDB.RootGroup); } return; } catch (Exception e) { Debug.WriteLine("Standard exception was thrown during deltaDB.Open(): " + e.Message); //maybe the process has not finished writing to our file, but the filewtcher fires our event //sourceEntryUuid we have to ignore it and wait for the next one. return; } HideErrorHighlight(source.DestinationDB, source.Uuid); MergeIn(source.DestinationDB, deltaDB); deltaDB.Close(); }
/// <summary> /// The function tries to merge possible updates from the deltaDB into /// the actual database. If there was made changes to the actualDB, then /// the function fires a event, which cause the KeePass UI to update and /// show the "save"-button. /// </summary> public void Import(object sender, SyncSource source) { Debug.Assert(source.DestinationDB != null && source.DestinationDB.RootGroup != null); //merge all updates in PwDatabase deltaDB = new PwDatabase(); try { deltaDB.Open(IOConnectionInfo.FromPath(source.Location), source.Key, null); } catch (InvalidCompositeKeyException e) { Debug.WriteLine("Wrong key! exception was: " + e.Message); //brand this entry as a false one => red bg-color and "X" as group icon ShowErrorHighlight(source.DestinationDB, source.Uuid); if (Imported != null) Imported.Invoke(this, source.DestinationDB.RootGroup); return; } catch (Exception e) { Debug.WriteLine("Standard exception was thrown during deltaDB.Open(): " + e.Message); //maybe the process has not finished writing to our file, but the filewtcher fires our event //sourceEntryUuid we have to ignore it and wait for the next one. return; } HideErrorHighlight(source.DestinationDB, source.Uuid); MergeIn(source.DestinationDB, deltaDB); deltaDB.Close(); }
private void ExportDatabaseTo(PwDatabase deltaDB, PwEntry userRoot, List <string> paths) { //Save the database encrypted with the KEY specified in the PasswordFiled of the user deltaDB.MasterKey = SyncSource.CreateKeyFor(userRoot); deltaDB.DataCipherUuid = StandardAesEngine.AesUuid; deltaDB.Compression = PwCompressionAlgorithm.GZip; deltaDB.MemoryProtection.ProtectPassword = true; deltaDB.SetCustomAttribute(KeeShare.AttributeFlags.IsDeltaDatabase, true); string fileName = SyncSource.FileNameFor(userRoot); foreach (string path in paths) { string databasePath = path; if (!path.EndsWith(Path.DirectorySeparatorChar.ToString())) { databasePath += Path.DirectorySeparatorChar; } databasePath += fileName + FileExtension; deltaDB.SaveAs(IOConnectionInfo.FromPath(databasePath), false, null); } }
/// <summary> /// The function we have to call from the outside to trigger any tests we have to /// make after some changes to the given database, so we can ensure full functionality /// </summary> /// <param name="database">The database we should work on.</param> public void RefeshSourcesList() { Debug.Assert(m_initialized); Debug.Assert(m_database != null); if (!m_initialized || m_database == null) { return; } PwGroup importGroup = m_database.GetImportGroup(); PwObjectList<PwEntry> activeSources = importGroup.GetEntries(true); // remove old/invalid sources foreach (SyncSource source in m_syncSourceList.ToArray()) { //don't touch sources of closed tabs! if (source.DestinationDB != m_database) { // The database where the source is configured in is not a target for the source! // WTF: Why do we keep it in the DB? continue; } bool isActive = false; foreach (PwEntry entry in activeSources) { if (source.IsSimilar(entry, m_database) || source.IsSimilar(entry, m_database)) { isActive = true; break; } } if (!isActive) { source.StopWatch(); source.Changed -= m_importer.Import; m_syncSourceList.Remove(source); } } //look for new sources foreach( PwEntry entry in activeSources ) { if( entry.IsValidSource() && !SouceListContains( entry) ) { //maybe only an update is needed SyncSource source = GetSourceRepresentedBy( entry); if( null != source && !source.IsEqual( entry, m_database) ) { source.Key = SyncSource.CreateKeyFor( entry ); source.StartWatch(); } //a syncSource without a Pasword that could be used as Key will be ignored! else if( entry.Strings.ReadSafe(KeeShare.PasswordField) != "" ) { //create a new source otherwise SyncSource src = new SyncSource( entry, m_database); src.Changed += m_importer.Import; src.StartWatch(); m_syncSourceList.Add( src ); } } } }
/// <summary> /// The function we have to call from the outside to trigger any tests we have to /// make after some changes to the given database, so we can ensure full functionality /// </summary> /// <param name="database">The database we should work on.</param> public void RefeshSourcesList() { Debug.Assert(m_initialized); Debug.Assert(m_database != null); if (!m_initialized || m_database == null) { return; } PwGroup importGroup = m_database.GetImportGroup(); PwObjectList <PwEntry> activeSources = importGroup.GetEntries(true); // remove old/invalid sources foreach (SyncSource source in m_syncSourceList.ToArray()) { //don't touch sources of closed tabs! if (source.DestinationDB != m_database) { // The database where the source is configured in is not a target for the source! // WTF: Why do we keep it in the DB? continue; } bool isActive = false; foreach (PwEntry entry in activeSources) { if (source.IsSimilar(entry, m_database) || source.IsSimilar(entry, m_database)) { isActive = true; break; } } if (!isActive) { source.StopWatch(); source.Changed -= m_importer.Import; m_syncSourceList.Remove(source); } } //look for new sources foreach (PwEntry entry in activeSources) { if (entry.IsValidSource() && !SouceListContains(entry)) { //maybe only an update is needed SyncSource source = GetSourceRepresentedBy(entry); if (null != source && !source.IsEqual(entry, m_database)) { source.Key = SyncSource.CreateKeyFor(entry); source.StartWatch(); } //a syncSource without a Pasword that could be used as Key will be ignored! else if (entry.Strings.ReadSafe(KeeShare.PasswordField) != "") { //create a new source otherwise SyncSource src = new SyncSource(entry, m_database); src.Changed += m_importer.Import; src.StartWatch(); m_syncSourceList.Add(src); } } } }