Пример #1
0
        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);
            }
        }
Пример #2
0
        /// <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);
                    }
                }
            }
        }