private void RestoreTarget(object sender, RoutedEventArgs e) { if (Settings.Dirs.Count < 1) { return; } DirPair dirPair = null; if (grDirs.Visibility == Visibility.Visible) { dirPair = ((Button)sender).DataContext as DirPair; if (dirPair == null) { return; } } else { dirPair = Settings.Dirs[0]; } var dlg = new VistaFolderBrowserDialog(); dlg.Description = CoreResources.Ui_Dialogs_RestoreTarget; dlg.SelectedPath = dirPair.Source; dlg.ShowNewFolderButton = true; bool?result = dlg.ShowDialog(); if (!result.HasValue || !result.Value) { return; } string targetPath = dlg.SelectedPath; _cancellationTokenSource = new CancellationTokenSource(); _logger.Start(); Task.Factory .StartNew(() => { var passwordRuleParser = new PasswordGenerator(Settings.PasswordRule, Settings.CustomPasswordRule, Settings.MasterPassword); var zip = new Zip(passwordRuleParser); var fileProcessor = new DirPairProcessor(dirPair, Settings.ArchiveNameRule, false, zip, null, _logger); fileProcessor.Unpack(targetPath, _cancellationTokenSource.Token); } , _cancellationTokenSource.Token ) .ContinueWith(LogErrorIfAny, TaskContinuationOptions.OnlyOnFaulted) .ContinueWith(o => Dispatcher.Invoke(new Action(() => _logger.Stop()))); }
private static DirPair GetUnpackDirPair(CommandLineArgs cmd, Settings settings, ILogger logger) { DirPair dirPair = null; if (!string.IsNullOrEmpty(cmd.UnpackSource)) { dirPair = settings.Dirs.FirstOrDefault(d => string.Equals(d.Target, cmd.UnpackSource, StringComparison.InvariantCultureIgnoreCase)); } else if (settings.Dirs.Count == 1 || !settings.HasMultipleDirs) { dirPair = settings.Dirs[0]; } if (dirPair == null) { logger.Log(false, Core.Properties.Resources.Console_RestoreSourceNotDefined); } return(dirPair); }