private void CopyBtn_Click(object sender, RoutedEventArgs e) { FolderCmpItem item = (FolderCmpItem)foldersCmpList.SelectedItem; string destDirPath = item.pathToCopy; string filePath = ""; if (item.status == NOT_EQUAL_COPY_BY_DATE) { filePath = item.secondName; } else if (item.status == NOT_EQUAL_COPY_BY_DATE) { filePath = item.firstName; } else if (item.status != EQUALLY && item.status.Length != 0) { filePath = item.firstName.Length > 0 ? item.firstName : item.secondName; } if (showQuestionModal(filePath, destDirPath)) { copyFile(filePath, destDirPath); } updateListview(); }
public void RenderFilesWithDeep(string path, string side) { Stack <string> dirs = new Stack <string>(20); FolderCmpItem cpmItem = new FolderCmpItem(); if (!Directory.Exists(path)) { throw new ArgumentException(); } dirs.Push(path); while (dirs.Count > 0) { string currentDir = dirs.Pop(); string[] subDir = Directory.GetDirectories(currentDir); string filter = filterExtension.Text; FileInfo[] files = MyFile.GetFiles(currentDir, filter); addDirectoryNameItem(currentDir, side); foreach (FileInfo file in files) { addFileNameItem(file, path, side); } foreach (string str in subDir) { dirs.Push(str); } } }
private void Button_Click(object sender, RoutedEventArgs e) { FolderCmpItem itemSelected = (FolderCmpItem)foldersCmpList.SelectedItem; if (cmpContent.IsChecked == true && itemSelected != null && itemSelected.status == EQUALLY) { if (itemSelected.firstName != null && itemSelected.secondName != null) { Difference diff = new Difference(itemSelected.firstName, itemSelected.secondName); diff.ShowDialog(); } } updateListview(); }
public void addDirectoryNameItem(string currentDir, string side) { FolderCmpItem cpmItem = new FolderCmpItem(); if (side == LEFT) { string pathToCopy = BuiltPathToCopy(currentDir, LEFT); ListCmpFilesCollections.Add(cpmItem.createCmpItem(currentDir, "", LEFT_ARROW_IMG, DIRECTORY, pathToCopy)); } if (side == RIGHT) { string pathToCopy = BuiltPathToCopy(currentDir, RIGHT); ListCmpFilesCollections.Add(cpmItem.createCmpItem("", currentDir, RIGHT_ARROW_IMG, DIRECTORY, pathToCopy)); } }
public void addFileNameItem(FileInfo file, string path, string side) { FolderCmpItem cpmItem = new FolderCmpItem(); string imgPath; if (side == LEFT) { imgPath = LEFT_ARROW_IMG; string pathToCopy = BuiltPathToCopy(file, LEFT); ListCmpFilesCollections.Add(cpmItem.createCmpItem(file, null, imgPath, NOT_EXIST_RIGHT_SIDE, path, pathToCopy)); filesToRightPathCopy.Add(file); } if (side == RIGHT) { imgPath = RIGHT_ARROW_IMG; string pathToCopy = BuiltPathToCopy(file, RIGHT); ListCmpFilesCollections.Add(cpmItem.createCmpItem(null, file, imgPath, NOT_EXIST_LEFT_SIDE, path, pathToCopy)); filesToLeftPathCopy.Add(file); } }
private void foldersCmpList_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e) { FolderCmpItem itemSelected = (FolderCmpItem)foldersCmpList.SelectedItem; Console.WriteLine("Status: {0}, parentDir: {1}, pathToCopy: {2}", itemSelected.status, itemSelected.parentDir, itemSelected.pathToCopy); }
private void CompareFilesWithSubDirs(string leftPath, string rightPath) { HashSet <string> dirsLeft = new HashSet <string>(); HashSet <string> dirsRight = new HashSet <string>(); if (!Directory.Exists(leftPath) || !Directory.Exists(rightPath)) { throw new ArgumentException(); } dirsLeft.Add(leftPath); dirsRight.Add(rightPath); while (dirsLeft.Count > 0 && dirsRight.Count > 0) { string currentDirLeft; string currentDirRight; string[] subDirsLeft; string[] subDirsRight; string lastFolderLeft; try { currentDirLeft = dirsLeft.First(); currentDirRight = dirsRight.First(); subDirsLeft = Directory.GetDirectories(currentDirLeft); subDirsRight = Directory.GetDirectories(currentDirRight); lastFolderLeft = Path.GetFileName(Path.GetDirectoryName(currentDirLeft + "\\")); } catch (UnauthorizedAccessException e) { Console.WriteLine(e.Message); continue; } catch (DirectoryNotFoundException e) { Console.WriteLine(e.Message); continue; } FolderCmpItem cpmItem = new FolderCmpItem(); if (dirsLeft.Contains(currentDirLeft) && dirsRight.Contains(currentDirRight)) { ListCmpFilesCollections.Add(cpmItem.createCmpItem(currentDirLeft, currentDirRight, EQUAL_IMG, DIRECTORY, "")); } CompareFilesInFolder(currentDirLeft, currentDirRight); if (dirsLeft.Contains(currentDirLeft)) { dirsLeft.Remove(currentDirLeft); } if (dirsRight.Contains(currentDirRight)) { dirsRight.Remove(currentDirRight); } //List<string> leftSide = new List<string>(Directory.GetDirectories(currentDirLeft)); //List<string> rightSide = new List<string>(Directory.GetDirectories(currentDirRight)); List <string> leftNames = new List <string>(); List <string> rightNames = new List <string>(); foreach (string dir in subDirsLeft) { string folderName = Path.GetFileName(Path.GetDirectoryName(dir + "\\")); leftNames.Add(folderName); } foreach (string dir in subDirsRight) { string folderName = Path.GetFileName(Path.GetDirectoryName(dir + "\\")); rightNames.Add(folderName); } IEnumerable <string> theSameFolders = leftNames.Where(file => rightNames.Contains(file)); foreach (string dir in theSameFolders) { dirsLeft.Add(currentDirLeft + "\\" + dir); dirsRight.Add(currentDirRight + "\\" + dir); } IEnumerable <string> firstDiffSecond = leftNames.Where(file => !rightNames.Contains(file)); foreach (string dir in firstDiffSecond) { string path = currentDirLeft + "\\" + dir; // ListCmpFilesCollections.Add(cpmItem.createCmpItem(path, "", LEFT_ARROW_IMG)); RenderFilesWithDeep(path, LEFT); } IEnumerable <string> secondDiffFirst = rightNames.Where(file => !leftNames.Contains(file)); foreach (string dir in secondDiffFirst) { string path = currentDirRight + "\\" + dir; //ListCmpFilesCollections.Add(cpmItem.createCmpItem("", path, RIGHT_ARROW_IMG)); RenderFilesWithDeep(path, RIGHT); } } }
private void CompareFilesInFolder(string leftPath, string rightPath) { string filter = filterExtension.Text; filesToRightPathCopy.Clear(); filesToLeftPathCopy.Clear(); leftFiles = MyFile.GetFiles(leftPath, filter); rightFiles = MyFile.GetFiles(rightPath, filter); string imgPath; FolderCmpItem cpmItem = new FolderCmpItem(); string pathToCopy; if (leftFiles.Length > 0 || rightFiles.Length > 0) { SyncBtn.IsEnabled = true; } foreach (FileInfo file in leftFiles) { int index = Array.IndexOf(rightFiles, rightFiles.FirstOrDefault(f => f.Name == file.Name)); if (index > -1) { FileInfo secondFile = rightFiles[index]; imgPath = EQUAL_IMG; string redItem = "red"; if (byDate.IsChecked == true) { string dateFile_1 = MyFile.GetFileDate(file); string dateFile_2 = MyFile.GetFileDate(secondFile); DateTime nowdate = DateTime.Today; DateTime filedate_1 = file.LastWriteTime; DateTime filedate_2 = secondFile.LastWriteTime; TimeSpan comparevalue = filedate_2 - filedate_1; if (Math.Abs(comparevalue.Seconds) > 0) { imgPath = NOT_EQUAL_IMG; pathToCopy = BuiltPathToCopy(file, LEFT); ListCmpFilesCollections.Add(cpmItem.createCmpItem(file, secondFile, imgPath, NOT_EQUAL_COPY_BY_DATE, rightPath, pathToCopy, redItem)); } else { pathToCopy = BuiltPathToCopy(file, RIGHT); ListCmpFilesCollections.Add(cpmItem.createCmpItem(file, secondFile, imgPath, NOT_EQUAL_COPY_BY_DATE, leftPath)); } } else { ListCmpFilesCollections.Add(cpmItem.createCmpItem(file, secondFile, imgPath, EQUALLY, leftPath)); } //delete this file in rightFiles List <FileInfo> tmp = new List <FileInfo>(rightFiles); tmp.RemoveAt(index); rightFiles = tmp.ToArray(); } else { imgPath = LEFT_ARROW_IMG; pathToCopy = BuiltPathToCopy(file, LEFT); ListCmpFilesCollections.Add(cpmItem.createCmpItem(file, null, imgPath, NOT_EXIST_RIGHT_SIDE, leftPath, pathToCopy)); filesToRightPathCopy.Add(file); } } foreach (FileInfo secondFile in rightFiles) { imgPath = RIGHT_ARROW_IMG; pathToCopy = BuiltPathToCopy(secondFile, RIGHT); ListCmpFilesCollections.Add(cpmItem.createCmpItem(null, secondFile, imgPath, NOT_EXIST_LEFT_SIDE, rightPath, pathToCopy)); filesToLeftPathCopy.Add(secondFile); } foldersCmpList.ItemsSource = ListCmpFilesCollections; }