private async void CopyToExecuted(object sender, ExecutedRoutedEventArgs e) { if (ListViewExplorer.SelectedItems.Count <= 0) return; await PbVisualization.TogglePbVisibilityAsync(); var dialog = new PickDialog(PickDialogType.Directory, _fileDiver.CurrentPath) { Title = Properties.Resources.PdTitleDir, Owner = this, WindowStartupLocation = WindowStartupLocation.CenterOwner }; dialog.ShowDialog(); if (dialog.PickDialogResult == PickDialogResult.Ok) { var destinationPath = dialog.SelectedPath; var fsEntries = ListViewExplorer.SelectedItems; if (fsEntries != null) { try { var copyDialog = new CopyDialog { Owner = this, WindowStartupLocation = WindowStartupLocation.CenterOwner }; var copyTask = Task.Factory.StartNew(() => { Dispatcher.InvokeAsync(() => { copyDialog.PbCopyProgress.Maximum = fsEntries.Count; copyDialog.ShowDialog(); }); foreach (FileSystemInfo entry in fsEntries) { if (copyDialog.Canceled) { Dispatcher.InvokeAsync(() => { copyDialog.Close(); }); return; } Dispatcher.InvokeAsync(() => { copyDialog.TbCopyObject.Text = entry.Name; }); if (entry.IsDirectory()) { try { Directory.CreateDirectory(Path.Combine(destinationPath, entry.Name)); _fileDiver.CopyAllInDir((DirectoryInfo) entry, new DirectoryInfo(Path.Combine(destinationPath, entry.Name))); } catch (Exception) { Dispatcher.InvokeAsync(() => { ErrorPopup.IsOpen = true; SystemSounds.Exclamation.Play(); }); } } else { try { File.Copy(entry.FullName, Path.Combine(destinationPath, entry.Name), true); } catch (Exception) { Dispatcher.InvokeAsync(() => { ErrorPopup.IsOpen = true; SystemSounds.Exclamation.Play(); }); } } Dispatcher.InvokeAsync(() => { copyDialog.PbCopyProgress.Value++; }); } }); await copyTask; if (copyDialog.Visibility == Visibility.Visible) { copyDialog.Close(); } } catch (Exception) { ErrorPopup.IsOpen = true; SystemSounds.Exclamation.Play(); } finally { ListViewExplorer_Refresh(); } } } await PbVisualization.TogglePbVisibilityAsync(); }
private async void MoveFilesExecuted(object sender, ExecutedRoutedEventArgs e) { if (ListViewExplorer.SelectedItems.Count < 1) return; await PbVisualization.TogglePbVisibilityAsync(); bool doMove = false; string destinationPath = string.Empty; await Dispatcher.InvokeAsync(() => { var dialog = new PickDialog(PickDialogType.Directory, _fileDiver.CurrentPath) { Title = Properties.Resources.PdTitleDir, Owner = this, WindowStartupLocation = WindowStartupLocation.CenterOwner }; if (dialog.ShowDialog() == true) { doMove = true; destinationPath = dialog.SelectedPath; } }); if (doMove) { var fsEntries = ListViewExplorer.SelectedItems; if (fsEntries != null) { var moveTask = Task.Factory.StartNew(() => { foreach (FileSystemInfo entry in fsEntries) { try { string watch = Path.Combine(destinationPath, entry.Name); Directory.Move(entry.FullName, watch); } catch (Exception) { Dispatcher.InvokeAsync(() => { ErrorPopup.IsOpen = true; SystemSounds.Exclamation.Play(); }); } } }); await moveTask; } } ListViewExplorer_Refresh(); await PbVisualization.TogglePbVisibilityAsync(); }