/// <summary>
        /// Triggered when a KeePass database is being saved
        /// </summary>
        private static async void MainWindowOnFileSaved(object sender, FileSavedEventArgs fileSavedEventArgs)
        {
            var config = Configuration.GetPasswordDatabaseConfiguration(fileSavedEventArgs.Database.IOConnectionInfo.Path);

            config.KeePassDatabase = fileSavedEventArgs.Database;

            // Check if we should sync this database
            if (config.DoNotSync)
            {
                return;
            }

            // Make sure it's not a remote database on i.e. an FTP or website
            if (!fileSavedEventArgs.Database.IOConnectionInfo.IsLocalFile())
            {
                MessageBox.Show("KeePass OneDriveSync does not support synchronizing databases from remote locations and will therefore not be available for this database", "KeePass OneDriveSync", MessageBoxButtons.OK, MessageBoxIcon.Information);

                config.DoNotSync = true;
                Configuration.Save();
                return;
            }

            await KeePass.SyncDatabase(fileSavedEventArgs.Database.IOConnectionInfo.Path, KeePass.UpdateStatus);

            // If the OneDrive Refresh Token is stored in the KeePass database, we must trigger a save of the database here so to ensure that the actual value gets saved into the KDBX
            if (config.RefreshTokenStorage == OneDriveRefreshTokenStorage.KeePassDatabase)
            {
                fileSavedEventArgs.Database.Save(null);
            }
        }
        /// <summary>
        /// Triggered when a KeePass database is being opened
        /// </summary>
        private async static void OnKeePassDatabaseOpened(object sender, FileOpenedEventArgs fileOpenedEventArgs)
        {
            // Add the KeePass database instance to the already available configuration
            var config = Configuration.GetPasswordDatabaseConfiguration(fileOpenedEventArgs.Database.IOConnectionInfo.Path);

            config.KeePassDatabase = fileOpenedEventArgs.Database;

            // Check if we should sync this database
            if (config.DoNotSync || !fileOpenedEventArgs.Database.IOConnectionInfo.IsLocalFile())
            {
                return;
            }

            // Check if the database configuration of the opened KeePass database is set to retrieve the OneDrive Refresh Token from the KeePass database itself
            if (config.RefreshTokenStorage == OneDriveRefreshTokenStorage.KeePassDatabase)
            {
                // Retrieve the OneDrive Refresh Token from the KeePass database that is being opened
                config.RefreshToken = Utilities.GetRefreshTokenFromKeePassDatabase(fileOpenedEventArgs.Database);
            }

            await KeePass.SyncDatabase(fileOpenedEventArgs.Database.IOConnectionInfo.Path, KeePass.UpdateStatus);

            // If the OneDrive Refresh Token is stored in the KeePass database, we must trigger a save of the database here so to ensure that the actual value gets saved into the KDBX
            if (config.RefreshTokenStorage == OneDriveRefreshTokenStorage.KeePassDatabase)
            {
                fileOpenedEventArgs.Database.Save(null);
            }
        }
Exemple #3
0
        private async void ForceSyncButton_Click(object sender, EventArgs e)
        {
            UpdateStatus("Synchronizing");
            await KeePass.SyncDatabase(_configuration.Key, UpdateStatus);

            ShowConfiguration();
        }
Exemple #4
0
        private async Task SyncNow()
        {
            // Only allow syncing if the database is not marked with the DoNotSync flag
            var configuration = ((KeyValuePair <string, Configuration>)ConfigurationListView.SelectedItems[0].Tag);

            if (configuration.Value.DoNotSync)
            {
                return;
            }

            // Only allow syncing if the currently opened database is the one we're trying to sync
            if (!KoenZomersKeePassOneDriveSyncExt.Host.Database.IOConnectionInfo.Path.Equals(ConfigurationListView.SelectedItems[0].Text, StringComparison.InvariantCultureIgnoreCase))
            {
                return;
            }

            UpdateStatus("Synchronizing");
            await KeePass.SyncDatabase(ConfigurationListView.SelectedItems[0].Text, UpdateStatus);
        }