private async void ForceSyncButton_Click(object sender, EventArgs e) { UpdateStatus("Synchronizing"); await KeePassDatabase.SyncDatabase(_configuration.Key, UpdateStatus, true); ShowConfiguration(); }
private async Task SyncNow() { foreach (ListViewItem selectedItem in ConfigurationListView.SelectedItems) { // Only allow syncing if the database is not marked with the DoNotSync flag var configuration = (KeyValuePair <string, Configuration>)selectedItem.Tag; if (configuration.Value.DoNotSync) { return; } // Ensure the database to be synced is currently open if (configuration.Value.KeePassDatabase == null) { UpdateStatus(string.Format("Database {0} must be open before it can sync", configuration.Key)); continue; } UpdateStatus(string.Format("Synchronizing database {0}", configuration.Value.KeePassDatabase.Name)); await KeePassDatabase.SyncDatabase(selectedItem.Text, UpdateStatus, true, configuration.Value); // Update the Last Synced column selectedItem.SubItems[3].Text = configuration.Value.LastCheckedAt.HasValue ? configuration.Value.LastCheckedAt.Value.ToString("ddd d MMMM yyyy HH:mm:ss") : "Never"; selectedItem.SubItems[3].Tag = configuration.Value.LastCheckedAt.HasValue ? (DateTime?)configuration.Value.LastCheckedAt.Value : null; } }
/// <summary> /// Triggered when a KeePass database is being opened /// </summary> private async void OnKeePassDatabaseOpened(object sender, FileOpenedEventArgs fileOpenedEventArgs) { var databasePath = fileOpenedEventArgs.Database.IOConnectionInfo.Path; // Add the KeePass database instance to the already available configuration var config = Configuration.GetPasswordDatabaseConfiguration(databasePath); config.KeePassDatabase = fileOpenedEventArgs.Database; // Check if we should sync this database if (config.DoNotSync || !fileOpenedEventArgs.Database.IOConnectionInfo.IsLocalFile()) { return; } if (!_fileOfflineMenuItem.Checked) { Host.MainWindow.SetStatusEx(string.Format("OneDriveSync has been set to offline, skipping sync for database {0}", fileOpenedEventArgs.Database.Name)); 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 && string.IsNullOrEmpty(config.RefreshToken)) { // Retrieve the OneDrive Refresh Token from the KeePass database that is being opened config.RefreshToken = Utilities.GetRefreshTokenFromKeePassDatabase(fileOpenedEventArgs.Database); } await KeePassDatabase.SyncDatabase(databasePath, KeePassDatabase.UpdateStatus, false, config); // 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); } }
/// <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 KeePassDatabase.SyncDatabase(fileSavedEventArgs.Database.IOConnectionInfo.Path, KeePassDatabase.UpdateStatus, true); // 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 KeePassDatabase.SyncDatabase(fileOpenedEventArgs.Database.IOConnectionInfo.Path, KeePassDatabase.UpdateStatus, false); // 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); } }
private async void ForceSyncButton_Click(object sender, EventArgs e) { if (_configuration.Value.KeePassDatabase == null) { UpdateStatus("Database must be open before it can synchronize"); return; } UpdateStatus("Synchronizing"); await KeePassDatabase.SyncDatabase(_configuration.Key, UpdateStatus, true, null); ShowConfiguration(); }
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 KeePassDatabase.SyncDatabase(ConfigurationListView.SelectedItems[0].Text, UpdateStatus, true); }
/// <summary> /// Triggered when a KeePass database is being saved /// </summary> private async void MainWindowOnFileSaved(object sender, FileSavedEventArgs fileSavedEventArgs) { var databasePath = fileSavedEventArgs.Database.IOConnectionInfo.Path; // If the database is located under the folder from where KeePass runs, use a relative path instead of the absolute path if (fileSavedEventArgs.Database.IOConnectionInfo.Path.StartsWith(AppDomain.CurrentDomain.BaseDirectory)) { databasePath = databasePath.Remove(0, AppDomain.CurrentDomain.BaseDirectory.Length); } var config = Configuration.GetPasswordDatabaseConfiguration(databasePath); config.KeePassDatabase = fileSavedEventArgs.Database; // Check if we should sync this database if (config.DoNotSync) { return; } if (!_fileOfflineMenuItem.Checked) { Host.MainWindow.SetStatusEx(string.Format("OneDriveSync has been set to offline, skipping sync for database {0}", fileSavedEventArgs.Database.Name)); 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 KeePassDatabase.SyncDatabase(databasePath, KeePassDatabase.UpdateStatus, true, config); // 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); } }
private async Task SyncNow() { foreach (ListViewItem selectedItem in ConfigurationListView.SelectedItems) { // Only allow syncing if the database is not marked with the DoNotSync flag var configuration = (KeyValuePair <string, Configuration>)selectedItem.Tag; if (configuration.Value.DoNotSync) { return; } // Ensure the database to be synced is currently open if (configuration.Value.KeePassDatabase == null) { UpdateStatus(string.Format("Database {0} must be open before it can sync", configuration.Key)); continue; } UpdateStatus(string.Format("Synchronizing database {0}", configuration.Value.KeePassDatabase.Name)); await KeePassDatabase.SyncDatabase(selectedItem.Text, UpdateStatus, true, configuration.Value); } }
/// <summary> /// Triggered when a KeePass database is being opened /// </summary> private async void OnKeePassDatabaseOpened(object sender, FileOpenedEventArgs fileOpenedEventArgs) { var databasePath = fileOpenedEventArgs.Database.IOConnectionInfo.Path; // If the database is located under the folder from where KeePass runs, use a relative path instead of the absolute path if (fileOpenedEventArgs.Database.IOConnectionInfo.Path.StartsWith(AppDomain.CurrentDomain.BaseDirectory)) { databasePath = databasePath.Remove(0, AppDomain.CurrentDomain.BaseDirectory.Length); } // Add the KeePass database instance to the already available configuration var config = Configuration.GetPasswordDatabaseConfiguration(databasePath); config.KeePassDatabase = fileOpenedEventArgs.Database; // Check if we should sync this database if (config.DoNotSync || !fileOpenedEventArgs.Database.IOConnectionInfo.IsLocalFile() || !_fileOfflineMenuItem.Checked) { 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 && string.IsNullOrEmpty(config.RefreshToken)) { // Retrieve the OneDrive Refresh Token from the KeePass database that is being opened config.RefreshToken = Utilities.GetRefreshTokenFromKeePassDatabase(fileOpenedEventArgs.Database); } await KeePassDatabase.SyncDatabase(databasePath, KeePassDatabase.UpdateStatus, false, config); // 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); } }
/// <summary> /// Triggered when clicking on the Open from OneDrive menu item under File > Open /// </summary> private async static void MenuFileOpenFromOneDriveOnClick(object sender, EventArgs e) { await KeePassDatabase.OpenDatabaseFromCloudService(KeePassDatabase.UpdateStatus); }