public static void show(string message, string caption, int width = 300) { var message_box = new MyMessageBox(message, caption, width); message_box.ShowDialog(); }
private void Add_Click(object sender, RoutedEventArgs e) { // Check the fields Directory_tb.Text = Directory_tb.Text.Trim(); if (Directory.Exists(Directory_tb.Text) == false) { MyMessageBox.show("The directory does not exist on disk.", "Error"); return; } if (Rules_cb.SelectedIndex > 1) { Suffixes_tb.Text = Suffixes_tb.Text.Trim(); if (Suffixes_tb.Text.Length == 0) { if (Rules_cb.SelectedIndex == 2 || Rules_cb.SelectedIndex == 3) { MyMessageBox.show("The suffixes field cannot be empty if the " + "rule type is to accept or reject suffixes.", "Error"); return; } else if (Rules_cb.SelectedIndex == 4) { MyMessageBox.show("The sub-directories field cannot be empty if the " + "rule type is to reject sub-directories.", "Error"); return; } } } // Update the category number category = Categories_cb.SelectedIndex; // Create a rule object and exit. string directory = Directory_tb.Text; WindowsBackup_App.remove_ending_slash(ref directory); string suffixes = null; string subdirs = null; var rule_type = BackupRuleLists.BackupRuleType.ACCEPT_ALL; if (Rules_cb.SelectedIndex == 1) { rule_type = BackupRuleLists.BackupRuleType.REJECT_ALL; } else if (Rules_cb.SelectedIndex == 2) { rule_type = BackupRuleLists.BackupRuleType.ACCEPT_SUFFIX; suffixes = Suffixes_tb.Text.Trim(); } else if (Rules_cb.SelectedIndex == 3) { rule_type = BackupRuleLists.BackupRuleType.REJECT_SUFFIX; suffixes = Suffixes_tb.Text.Trim(); } else if (Rules_cb.SelectedIndex == 4) { rule_type = BackupRuleLists.BackupRuleType.REJECT_SUB_DIR; subdirs = Suffixes_tb.Text.Trim(); } rule = new BackupRuleLists.BackupRule(directory, rule_type, suffixes, subdirs); Close(); }
private void AddBackup_btn_Click(object sender, RoutedEventArgs e) { // Backup Name has to be filled BackupName_tb.Text = BackupName_tb.Text.Trim(); if (BackupName_tb.Text.Length == 0) { MyMessageBox.show("The backup name field must be filled.", "Error"); return; } // Source directory has to exist string directory = Source_tb.Text.Trim(); WindowsBackup_App.remove_ending_slash(ref directory); Source_tb.Text = directory; if (directory.Length == 0) { MyMessageBox.show("The source directory field is not filled out.", "Error"); return; } if (Directory.Exists(directory) == false) { MyMessageBox.show("The backup source directory \"" + directory + "\" does not exist.", "Error"); return; } // Destination, if it's a disk directory, has to exist. This directory // has to be unused by other backups. if (DestinationName_cb.SelectedIndex == 0) { // Clean up destination directory. directory = DestinationPath_tb.Text.Trim(); WindowsBackup_App.remove_ending_slash(ref directory); DestinationPath_tb.Text = directory; // Make sure destination directory exists, and is not the same as source. if (directory.Length == 0) { MyMessageBox.show("The backup destination directory field " + "is not filled out.", "Error"); return; } if (Directory.Exists(directory) == false) { MyMessageBox.show("The backup destination directory \"" + directory + "\" does not exist.", "Error"); return; } if (DestinationPath_tb.Text.Equals(Source_tb.Text)) { MyMessageBox.show("The backup destination directory is the same " + "as the backup source directory.", "Error"); return; } // Make sure destination directory has not been used before. foreach (var backup in backup_manager.backups) { if (backup is DiskBackup) { var disk_backup = (DiskBackup)backup; if (disk_backup.destination_base.Equals(directory)) { MyMessageBox.show("The backup destination directory \"" + directory + "\" is already being used by the backup \"" + disk_backup.Name + "\" .", "Error"); return; } } else if (backup is EncryptedBackup) { var encrypted_backup = (EncryptedBackup)backup; if (encrypted_backup.destination_name.ToLower().Equals("disk") && encrypted_backup.destination_base.Equals(directory)) { MyMessageBox.show("The backup destination directory \"" + directory + "\" is already being used by the encrypted backup \"" + encrypted_backup.Name + "\" .", "Error"); return; } } } } // Destination, if it's a bucket, has to be readable. if (DestinationName_cb.SelectedIndex > 0) { string bucket = DestinationPath_tb.Text.Trim(); DestinationPath_tb.Text = bucket; int index = DestinationName_cb.SelectedIndex - 1; // Check that the destination bucket field is filled out. if (bucket.Length == 0) { MyMessageBox.show("The backup destination bucket field needs to " + "be filled out.", "Error"); return; } // Check that the destination bucket is readable. try { cloud_backups[index].list_objects(bucket, 10); } catch { MyMessageBox.show("Failed to read from cloud backup \"" + cloud_backups[index].Name + "\\" + bucket + "\".", "Error"); return; } } // If encryption is used, check the embedded prefix. if (Encryption_cb.IsChecked == true) { // Make sure there is an embedded prefix. string prefix = EmbeddedPrefix_tb.Text.Trim(); if (prefix.Length == 0) { MyMessageBox.show("All encrypted backups must have an unique embedded prefix.", "Error"); return; } WindowsBackup_App.remove_ending_slash(ref prefix); EmbeddedPrefix_tb.Text = prefix; // Make sure the embedded prefix has no '\' character if (prefix.IndexOf('\\') >= 0) { MyMessageBox.show("The embedded prefix \"" + prefix + "\" has a '\\', " + "which is not allowed.", "Error"); return; } // Make sure the embedded prefix is unique. foreach (var backup in backup_manager.backups) { if (backup is EncryptedBackup) { var encrypted_backup = (EncryptedBackup)backup; if (encrypted_backup.embedded_prefix.Equals(prefix)) { MyMessageBox.show("The embedded prefix \"" + prefix + "\" is already being used by the encrypted backup \"" + encrypted_backup.Name + "\".", "Error"); return; } } } } // Determine the key number. Generate new key if needed. UInt16 key_number = 0; if (Encryption_cb.IsChecked == true) { if (Keys_cb.SelectedIndex == 0) { key_number = key_manager.add_key(); } else { string key_name = Keys_cb.Items[Keys_cb.SelectedIndex].ToString(); key_number = key_manager.get_key_number(key_name).Value; } } // Determine destination_name string destination_name = "disk"; // use lower case for storage if (DestinationName_cb.SelectedIndex > 0) { destination_name = cloud_backups[DestinationName_cb.SelectedIndex - 1].Name; } // Create backup Backup new_backup = null; if (Encryption_cb.IsChecked == true) { new_backup = new EncryptedBackup(Source_tb.Text, EmbeddedPrefix_tb.Text, key_number, destination_name, DestinationPath_tb.Text, rule_lists, BackupName_tb.Text); } else { new_backup = new DiskBackup(Source_tb.Text, DestinationPath_tb.Text, rule_lists, BackupName_tb.Text); } add_backup(new_backup); }
private void StartRestore_btn_Click(object sender, RoutedEventArgs e) { var settings = new RestoreSettings(); if (MultiDestination_rbtn.IsChecked == true) { // check mapping_list if (mapping_list.Count == 0) { MyMessageBox.show("The \"destination\" options section is incorrect. " + "The user did not provide any restore destination information.", "Error"); return; } // check that each destination directory exists foreach (var mapping in mapping_list) { mapping.destination = mapping.destination.Trim(); WindowsBackup_App.remove_ending_slash(ref mapping.destination); if (mapping.destination.Length > 0 && Directory.Exists(mapping.destination) == false) { MyMessageBox.show("The embedded prefix \"" + mapping.prefix + "\" is mapped to a destination \"" + mapping.destination + "\" that does not exist on disk.", "Error"); return; } } // Build up embedded_prefix --> destination lookup var destination_lookup = new Dictionary <string, string>(); foreach (var mapping in mapping_list) { if (mapping.destination.Length > 0) { destination_lookup.Add(mapping.prefix, mapping.destination); } } settings.restore_destination_lookup = destination_lookup; } else if (SingleDestination_rbtn.IsChecked == true) { // check that destination directory exists BaseDestination_tb.Text = BaseDestination_tb.Text.Trim(); string destination_base = BaseDestination_tb.Text; WindowsBackup_App.remove_ending_slash(ref destination_base); if (Directory.Exists(destination_base) == false) { MyMessageBox.show("The restore destination directory \"" + destination_base + "\" does not exist on disk.", "Error"); return; } settings.restore_destination_base = destination_base; } // The file name registration field needs to be filled out FNR_Path_tb.Text = FNR_Path_tb.Text.Trim(); if (FNR_Path_tb.Text.Length == 0) { MyMessageBox.show("The file name registration field is not filled out. " + "Restoring encrypted files result in a new file name registration record.", "Error"); return; } // The file name registration field should not reference an existing file if (File.Exists(FNR_Path_tb.Text)) { MyMessageBox.show("The file name registration field is referencing a file \"" + FNR_Path_tb.Text + "\" that currently exists.", "Error"); return; } // The file name registration file should not reference an existing directory if (Directory.Exists(FNR_Path_tb.Text)) { MyMessageBox.show("The file name registration field is referencing a location \"" + FNR_Path_tb.Text + "\" that currently exists as a directory.", "Error"); return; } // disable previous controls, show RestoreStatus_text disable_controls(new UIElement[] { MultiDestination_rbtn, SingleDestination_rbtn, EmbeddedPrefix_datagrid, BaseDestination_tb, BaseDestination_btn, FNR_Path_tb, FNR_Path_btn, StartRestore_btn }); RestoreStatus_text.Visibility = Visibility.Visible; // start restore operation on the backup manager thread settings.indices = get_restore_indices(); settings.file_name_reg = new FileNameRegistration(FNR_Path_tb.Text); var restore_manager = app.restore_manager; app.backup_manager.restore(restore_manager, settings); }