Beispiel #1
0
        private void TestFilePath_btn_Click(object sender, RoutedEventArgs e)
        {
            string file_path = TestFilePath_tb.Text.Trim();

            if (file_path.Length == 0)
            {
                return;
            }

            bool accepted = true;

            if (file_path.StartsWith(Source_tb.Text.Trim()) == false)
            {
                accepted = false;
            }
            else
            {
                accepted = rule_lists.accepts(file_path);
            }

            if (accepted)
            {
                MyMessageBox.show("The file \"" + file_path + "\" will be backed up.",
                                  "File Accepted");
            }
            else
            {
                MyMessageBox.show("The file \"" + file_path + "\" will be ignored.",
                                  "File Rejected");
            }
        }
        private void CompareDir_btn_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Mouse.OverrideCursor = Cursors.Wait;
                string result = compare_directories(Dir1_tb.Text.Trim(), Dir2_tb.Text.Trim());
                Mouse.OverrideCursor = null;

                result = result.Trim();
                if (result.Length == 0)
                {
                    result = "No difference found.";
                }
                else
                {
                    result += "\n\nDirectory comparison completed.";
                }

                DirCompareOutput_tb.Visibility = Visibility.Visible;
                DirCompareOutput_tb.Text       = result;
            }
            catch (Exception ex)
            {
                MyMessageBox.show(ex.Message, "Error");
            }
        }
Beispiel #3
0
        private void GetInfo_btn_Click(object sender, RoutedEventArgs e)
        {
            // Obtain selected indices
            int[] restore_indices = get_restore_indices();
            if (restore_indices.Length == 0)
            {
                MyMessageBox.show("No archive selected.", "Error");
                return;
            }

            // Update GUI
            disable_controls(new UIElement[] { RestoreNames_lb, GetInfo_btn,
                                               GetFileNames_cb });
            RestoreInfo_text.Visibility = Visibility.Visible;

            // Call get_restore_info(...) on backup manager thread
            bool skip_file_names = true;

            if (GetFileNames_cb.IsChecked == true)
            {
                skip_file_names = false;
            }

            var restore_manager = app.restore_manager;

            app.backup_manager.get_restore_info(restore_manager, restore_indices, skip_file_names);
        }
Beispiel #4
0
        internal void load_backup(Backup backup)
        {
            // Loading a new backup object could mean leaving a previous
            // backup object. Update the name in the tree view.
            if (update_backup_node_headers != null)
            {
                update_backup_node_headers();
            }

            // It's either "disk_backup" or "encrypted_backup".
            disk_backup      = backup as DiskBackup;
            encrypted_backup = backup as EncryptedBackup;

            if (disk_backup != null)
            {
                init_gui(disk_backup);
            }
            else if (encrypted_backup != null)
            {
                init_gui(encrypted_backup);
            }
            else
            {
                MyMessageBox.show("Software error. EditBackup_Page :: "
                                  + " load_backup(Backup backup) is being fed an unknown object",
                                  "Error");
            }
        }
Beispiel #5
0
        private void Add_btn_Click(object sender, RoutedEventArgs e)
        {
            var add_rule_window = new AddRule_Window(rule_lists.backup_rule_lists.Count);

            add_rule_window.ShowDialog();

            if (add_rule_window.rule != null)
            {
                // Check directory for validity.
                if (add_rule_window.rule.directory.StartsWith(source_base) == false)
                {
                    MyMessageBox.show("The rule just added is not a subdirectory "
                                      + "of the source field. Therefore it is rejected. "
                                      + "(\"" + add_rule_window.rule.directory
                                      + "\" not a subdirectory of \"" + source_base + "\")",
                                      "Error");
                    return;
                }

                // Add new rule to rule_list.
                rule_lists.add_rule(add_rule_window.rule, add_rule_window.Category);
                modified = true;
                AddBackup_Page.redraw_backup_rules_listbox(Rules_lb, rule_lists);
            }
        }
        private void Test_btn_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (BucketName_tb.Text.Trim().Length == 0)
                {
                    MyMessageBox.show("Bucket name needed.", "Error");
                    return;
                }

                var cloud_backup = create_cloud_bakcup_from_user_input("");

                // Read items from "cloud_backup"
                var names = cloud_backup.list_objects(BucketName_tb.Text.Trim(), 10);

                // Test fails if no item is requested.
                if (names.Count == 0)
                {
                    MyMessageBox.show("No object found at cloud account.", "Error");
                    return;
                }
                else
                {
                    // Test passes if at least 1 item is read.
                    // List objects.
                    var sb = new StringBuilder();
                    if (names.Count >= 10)
                    {
                        sb.AppendLine("Ten or more objects found:");
                    }
                    else
                    {
                        sb.AppendLine("Objects found:");
                    }

                    // Limit printing to 10 items.
                    int length = names.Count;
                    if (length > 10)
                    {
                        length = 10;
                    }

                    for (int i = 0; i < length; i++)
                    {
                        sb.AppendLine(names[i]);
                    }

                    Test_text.Text = sb.ToString();

                    // Show additional controls
                    show_controls(new UIElement[] { Test_text, AccountName_text,
                                                    AccountName_tb, Add_btn });
                }
            }
            catch (Exception ex)
            {
                MyMessageBox.show(ex.Message, "Error");
            }
        }
        private void TestExisting_btn_Click(object sender, RoutedEventArgs e)
        {
            int index = ExistingClouds_lb.SelectedIndex;

            if (index < 0)
            {
                return;
            }

            try
            {
                if (BucketName2_tb.Text.Trim().Length == 0)
                {
                    MyMessageBox.show("Bucket name needed.", "Error");
                    return;
                }

                // Read items from "cloud_backup"
                var names = cloud_backup_services[index].list_objects(BucketName2_tb.Text.Trim(), 10);
                if (names.Count > 0)
                {
                    var sb = new StringBuilder();
                    if (names.Count >= 10)
                    {
                        sb.AppendLine("Ten or more objects found:");
                    }
                    else
                    {
                        sb.AppendLine("Objects found:");
                    }

                    // Limit printing to 10 items.
                    int length = names.Count;
                    if (length > 10)
                    {
                        length = 10;
                    }

                    for (int i = 0; i < length; i++)
                    {
                        sb.AppendLine(names[i]);
                    }

                    TestExisting_text.Text = sb.ToString();
                }
                else
                {
                    TestExisting_text.Text = "No object found.";
                }
            }
            catch (Exception ex)
            {
                MyMessageBox.show(ex.Message, "Error");
            }
        }
