/// <summary> /// EventHandler runs when all processes are finished /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private void CopyWindowOnFinished(object sender, EventArgs args) { try { _copyWindow = null; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// EventHandler for COPY button /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ButtonStartCopy_OnClick(object sender, RoutedEventArgs e) { try { string pathToDirectory = ((DirectoryInTree)ListViewDestinationTo.Items[0]).FullPath; if (ListViewDestinationFrom.SelectedItems.Count == 0) { throw new Exception("Please, select files to copy"); } if (!new DirectoryInfo(pathToDirectory).Parent.Exists&& (new DirectoryInfo(pathToDirectory).Parent.Attributes & FileAttributes.System) != 0) { throw new Exception("Please, select correct directory to copy in"); } List <string> listPathesOfFiles = new List <string>(); for (int i = 0; i < ListViewDestinationFrom.SelectedItems.Count; i++) { if (!new FileInfo(((FileInTree)ListViewDestinationFrom.SelectedItems[i]).FullPath).Exists) { throw new Exception("Please, select correct file to copy from directory"); } if ( new FileInfo( $"{new DirectoryInfo(pathToDirectory).Parent.FullName}\\{new FileInfo(((FileInTree)ListViewDestinationFrom.SelectedItems[i]).FullPath).Name}") .Exists) { throw new Exception($"File: {new DirectoryInfo(pathToDirectory).Parent.FullName}\\{new FileInfo(((FileInTree)ListViewDestinationFrom.SelectedItems[i]).FullPath).Name} has already existed"); } listPathesOfFiles.Add(((FileInTree)ListViewDestinationFrom.SelectedItems[i]).FullPath); } // Initialization of WindowCopy or addition to it new UIElements if (_copyWindow == null) { _copyWindow = new WindowCopy(); _copyWindow.Finished += CopyWindowOnFinished; _copyWindow.Show(); } // Run the copy processes for each file foreach (var file in listPathesOfFiles) { _copyWindow.AddProgressWindow(file, new DirectoryInfo(pathToDirectory).Parent.FullName); _copyWindow.StartCopy(file, new DirectoryInfo(pathToDirectory).Parent.FullName); } } catch (InvalidCastException) { MessageBox.Show("You have selected the folder, but should select files"); } catch (Exception ex) { MessageBox.Show(ex.Message); } }