/// <summary> /// Backup the user's data to the backup directory. /// </summary> private void BackupData() { // Get the id for this backup int id = ProjectFileInterface.RequestBackupId(); if (id <= -1) { NotificationDialog errorDialog = new NotificationDialog("Backup Failed", "Error creating new id for this backup. Please check the log file for more details."); errorDialog.ShowDialog(); return; } // Create the backup dirs string backupDir = Path.Combine(DataDirectory, string.Format("backup\\backup_{0}", id)); Directory.CreateDirectory(backupDir); // Write all project data to make sure that it's current ProjectFileInterface.WriteAllProjectData(); // Copy the data to the backup location CopyDirectoryRecursively(DataDirectory, backupDir, true); // Delete any backups that we copied string copiedBackupsDir = Path.Combine(backupDir, "backup"); Directory.Delete(copiedBackupsDir, true); // Let the user know that the operation succeeded NotificationDialog dialog = new NotificationDialog("Backup Successful", string.Format( "Backup to\n\n{0}\n\nwas successful.", backupDir)); dialog.ShowDialog(); }
/// <summary> /// Change's the directory for the project data. /// </summary> /// <param name="newDir">The new directory for the data.</param> private void ChangeDataDirectory(string newDir) { string oldDir = DataDirectory; // Check to see if new dir is empty if (Directory.EnumerateFiles(newDir).Any()) { // If it's not empty, warn the user that overwrites may occur ConfirmationDialog dialog = new ConfirmationDialog(string.Format( "{0} is not empty. Any files it contains may be overwritten. Proceed?", newDir)); if (dialog.ShowDialog() != true) { // If the user opted not to proceed, abort the operation return; } } // Make sure all the project notes are saved before we copy NotificationDialog notifDialog = new NotificationDialog("Save Data", "Please save all project notes files. Press OK when all files are saved."); notifDialog.ShowDialog(); // Write all project data to make sure that it's current ProjectFileInterface.WriteAllProjectData(); // Copy the data to the new directory CopyDirectoryRecursively(oldDir, newDir, true); // At the end, set the new directory and rename the files in PFI DataDirectory = newDir; UserSettings.DataDirectory = newDir; ProjectFileInterface.RenameFullFilenamesForDataDirectoryChange(); // Let the user know that the operation was successful notifDialog = new NotificationDialog("Success", "Data directory successfully changed."); notifDialog.ShowDialog(); }