Пример #1
0
        public override bool Initialize(KeePass.Plugins.IPluginHost host)
        {
            bool ret = base.Initialize(host);

            if (!ret || ReferenceEquals(host, null))
            {
                return(false);
            }

            _host                        = host;
            _windowLogger                = _host.MainWindow.CreateShowWarningsLogger();
            _statusBarLogger             = _host.MainWindow.CreateStatusBarLogger();
            _host.MainWindow.FileSaving += OnDatabaseSaving;

            return(true);
        }
Пример #2
0
 public void SetLogger(KeePassLib.Interfaces.IStatusLogger logger)
 {
     this.logger = logger;
 }
Пример #3
0
        private static bool Export(KeePassLib.PwDatabase database, Uri filePath, KeePassLib.Security.ProtectedString password, KeePassLib.Interfaces.IStatusLogger logger)
        {
            Exception argumentError = CheckArgument(database, filePath, password);

            if (!ReferenceEquals(argumentError, null))
            {
                throw argumentError;
            }

            if (string.Equals(database.IOConnectionInfo.Path, filePath.LocalPath, StringComparison.InvariantCultureIgnoreCase))
            {
                return(false); //Don't export myself
            }
            //Create new database in temporary file
            KeePassLib.PwDatabase exportedDatabase = new KeePassLib.PwDatabase();
            exportedDatabase.Compression = KeePassLib.PwCompressionAlgorithm.GZip;
            KeePassLib.Serialization.IOConnectionInfo connectionInfo = new KeePassLib.Serialization.IOConnectionInfo();
            string storageDirectory = Path.GetDirectoryName(filePath.LocalPath);
            string tmpPath          = Path.Combine(storageDirectory, string.Format("{0}{1}", Guid.NewGuid(), KeePassDatabaseExtension));

            connectionInfo.Path         = tmpPath;
            connectionInfo.CredSaveMode = KeePassLib.Serialization.IOCredSaveMode.SaveCred;
            KeePassLib.Keys.CompositeKey exportedKey = new KeePassLib.Keys.CompositeKey();
            exportedKey.AddUserKey(new KeePassLib.Keys.KcpPassword(password.ReadString()));
            exportedDatabase.New(connectionInfo, exportedKey);
            exportedDatabase.RootGroup.Name = database.RootGroup.Name;

            //Merge current database in temporary file
            exportedDatabase.MergeIn(database, KeePassLib.PwMergeMethod.OverwriteExisting, logger);
            exportedDatabase.Save(logger);
            exportedDatabase.Close();

            //Move temporary file into target backup path
            if (File.Exists(filePath.LocalPath))
            {
                File.Delete(filePath.LocalPath);
            }
            File.Move(tmpPath, filePath.LocalPath);

            return(true);
        }