private void finishBackup(Logger logger, string status) { this.backupTimer.Stop(); this.backupStatusTimer.Stop(); this.currentBackupFilescanner = null; this.backupInProgress = false; if (logger != null) { logger.Close(); } this.InvokeEx(f => f.statusLabelBackupAction.Text = status); // Files/folders could will have changed this.InvokeEx(f => f.updateInfoDisplay()); this.InvokeEx(f => f.setButtonStates()); if (this.closeAfterFinish) { this.InvokeEx(f => f.Close()); } }
private void backgroundWorkerBackup_DoWork(object sender, DoWorkEventArgs e) { BackupItem backupArgs = (BackupItem)e.Argument; string source = backupArgs.Source; Settings settings = backupArgs.Settings; Database database = backupArgs.Database; Logger logger = backupArgs.Logger; BackendBase[] backends = backupArgs.BackendBases; bool restore = backupArgs.Restore; database.Open(); try { database.LoadToMemory(); } catch (Database.DatabaseInUseException ex) { database.Close(); this.showError("The database is currently in use (lockfile exists). Are you running this backup elsewhere?\n\nIf you're certain this is the only instance of the program running, delete " + ex.LockFile); this.finishBackup(logger, "Error"); return; } try { foreach (BackendBase backend in backends) { this.InvokeEx(f => f.statusLabelBackupAction.Text = "Setting up " + backend.Name + " backend..."); backend.SetupInitial(); } } catch (IOException ex) { this.showError("Error setting up backends\n\n" + ex.Message); database.Close(); this.finishBackup(logger, "Error"); return; } this.currentBackupFilescanner = new FileScanner(source, database, logger, settings.Name, backends, settings.FileIgnorePattern, new HashSet <string>(settings.IgnoredFiles), new HashSet <string>(settings.IgnoredFolders)); this.currentBackupFilescanner.BackupAction += new FileScanner.BackupActionEventHandler(fileScanner_BackupAction); if (!restore) { this.currentBackupFilescanner.Backup(); } else { this.currentBackupFilescanner.Restore(backupArgs.RestoreOverwrite, backupArgs.RestoreOverwriteOnlyIfOlder, backupArgs.RestorePurge); } settings.LastRunCancelled = this.currentBackupFilescanner.Cancelled; settings.LastRunErrors = this.currentBackupFilescanner.WarningOccurred; // Need to close to actually back up the database this.backupStatus = "Closing database..."; database.Close(); if (!restore && !this.currentBackupFilescanner.Cancelled) { this.backupStatus = "Backing up database..."; FileScanner.BackupDatabase(database.FilePath, backends); } if (this.currentBackupFilescanner.WarningOccurred && !(backupArgs.FromScheduler && settings.IgnoreWarnings)) { DialogResult result = MessageBox.Show("One or more warnings occurred. Do you want to view the log file?\n\nIt's probably worth running the operation again", "Some warnings happened", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (result == DialogResult.Yes) { Process.Start(logger.LogFilePath); } } this.finishBackup(logger, this.currentBackupFilescanner.Cancelled ? "Cancelled" : "Completed"); }