示例#1
0
        private void BrowseDestination_Click(object sender, RoutedEventArgs e)
        {
            string directory = WindowsBackup_App.get_folder(DestinationPath_tb.Text);

            WindowsBackup_App.remove_ending_slash(ref directory);
            DestinationPath_tb.Text = directory;
        }
        private void Dir2_btn_Click(object sender, RoutedEventArgs e)
        {
            string directory = WindowsBackup_App.get_folder(Dir2_tb.Text);

            WindowsBackup_App.remove_ending_slash(ref directory);
            Dir2_tb.Text = directory;
        }
示例#3
0
        private void BrowseSource_btn_Click(object sender, RoutedEventArgs e)
        {
            string directory = WindowsBackup_App.get_folder(Source_tb.Text);

            WindowsBackup_App.remove_ending_slash(ref directory);
            Source_tb.Text = directory;
            generate_default_embedded_prefix();
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            // allocate icons
            var ready_icon = new Icon("icons\\ready.ico");
            var busy_icon  = new Icon("icons\\busy.ico");
            var error_icon = new Icon("icons\\error.ico");

            // notify icon setup
            notify_icon              = new NotifyIcon();
            notify_icon.Icon         = ready_icon;
            notify_icon.Click       += notify_icon_Click;
            notify_icon.DoubleClick += notify_icon_Click;
            notify_icon.Visible      = true;

            app = new WindowsBackup_App(Output_tb, notify_icon, ready_icon, busy_icon, error_icon);
        }
示例#5
0
        internal SetupWindow(WindowsBackup_App app)
        {
            InitializeComponent();

            this.app = app;

            // Create the tree nodes.
            // Key node
            var key_node = new TreeViewItem();

            key_node.Header = "Keys                "; // spaces for easier clicking
            NavPane_tv.Items.Add(key_node);

            // Cloud node
            var cloud_node = new TreeViewItem();

            cloud_node.Header = "Cloud Accounts";
            NavPane_tv.Items.Add(cloud_node);

            // Backup root node
            backup_root_node            = new TreeViewItem();
            backup_root_node.IsExpanded = true;
            backup_root_node.Header     = "Backups";
            NavPane_tv.Items.Add(backup_root_node);

            // Create pages and attach them to the nodes.
            var key_page = new Key_Page(app.key_manager);

            associate_tv_item_to_page(key_node, key_page);
            pages.Add(key_page);

            var cloud_page = new Cloud_Page(app.cloud_backup_services);

            associate_tv_item_to_page(cloud_node, cloud_page);
            pages.Add(cloud_page);

            // The edit_backup_page is not re-created when the backup nodes are
            // re-created. So adding it to the list of "CanBeModified" here, so
            // that it's a one time add.
            edit_backup_page = new EditBackup_Page(update_backup_node_headers);
            pages.Add(edit_backup_page);

            init_backup_nodes();
        }
        private void GetInfo_btn_Click(object sender, RoutedEventArgs e)
        {
            var path = Path_tb.Text.Trim();

            WindowsBackup_App.remove_ending_slash(ref path);
            Path_tb.Text = path;

            var path_status = file_name_reg.get_path_status(path);

            if (path_status == null)
            {
                Info_text.Text        = "No info";
                Info_text.Visibility  = Visibility.Visible;
                Delete_btn.Visibility = Visibility.Collapsed;
            }
            else if (path_status.is_file == false)
            {
                Info_text.Text        = "Path is a directory";
                Info_text.Visibility  = Visibility.Visible;
                Delete_btn.Visibility = Visibility.Collapsed;
            }
            else if (path_status.is_file)
            {
                var sb = new StringBuilder();
                sb.AppendLine("Encrypted file name: " + path_status.alt_file_name);
                if (path_status.modified_time != null)
                {
                    sb.AppendLine("File modified time (UTC): " + path_status.modified_time.Value);
                }
                else
                {
                    sb.AppendLine("File modified time unknown");
                }

                Info_text.Text        = sb.ToString();
                Info_text.Visibility  = Visibility.Visible;
                Delete_btn.Visibility = Visibility.Visible;
            }
        }
示例#7
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);
            }
        }
示例#8
0
        void generate_default_embedded_prefix()
        {
            if (Encryption_cb.IsChecked == false)
            {
                return;
            }

            // Default the embedded prefix to the source directory name.
            string source_dir = Source_tb.Text.Trim();

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

            int index = source_dir.LastIndexOf('\\');

            if (index >= 0)
            {
                EmbeddedPrefix_tb.Text = source_dir.Substring(index + 1);
            }
            else
            {
                EmbeddedPrefix_tb.Text = source_dir;
            }
        }
示例#9
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);
        }
示例#10
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();
        }
示例#11
0
 private void BrowseDirectory_Click(object sender, RoutedEventArgs e)
 {
     Directory_tb.Text = WindowsBackup_App.get_folder(Directory_tb.Text);
 }
示例#12
0
        internal Restore_Window(WindowsBackup_App app)
        {
            this.app = app;

            InitializeComponent();
        }
示例#13
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);
        }