/// <summary>
        /// Go over restore objects and restore their files.
        /// </summary>
        public void restore(RestoreSettings settings)
        {
            int[] indices = settings.indices;

            foreach (var i in indices)
            {
                restores[i].restore(settings.restore_destination_base,
                                    settings.restore_destination_lookup,
                                    settings.prefix_filter, settings.file_name_reg);
            }
        }
Example #2
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);
        }