Beispiel #8
0
        private void AddKey_btn_Click(object sender, RoutedEventArgs e)
        {
            if (NewKeyName_tb.Text.Trim().Length == 0)
            {
                return;
            }

            try
            {
                modified = true;
                key_manager.add_key(NewKeyName_tb.Text);
                update_gui();
            }
            catch (Exception ex)
            {
                MyMessageBox.show(ex.Message, "Error");
            }
        }
        /// <summary>
        /// Call this on the GUI thread only, using Dispatcher.BeginInvoke(...)
        /// </summary>
        void show_error_message_box(string message)
        {
            // Gradually increase the width of the error message window.
            int width = 300;

            if (message.Length > 300)
            {
                width = 400;
            }
            if (message.Length > 400)
            {
                width = 500;
            }
            if (message.Length > 500)
            {
                width = 600;
            }

            MyMessageBox.show(message, "Error", width);
        }
        private void Restore_menuItem_Click(object sender, RoutedEventArgs e)
        {
            app.backup_manager.stop_live_backup();

            bool success = app.enter_restore_mode();

            if (success)
            {
                var restore = new Restore_Window(app);
                restore.Height = 300;
                restore.ShowDialog();

                app.leave_restore_mode();
            }
            else
            {
                MyMessageBox.show("Software stuck in error mode. Cannot start "
                                  + "\"restore\" window. Restart this software to clear error mode.",
                                  "Error");
            }
        }
        private void CompareFile_btn_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Mouse.OverrideCursor = Cursors.Wait;
                bool same = compare_files(File1_tb.Text.Trim(), File2_tb.Text.Trim());
                Mouse.OverrideCursor = null;

                if (same)
                {
                    MyMessageBox.show("The two files are the same.", "File Compare Result");
                }
                else
                {
                    MyMessageBox.show("The two files are the DIFFERENT.", "File Compare Result");
                }
            }
            catch (Exception ex)
            {
                MyMessageBox.show(ex.Message, "Error");
            }
        }
        private void Add_btn_Click(object sender, RoutedEventArgs e)
        {
            // Check that account name has been entered.
            if (AccountName_tb.Text.Trim().Length == 0)
            {
                MyMessageBox.show("The account name is missing.", "Error");
                return;
            }
            string account_name = AccountName_tb.Text.Trim();

            // Check that account name is not in use.
            bool name_found = false;

            foreach (var backup in cloud_backup_services)
            {
                if (backup.Name.Equals(account_name))
                {
                    name_found = true;
                    break;
                }
            }

            if (name_found)
            {
                MyMessageBox.show("The account name \"" + account_name
                                  + "\" is already used by another cloud account. "
                                  + "Choose something else as the account name.", "Error");
                return;
            }

            var cloud_backup = create_cloud_bakcup_from_user_input(account_name);

            cloud_backup_services.Add(cloud_backup);
            cloud_backup_services.Sort(compare_two_cloud_backups);
            modified = true;

            reset_gui();
        }
Beispiel #13
0
        /// <summary>
        /// Event handler for adding a rule.
        /// </summary>
        private void Add_btn_Click(object sender, RoutedEventArgs e)
        {
            // Check that there is a valid source directory.
            string directory = Source_tb.Text.Trim();

            WindowsBackup_App.remove_ending_slash(ref directory);
            Source_tb.Text = directory;

            if (Directory.Exists(Source_tb.Text) == false)
            {
                MyMessageBox.show("Before adding rules, the source field needs "
                                  + "to be an existing directory.", "Error");
                return;
            }

            var add_rule_window = new AddRule_Window(rule_lists.backup_rule_lists.Count);

            add_rule_window.ShowDialog();

            if (add_rule_window.rule != null)
            {
                // Check directory for validity.
                if (add_rule_window.rule.directory.StartsWith(Source_tb.Text) == false)
                {
                    MyMessageBox.show("The rule just added is not a subdirectory "
                                      + "of the source field. Therefore it is rejected. "
                                      + "(\"" + add_rule_window.rule.directory
                                      + "\" not a subdirectory of \"" + Source_tb.Text + "\")",
                                      "Error");
                    return;
                }

                // Add new rule to rule_list.
                rule_lists.add_rule(add_rule_window.rule, add_rule_window.Category);
                redraw_backup_rules_listbox(BackupRules_lb, rule_lists);
            }
        }
Beispiel #14
0
        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);
        }
Beispiel #15
0
        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();
        }
Beispiel #16
0
        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);
        }