private void Execute(Host host, string filepath) { HelpersGUI.BringFormToFront(MainWindowCommandInterface.Form); if (filepath == "") { // Showing this dialog has the (undocumented) side effect of changing the working directory // to that of the file selected. This means a handle to the directory persists, making // it undeletable until the program exits, or the working dir moves on. So, save and // restore the working dir... String oldDir = ""; try { oldDir = Directory.GetCurrentDirectory(); OpenFileDialog dialog = new OpenFileDialog(); dialog.AddExtension = true; dialog.Filter = string.Format("{0} (*.{1})|*.{1}|{2} (*.*)|*.*", Messages.XS_BACKUP_FILES, Branding.BACKUP, Messages.ALL_FILES); dialog.FilterIndex = 0; dialog.RestoreDirectory = true; dialog.DefaultExt = Branding.BACKUP; dialog.CheckPathExists = false; if (dialog.ShowDialog(Parent) == DialogResult.Cancel) { return; } filepath = dialog.FileName; } finally { Directory.SetCurrentDirectory(oldDir); } } if (host == null) { SelectHostDialog hostdialog = new SelectHostDialog { TheHost = host, TopBlurb = Messages.BACKUP_SELECT_HOST, TopPicture = Images.StaticImages.backup_restore_32, HelpString = "Backup", // don't i18n Text = Messages.BACKUP_SELECT_HOST_TITLE, OkButtonText = Messages.BACKUP_SELECT_HOST_BUTTON }; hostdialog.FormClosed += delegate { if (hostdialog.DialogResult != DialogResult.OK) { return; } host = hostdialog.TheHost; HostBackupRestoreAction action = new HostBackupRestoreAction(host, HostBackupRestoreAction.HostBackupRestoreType.restore, filepath); action.Completed += RestoreAction_Completed; action.RunAsync(); }; hostdialog.Show(Parent); } else { HostBackupRestoreAction action = new HostBackupRestoreAction(host, HostBackupRestoreAction.HostBackupRestoreType.restore, filepath); action.Completed += RestoreAction_Completed; action.RunAsync(); } }
private void Execute(Host host, string filepath) { MainWindowCommandInterface.BringToFront(); if (filepath == "") { // Showing this dialog has the (undocumented) side effect of changing the working directory // to that of the file selected. This means a handle to the directory persists, making // it undeletable until the program exits, or the working dir moves on. So, save and // restore the working dir... String oldDir = ""; try { oldDir = Directory.GetCurrentDirectory(); OpenFileDialog dialog = new OpenFileDialog(); dialog.AddExtension = true; dialog.Filter = string.Format("{0} (*.xbk)|*.xbk|{1} (*.*)|*.*", Messages.XS_BACKUP_FILES, Messages.ALL_FILES); dialog.FilterIndex = 0; dialog.RestoreDirectory = true; dialog.DefaultExt = "xbk"; dialog.CheckPathExists = false; if (dialog.ShowDialog(Parent) == DialogResult.Cancel) { return; } filepath = dialog.FileName; } finally { Directory.SetCurrentDirectory(oldDir); } } if (host == null) { SelectHostDialog hostdialog = new SelectHostDialog(); hostdialog.TheHost = host; hostdialog.DispString = Messages.BACKUP_SELECT_HOST; hostdialog.SetPicture = Properties.Resources.backup_restore_32; hostdialog.HelpString = "Backup"; // dont i18n hostdialog.Text = Messages.BACKUP_SELECT_HOST_TITLE; hostdialog.okbutton.Text = Messages.BACKUP_SELECT_HOST_BUTTON; hostdialog.FormClosed += delegate { if (hostdialog.DialogResult != DialogResult.OK) { return; } host = hostdialog.TheHost; MainWindowCommandInterface.AllowHistorySwitch(); HostBackupRestoreAction action = new HostBackupRestoreAction(host, HostBackupRestoreAction.HostBackupRestoreType.restore, filepath); action.Completed += RestoreAction_Completed; action.RunAsync(); }; hostdialog.Show(Parent); } else { MainWindowCommandInterface.AllowHistorySwitch(); HostBackupRestoreAction action = new HostBackupRestoreAction(host, HostBackupRestoreAction.HostBackupRestoreType.restore, filepath); action.Completed += RestoreAction_Completed; action.RunAsync(); } }